Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 104 lines 2.3 kB view raw
1{ 2 lib, 3 stdenvNoCC, 4 runCommand, 5 writers, 6 python3Packages, 7 cargo, 8 nix-prefetch-git, 9 cacert, 10}: 11 12let 13 replaceWorkspaceValues = writers.writePython3Bin "replace-workspace-values" { 14 libraries = with python3Packages; [ 15 tomli 16 tomli-w 17 ]; 18 flakeIgnore = [ 19 "E501" 20 "W503" 21 ]; 22 } (builtins.readFile ./replace-workspace-values.py); 23 24 fetchCargoVendorUtil = writers.writePython3Bin "fetch-cargo-vendor-util" { 25 libraries = with python3Packages; [ 26 requests 27 ]; 28 flakeIgnore = [ 29 "E501" 30 ]; 31 } (builtins.readFile ./fetch-cargo-vendor-util.py); 32in 33 34{ 35 name ? if args ? pname && args ? version then "${args.pname}-${args.version}" else "cargo-deps", 36 hash ? (throw "fetchCargoVendor requires a `hash` value to be set for ${name}"), 37 nativeBuildInputs ? [ ], 38 ... 39}@args: 40 41# TODO: add asserts about pname version and name 42 43let 44 removedArgs = [ 45 "name" 46 "pname" 47 "version" 48 "nativeBuildInputs" 49 "hash" 50 ]; 51 52 vendorStaging = stdenvNoCC.mkDerivation ( 53 { 54 name = "${name}-vendor-staging"; 55 56 impureEnvVars = lib.fetchers.proxyImpureEnvVars; 57 58 nativeBuildInputs = [ 59 fetchCargoVendorUtil 60 cacert 61 # break loop of nix-prefetch-git -> git-lfs -> asciidoctor -> ruby (yjit) -> fetchCargoVendor -> nix-prefetch-git 62 # Cargo does not currently handle git-lfs: https://github.com/rust-lang/cargo/issues/9692 63 (nix-prefetch-git.override { git-lfs = null; }) 64 ] 65 ++ nativeBuildInputs; 66 67 buildPhase = '' 68 runHook preBuild 69 70 if [ -n "''${cargoRoot-}" ]; then 71 cd "$cargoRoot" 72 fi 73 74 fetch-cargo-vendor-util create-vendor-staging ./Cargo.lock "$out" 75 76 runHook postBuild 77 ''; 78 79 strictDeps = true; 80 81 dontConfigure = true; 82 dontInstall = true; 83 dontFixup = true; 84 85 outputHash = hash; 86 outputHashAlgo = if hash == "" then "sha256" else null; 87 outputHashMode = "recursive"; 88 } 89 // builtins.removeAttrs args removedArgs 90 ); 91in 92 93runCommand "${name}-vendor" 94 { 95 inherit vendorStaging; 96 nativeBuildInputs = [ 97 fetchCargoVendorUtil 98 cargo 99 replaceWorkspaceValues 100 ]; 101 } 102 '' 103 fetch-cargo-vendor-util create-vendor "$vendorStaging" "$out" 104 ''