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