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