Merge pull request #142154 from figsoda/cargo-hash-default-null

buildRustPackage,fetchCargoTarball: accept empty hashes

authored by figsoda and committed by GitHub 5f33ded6 ce418102

+16 -24
+14 -20
pkgs/build-support/rust/default.nix
··· 1 - { stdenv 2 - , lib 3 - , buildPackages 1 + { lib 2 + , importCargoLock 3 + , fetchCargoTarball 4 + , rust 5 + , stdenv 6 + , callPackage 4 7 , cacert 8 + , git 5 9 , cargoBuildHook 6 10 , cargoCheckHook 7 11 , cargoInstallHook 8 12 , cargoSetupHook 9 - , fetchCargoTarball 10 - , importCargoLock 11 - , rustPlatform 12 - , callPackage 13 - , git 14 - , rust 15 13 , rustc 16 14 , libiconv 17 15 , windows ··· 19 17 20 18 { name ? "${args.pname}-${args.version}" 21 19 22 - # SRI hash 23 - , cargoHash ? "" 24 - 25 - # Legacy hash 26 - , cargoSha256 ? "" 27 - 28 20 # Name for the vendored dependencies tarball 29 21 , cargoDepsName ? name 30 22 ··· 56 48 , buildAndTestSubdir ? null 57 49 , ... } @ args: 58 50 59 - assert cargoVendorDir == null && cargoLock == null -> cargoSha256 == "" && cargoHash == "" 51 + assert cargoVendorDir == null && cargoLock == null -> !(args ? cargoSha256) && !(args ? cargoHash) 60 52 -> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set"; 61 53 assert buildType == "release" || buildType == "debug"; 62 54 ··· 68 60 else fetchCargoTarball ({ 69 61 inherit src srcs sourceRoot unpackPhase cargoUpdateHook; 70 62 name = cargoDepsName; 71 - hash = cargoHash; 72 63 patches = cargoPatches; 73 - sha256 = cargoSha256; 64 + } // lib.optionalAttrs (args ? cargoHash) { 65 + hash = args.cargoHash; 66 + } // lib.optionalAttrs (args ? cargoSha256) { 67 + sha256 = args.cargoSha256; 74 68 } // depsExtraArgs) 75 69 else null; 76 70 77 71 # If we have a cargoSha256 fixed-output derivation, validate it at build time 78 72 # against the src fixed-output derivation to check consistency. 79 - validateCargoDeps = !(cargoHash == "" && cargoSha256 == ""); 73 + validateCargoDeps = args ? cargoHash || args ? cargoSha256; 80 74 81 75 target = rust.toRustTargetSpec stdenv.hostPlatform; 82 76 targetIsJSON = lib.hasSuffix ".json" target; ··· 88 82 (lib.removeSuffix ".json" (builtins.baseNameOf "${target}")) 89 83 else target; 90 84 91 - sysroot = (callPackage ./sysroot {}) { 85 + sysroot = callPackage ./sysroot { } { 92 86 inherit target shortTarget; 93 87 RUSTFLAGS = args.RUSTFLAGS or ""; 94 88 originalCargoToml = src + /Cargo.toml; # profile info is later extracted
+2 -4
pkgs/build-support/rust/fetchCargoTarball.nix
··· 22 22 , srcs ? [] 23 23 , patches ? [] 24 24 , sourceRoot ? "" 25 - , hash ? "" 26 - , sha256 ? "" 27 25 , cargoUpdateHook ? "" 28 26 , ... 29 27 } @ args: 30 28 31 29 let hash_ = 32 - if hash != "" then { outputHashAlgo = null; outputHash = hash; } 33 - else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; } 30 + if args ? hash then { outputHashAlgo = null; outputHash = args.hash; } 31 + else if args ? sha256 then { outputHashAlgo = "sha256"; outputHash = args.sha256; } 34 32 else throw "fetchCargoTarball requires a hash for ${name}"; 35 33 in stdenv.mkDerivation ({ 36 34 name = "${name}-vendor.tar.gz";