fetchRepoProject: Refactor the code

Should hopefully make it a bit more readable and less redundant.
This commit is contained in:
Michael Weiss 2017-09-16 17:21:26 +02:00
parent 701db44ab9
commit 50ce8abccf

View File

@ -1,6 +1,7 @@
{ stdenv, git, gitRepo, gnupg ? null, cacert, copyPathsToStore }: { stdenv, git, gitRepo, gnupg ? null, cacert, copyPathsToStore }:
{ name, manifest, rev ? "HEAD", sha256, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? "" { name, manifest, rev ? "HEAD", sha256
, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? ""
, localManifests ? [], createMirror ? false, useArchive ? !createMirror , localManifests ? [], createMirror ? false, useArchive ? !createMirror
}: }:
@ -10,6 +11,12 @@ assert createMirror -> !useArchive;
with stdenv.lib; with stdenv.lib;
let let
extraRepoInitFlags = [
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
(optionalString (referenceDir != "") "--reference=${referenceDir}")
];
repoInitFlags = [ repoInitFlags = [
"--manifest-url=${manifest}" "--manifest-url=${manifest}"
"--manifest-branch=${rev}" "--manifest-branch=${rev}"
@ -18,56 +25,42 @@ let
"--no-clone-bundle" "--no-clone-bundle"
(optionalString createMirror "--mirror") (optionalString createMirror "--mirror")
(optionalString useArchive "--archive") (optionalString useArchive "--archive")
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}") ] ++ extraRepoInitFlags;
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
(optionalString (referenceDir != "") "--reference=${referenceDir}")
];
local_manifests = copyPathsToStore localManifests; local_manifests = copyPathsToStore localManifests;
in in stdenv.mkDerivation {
inherit name;
with stdenv.lib; inherit cacert manifest rev repoRepoURL repoRepoRev referenceDir; # TODO
let
extraRepoInitFlags = [
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
(optionalString (referenceDir != "") "--reference=${referenceDir}")
];
in
stdenv.mkDerivation {
buildCommand = ''
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
''}
export HOME=.repo
repo init ${concatStringsSep " " repoInitFlags}
repo sync --jobs=$NIX_BUILD_CORES --current-branch
${optionalString (!createMirror) "rm -rf $out/.repo"}
'';
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND" "SOCKS_SERVER"
];
buildInputs = [git gitRepo cacert] ++ optional (gnupg != null) [gnupg] ;
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHash = sha256; outputHash = sha256;
preferLocalBuild = true; preferLocalBuild = true;
enableParallelBuilding = true; enableParallelBuilding = true;
inherit name cacert manifest rev repoRepoURL repoRepoRev referenceDir;
impureEnvVars = fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND" "SOCKS_SERVER"
];
buildInputs = [ git gitRepo cacert ] ++ optional (gnupg != null) [ gnupg ];
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
buildCommand = ''
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
''}
export HOME=.repo
repo init ${concatStringsSep " " repoInitFlags}
repo sync --jobs=$NIX_BUILD_CORES --current-branch
${optionalString (!createMirror) "rm -rf $out/.repo"}
'';
} }