nixpkgs-suyu/pkgs/build-support/fetchrepoproject/default.nix

67 lines
1.9 KiB
Nix
Raw Normal View History

{ stdenv, gitRepo, cacert, copyPathsToStore }:
{ name, manifest, rev ? "HEAD", sha256
, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? ""
2017-03-26 11:59:08 +02:00
, localManifests ? [], createMirror ? false, useArchive ? !createMirror
}:
assert repoRepoRev != "" -> repoRepoURL != "";
2017-03-26 11:59:08 +02:00
assert createMirror -> !useArchive;
with stdenv.lib;
let
extraRepoInitFlags = [
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
(optionalString (referenceDir != "") "--reference=${referenceDir}")
];
2017-03-26 11:59:08 +02:00
repoInitFlags = [
"--manifest-url=${manifest}"
"--manifest-branch=${rev}"
"--depth=1"
2017-03-27 07:04:02 +02:00
(optionalString createMirror "--mirror")
2017-03-26 11:59:08 +02:00
(optionalString useArchive "--archive")
] ++ extraRepoInitFlags;
2017-03-26 11:59:08 +02:00
local_manifests = copyPathsToStore localManifests;
in stdenv.mkDerivation {
inherit name;
inherit cacert manifest rev repoRepoURL repoRepoRev referenceDir; # TODO
2017-03-26 11:59:08 +02:00
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = sha256;
preferLocalBuild = true;
enableParallelBuilding = true;
impureEnvVars = fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND" "SOCKS_SERVER"
2017-03-25 00:35:20 +01:00
];
buildInputs = [ gitRepo cacert ];
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
2017-03-26 11:59:08 +02:00
buildCommand = ''
# Path must be absolute (e.g. for GnuPG: ~/.repoconfig/gnupg/pubring.kbx)
export HOME="$(pwd)"
2017-03-26 11:59:08 +02: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 11:59:08 +02:00
''}
2017-03-26 11:59:08 +02:00
repo init ${concatStringsSep " " repoInitFlags}
repo sync --jobs=$NIX_BUILD_CORES --current-branch
2017-03-26 13:55:41 +02:00
${optionalString (!createMirror) "rm -rf $out/.repo"}
'';
}