2021-01-27 05:50:30 +00:00
|
|
|
{ lib, stdenvNoCC, gitRepo, cacert, copyPathsToStore }:
|
2017-03-23 03:22:44 +00:00
|
|
|
|
2017-09-16 15:21:26 +00:00
|
|
|
{ name, manifest, rev ? "HEAD", sha256
|
2017-09-17 21:16:33 +00:00
|
|
|
# Optional parameters:
|
2019-07-17 11:02:46 +00:00
|
|
|
, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? "", manifestName ? ""
|
2017-09-17 21:16:33 +00:00
|
|
|
, localManifests ? [], createMirror ? false, useArchive ? false
|
2017-03-26 09:59:08 +00:00
|
|
|
}:
|
2017-03-23 03:22:44 +00:00
|
|
|
|
|
|
|
assert repoRepoRev != "" -> repoRepoURL != "";
|
2017-03-26 09:59:08 +00:00
|
|
|
assert createMirror -> !useArchive;
|
|
|
|
|
2021-01-27 05:50:30 +00:00
|
|
|
with lib;
|
2017-03-26 09:59:08 +00:00
|
|
|
|
|
|
|
let
|
2017-09-16 15:21:26 +00:00
|
|
|
extraRepoInitFlags = [
|
|
|
|
(optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
|
|
|
|
(optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
|
|
|
|
(optionalString (referenceDir != "") "--reference=${referenceDir}")
|
2019-07-17 11:02:46 +00:00
|
|
|
(optionalString (manifestName != "") "--manifest-name=${manifestName}")
|
2017-09-16 15:21:26 +00:00
|
|
|
];
|
|
|
|
|
2017-03-26 09:59:08 +00:00
|
|
|
repoInitFlags = [
|
|
|
|
"--manifest-url=${manifest}"
|
|
|
|
"--manifest-branch=${rev}"
|
|
|
|
"--depth=1"
|
2017-03-27 05:04:02 +00:00
|
|
|
(optionalString createMirror "--mirror")
|
2017-03-26 09:59:08 +00:00
|
|
|
(optionalString useArchive "--archive")
|
2017-09-16 15:21:26 +00:00
|
|
|
] ++ extraRepoInitFlags;
|
2017-03-26 09:59:08 +00:00
|
|
|
|
|
|
|
local_manifests = copyPathsToStore localManifests;
|
|
|
|
|
2018-01-09 23:38:19 +00:00
|
|
|
in stdenvNoCC.mkDerivation {
|
2017-09-16 15:21:26 +00:00
|
|
|
inherit name;
|
2017-03-23 03:22:44 +00:00
|
|
|
|
2017-09-16 15:21:26 +00:00
|
|
|
inherit cacert manifest rev repoRepoURL repoRepoRev referenceDir; # TODO
|
2017-03-26 09:59:08 +00:00
|
|
|
|
2017-09-16 15:21:26 +00: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
|
|
|
];
|
|
|
|
|
2018-01-09 20:36:14 +00:00
|
|
|
nativeBuildInputs = [ gitRepo cacert ];
|
2017-09-16 15:21:26 +00:00
|
|
|
|
|
|
|
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
|
2017-03-26 09:59:08 +00:00
|
|
|
buildCommand = ''
|
2017-09-16 15:57:14 +00:00
|
|
|
# Path must be absolute (e.g. for GnuPG: ~/.repoconfig/gnupg/pubring.kbx)
|
|
|
|
export HOME="$(pwd)"
|
|
|
|
|
2017-09-17 21:16:33 +00:00
|
|
|
mkdir $out
|
|
|
|
cd $out
|
|
|
|
|
2017-03-26 09:59:08 +00:00
|
|
|
mkdir .repo
|
|
|
|
${optionalString (local_manifests != []) ''
|
2017-09-16 15:21:26 +00:00
|
|
|
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 09:59:08 +00:00
|
|
|
''}
|
2017-03-23 03:22:44 +00:00
|
|
|
|
2017-03-26 09:59:08 +00:00
|
|
|
repo init ${concatStringsSep " " repoInitFlags}
|
2017-03-23 03:22:44 +00:00
|
|
|
repo sync --jobs=$NIX_BUILD_CORES --current-branch
|
2017-09-17 21:16:33 +00:00
|
|
|
|
|
|
|
# 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 {} +
|
|
|
|
''}
|
2017-03-23 03:22:44 +00:00
|
|
|
'';
|
|
|
|
}
|