Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 112 lines 2.7 kB view raw
1{ 2 lib, 3 stdenvNoCC, 4 gitRepo, 5 cacert, 6 copyPathsToStore, 7}: 8lib.fetchers.withNormalizedHash { } ( 9 { 10 name, 11 manifest, 12 rev ? "HEAD", 13 outputHash, 14 outputHashAlgo, 15 # Optional parameters: 16 repoRepoURL ? "", 17 repoRepoRev ? "", 18 referenceDir ? "", 19 manifestName ? "", 20 localManifests ? [ ], 21 createMirror ? false, 22 useArchive ? false, 23 }: 24 25 assert repoRepoRev != "" -> repoRepoURL != ""; 26 assert createMirror -> !useArchive; 27 28 let 29 inherit (lib) 30 concatMapStringsSep 31 concatStringsSep 32 fetchers 33 optionalString 34 ; 35 36 extraRepoInitFlags = [ 37 (optionalString (repoRepoURL != "") "--repo-url=${repoRepoURL}") 38 (optionalString (repoRepoRev != "") "--repo-branch=${repoRepoRev}") 39 (optionalString (referenceDir != "") "--reference=${referenceDir}") 40 (optionalString (manifestName != "") "--manifest-name=${manifestName}") 41 ]; 42 43 repoInitFlags = [ 44 "--manifest-url=${manifest}" 45 "--manifest-branch=${rev}" 46 "--depth=1" 47 (optionalString createMirror "--mirror") 48 (optionalString useArchive "--archive") 49 ] 50 ++ extraRepoInitFlags; 51 52 local_manifests = copyPathsToStore localManifests; 53 54 in 55 stdenvNoCC.mkDerivation { 56 inherit name; 57 58 inherit 59 cacert 60 manifest 61 rev 62 repoRepoURL 63 repoRepoRev 64 referenceDir 65 ; # TODO 66 67 inherit outputHash outputHashAlgo; 68 outputHashMode = "recursive"; 69 70 preferLocalBuild = true; 71 enableParallelBuilding = true; 72 73 impureEnvVars = fetchers.proxyImpureEnvVars ++ [ 74 "GIT_PROXY_COMMAND" 75 "SOCKS_SERVER" 76 ]; 77 78 nativeBuildInputs = [ 79 gitRepo 80 cacert 81 ]; 82 83 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; 84 85 buildCommand = '' 86 # Path must be absolute (e.g. for GnuPG: ~/.repoconfig/gnupg/pubring.kbx) 87 export HOME="$(pwd)" 88 89 mkdir $out 90 cd $out 91 92 mkdir .repo 93 ${optionalString (local_manifests != [ ]) '' 94 mkdir .repo/local_manifests 95 for local_manifest in ${concatMapStringsSep " " toString local_manifests}; do 96 cp $local_manifest .repo/local_manifests/$(stripHash $local_manifest) 97 done 98 ''} 99 100 repo init ${concatStringsSep " " repoInitFlags} 101 repo sync --jobs=$NIX_BUILD_CORES --current-branch 102 103 # TODO: The git-index files (and probably the files in .repo as well) have 104 # different contents each time and will therefore change the final hash 105 # (i.e. creating a mirror probably won't work). 106 ${optionalString (!createMirror) '' 107 rm -rf .repo 108 find -type d -name '.git' -prune -exec rm -rf {} + 109 ''} 110 ''; 111 } 112)