1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-24 06:31:02 +00:00
nixpkgs/pkgs/build-support/fetchrepoproject/default.nix

78 lines
2.2 KiB
Nix
Raw Normal View History

{ stdenvNoCC, gitRepo, cacert, copyPathsToStore }:
{ name, manifest, rev ? "HEAD", sha256
# Optional parameters:
, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? ""
, localManifests ? [], createMirror ? false, useArchive ? false
2017-03-26 10:59:08 +01:00
}:
assert repoRepoRev != "" -> repoRepoURL != "";
2017-03-26 10:59:08 +01:00
assert createMirror -> !useArchive;
with stdenvNoCC.lib;
2017-03-26 10:59:08 +01:00
let
extraRepoInitFlags = [
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
(optionalString (referenceDir != "") "--reference=${referenceDir}")
];
2017-03-26 10:59:08 +01:00
repoInitFlags = [
"--manifest-url=${manifest}"
"--manifest-branch=${rev}"
"--depth=1"
2017-03-27 06:04:02 +01:00
(optionalString createMirror "--mirror")
2017-03-26 10:59:08 +01:00
(optionalString useArchive "--archive")
] ++ extraRepoInitFlags;
2017-03-26 10:59:08 +01:00
local_manifests = copyPathsToStore localManifests;
in stdenvNoCC.mkDerivation {
inherit name;
inherit cacert manifest rev repoRepoURL repoRepoRev referenceDir; # TODO
2017-03-26 10:59:08 +01:00
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = sha256;
preferLocalBuild = true;
enableParallelBuilding = true;
impureEnvVars = fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND" "SOCKS_SERVER"
2017-03-24 23:35:20 +00:00
];
nativeBuildInputs = [ gitRepo cacert ];
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
2017-03-26 10:59:08 +01:00
buildCommand = ''
# Path must be absolute (e.g. for GnuPG: ~/.repoconfig/gnupg/pubring.kbx)
export HOME="$(pwd)"
mkdir $out
cd $out
2017-03-26 10:59:08 +01:00
mkdir .repo
${optionalString (local_manifests != []) ''
mkdir .repo/local_manifests
for local_manifest in ${concatMapStringsSep " " toString local_manifests}; do
cp $local_manifest .repo/local_manifests/$(stripHash $local_manifest; echo $strippedName)
done
2017-03-26 10:59:08 +01:00
''}
2017-03-26 10:59:08 +01:00
repo init ${concatStringsSep " " repoInitFlags}
repo sync --jobs=$NIX_BUILD_CORES --current-branch
# TODO: The git-index files (and probably the files in .repo as well) have
# different contents each time and will therefore change the final hash
# (i.e. creating a mirror probably won't work).
${optionalString (!createMirror) ''
rm -rf .repo
find -type d -name '.git' -prune -exec rm -rf {} +
''}
'';
}