1{ lib, stdenvNoCC, gitRepo, cacert, copyPathsToStore }:
2
3{ name, manifest, rev ? "HEAD", sha256
4# Optional parameters:
5, repoRepoURL ? "", repoRepoRev ? "", referenceDir ? "", manifestName ? ""
6, localManifests ? [], createMirror ? false, useArchive ? false
7}:
8
9assert repoRepoRev != "" -> repoRepoURL != "";
10assert createMirror -> !useArchive;
11
12with lib;
13
14let
15 extraRepoInitFlags = [
16 (optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}")
17 (optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}")
18 (optionalString (referenceDir != "") "--reference=${referenceDir}")
19 (optionalString (manifestName != "") "--manifest-name=${manifestName}")
20 ];
21
22 repoInitFlags = [
23 "--manifest-url=${manifest}"
24 "--manifest-branch=${rev}"
25 "--depth=1"
26 (optionalString createMirror "--mirror")
27 (optionalString useArchive "--archive")
28 ] ++ extraRepoInitFlags;
29
30 local_manifests = copyPathsToStore localManifests;
31
32in stdenvNoCC.mkDerivation {
33 inherit name;
34
35 inherit cacert manifest rev repoRepoURL repoRepoRev referenceDir; # TODO
36
37 outputHashAlgo = "sha256";
38 outputHashMode = "recursive";
39 outputHash = sha256;
40
41 preferLocalBuild = true;
42 enableParallelBuilding = true;
43
44 impureEnvVars = fetchers.proxyImpureEnvVars ++ [
45 "GIT_PROXY_COMMAND" "SOCKS_SERVER"
46 ];
47
48 nativeBuildInputs = [ gitRepo cacert ];
49
50 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
51
52 buildCommand = ''
53 # Path must be absolute (e.g. for GnuPG: ~/.repoconfig/gnupg/pubring.kbx)
54 export HOME="$(pwd)"
55
56 mkdir $out
57 cd $out
58
59 mkdir .repo
60 ${optionalString (local_manifests != []) ''
61 mkdir .repo/local_manifests
62 for local_manifest in ${concatMapStringsSep " " toString local_manifests}; do
63 cp $local_manifest .repo/local_manifests/$(stripHash $local_manifest; echo $strippedName)
64 done
65 ''}
66
67 repo init ${concatStringsSep " " repoInitFlags}
68 repo sync --jobs=$NIX_BUILD_CORES --current-branch
69
70 # TODO: The git-index files (and probably the files in .repo as well) have
71 # different contents each time and will therefore change the final hash
72 # (i.e. creating a mirror probably won't work).
73 ${optionalString (!createMirror) ''
74 rm -rf .repo
75 find -type d -name '.git' -prune -exec rm -rf {} +
76 ''}
77 '';
78}