nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 164 lines 4.8 kB view raw
1{ 2 callPackage, 3 gnugrep, 4 lib, 5 autoPatchelfHook, 6 stdenv, 7}: 8 9{ 10 name, 11 src, 12 sourceRoot ? null, 13 version ? null, 14 targets, 15 bazel, 16 startupArgs ? [ ], 17 commandArgs ? [ ], 18 env ? { }, 19 serverJavabase ? null, 20 registry ? null, 21 bazelRepoCacheFOD ? { 22 outputHash = null; 23 outputHashAlgo = "sha256"; 24 }, 25 bazelVendorDepsFOD ? { 26 outputHash = null; 27 outputHashAlgo = "sha256"; 28 }, 29 installPhase, 30 buildInputs ? [ ], 31 nativeBuildInputs ? [ ], 32 autoPatchelfIgnoreMissingDeps ? null, 33}: 34let 35 # FOD produced by `bazel fetch` 36 # Repo cache contains content-addressed external Bazel dependencies without any patching 37 # Potentially this can be nixified via --experimental_repository_resolved_file 38 # (Note: file itself isn't reproducible because it has lots of extra info and order 39 # isn't stable too. Parsing it into nix fetch* commands isn't trivial but might be possible) 40 bazelRepoCache = 41 if bazelRepoCacheFOD.outputHash == null then 42 null 43 else 44 (callPackage ./bazelDerivation.nix { } { 45 name = "bazelRepoCache"; 46 inherit (bazelRepoCacheFOD) outputHash outputHashAlgo; 47 inherit 48 src 49 version 50 sourceRoot 51 env 52 buildInputs 53 nativeBuildInputs 54 ; 55 inherit registry; 56 inherit 57 bazel 58 targets 59 startupArgs 60 serverJavabase 61 ; 62 command = "fetch"; 63 outputHashMode = "recursive"; 64 commandArgs = [ "--repository_cache=repo_cache" ] ++ commandArgs; 65 bazelPreBuild = '' 66 mkdir repo_cache 67 ''; 68 installPhase = '' 69 mkdir -p $out/repo_cache 70 cp -r --reflink=auto repo_cache/* $out/repo_cache 71 ''; 72 }); 73 # Stage1: FOD produced by `bazel vendor`, Stage2: eventual patchelf or other tuning 74 # Vendor deps contains unpacked&patches external dependencies, this may need Nix-specific 75 # patching to address things like 76 # - broken symlinks 77 # - symlinks or other references to absolute nix store paths which isn't allowed for FOD 78 # - autoPatchelf for externally-fetched binaries 79 # 80 # Either repo cache or vendor deps should be enough to build a given package 81 bazelVendorDeps = 82 if bazelVendorDepsFOD.outputHash == null then 83 null 84 else 85 ( 86 let 87 stage1 = callPackage ./bazelDerivation.nix { } { 88 name = "bazelVendorDepsStage1"; 89 inherit (bazelVendorDepsFOD) outputHash outputHashAlgo; 90 inherit 91 src 92 version 93 sourceRoot 94 env 95 buildInputs 96 nativeBuildInputs 97 ; 98 inherit registry; 99 inherit 100 bazel 101 targets 102 startupArgs 103 serverJavabase 104 ; 105 dontFixup = true; 106 command = "vendor"; 107 outputHashMode = "recursive"; 108 commandArgs = [ "--vendor_dir=vendor_dir" ] ++ commandArgs; 109 bazelPreBuild = '' 110 mkdir vendor_dir 111 ''; 112 bazelPostBuild = '' 113 # remove symlinks that point to locations under bazel_src/ 114 find vendor_dir -type l -lname "$HOME/*" -exec rm '{}' \; 115 # remove symlinks to temp build directory on darwin 116 find vendor_dir -type l -lname "/private/var/tmp/*" -exec rm '{}' \; 117 # remove broken symlinks 118 find vendor_dir -xtype l -exec rm '{}' \; 119 120 # remove .marker files referencing NIX_STORE as those references aren't allowed in FOD 121 (${gnugrep}/bin/grep -rI "$NIX_STORE/" vendor_dir --files-with-matches --include="*.marker" --null || true) \ 122 | xargs -0 --no-run-if-empty rm 123 ''; 124 installPhase = '' 125 mkdir -p $out/vendor_dir 126 cp -r --reflink=auto vendor_dir/* $out/vendor_dir 127 ''; 128 129 }; 130 in 131 stdenv.mkDerivation { 132 name = "bazelVendorDeps"; 133 buildInputs = lib.optional (!stdenv.hostPlatform.isDarwin) autoPatchelfHook ++ buildInputs; 134 inherit autoPatchelfIgnoreMissingDeps; 135 src = stage1; 136 installPhase = '' 137 cp -r . $out 138 ''; 139 } 140 ); 141 142 package = callPackage ./bazelDerivation.nix { } { 143 inherit 144 name 145 src 146 version 147 sourceRoot 148 env 149 buildInputs 150 nativeBuildInputs 151 ; 152 inherit registry bazelRepoCache bazelVendorDeps; 153 inherit 154 bazel 155 targets 156 startupArgs 157 serverJavabase 158 commandArgs 159 ; 160 inherit installPhase; 161 command = "build"; 162 }; 163in 164package // { passthru = { inherit bazelRepoCache bazelVendorDeps; }; }