nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 107 lines 2.4 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 = 26 with python3Packages; 27 [ 28 requests 29 ] 30 ++ requests.optional-dependencies.socks; # to support socks proxy envs like ALL_PROXY in requests 31 flakeIgnore = [ 32 "E501" 33 ]; 34 } (builtins.readFile ./fetch-cargo-vendor-util.py); 35in 36 37{ 38 name ? if args ? pname && args ? version then "${args.pname}-${args.version}" else "cargo-deps", 39 hash ? (throw "fetchCargoVendor requires a `hash` value to be set for ${name}"), 40 nativeBuildInputs ? [ ], 41 ... 42}@args: 43 44# TODO: add asserts about pname version and name 45 46let 47 removedArgs = [ 48 "name" 49 "pname" 50 "version" 51 "nativeBuildInputs" 52 "hash" 53 ]; 54 55 vendorStaging = stdenvNoCC.mkDerivation ( 56 { 57 name = "${name}-vendor-staging"; 58 59 impureEnvVars = lib.fetchers.proxyImpureEnvVars; 60 61 nativeBuildInputs = [ 62 fetchCargoVendorUtil 63 cacert 64 # break loop of nix-prefetch-git -> git-lfs -> asciidoctor -> ruby (yjit) -> fetchCargoVendor -> nix-prefetch-git 65 # Cargo does not currently handle git-lfs: https://github.com/rust-lang/cargo/issues/9692 66 (nix-prefetch-git.override { git-lfs = null; }) 67 ] 68 ++ nativeBuildInputs; 69 70 buildPhase = '' 71 runHook preBuild 72 73 if [ -n "''${cargoRoot-}" ]; then 74 cd "$cargoRoot" 75 fi 76 77 fetch-cargo-vendor-util create-vendor-staging ./Cargo.lock "$out" 78 79 runHook postBuild 80 ''; 81 82 strictDeps = true; 83 84 dontConfigure = true; 85 dontInstall = true; 86 dontFixup = true; 87 88 outputHash = hash; 89 outputHashAlgo = if hash == "" then "sha256" else null; 90 outputHashMode = "recursive"; 91 } 92 // removeAttrs args removedArgs 93 ); 94in 95 96runCommand "${name}-vendor" 97 { 98 inherit vendorStaging; 99 nativeBuildInputs = [ 100 fetchCargoVendorUtil 101 cargo 102 replaceWorkspaceValues 103 ]; 104 } 105 '' 106 fetch-cargo-vendor-util create-vendor "$vendorStaging" "$out" 107 ''