summary refs log tree commit diff
diff options
context:
space:
mode:
authorfigsoda <figsoda@pm.me>2021-10-18 19:21:43 -0400
committerfigsoda <figsoda@pm.me>2021-10-19 20:56:46 -0400
commitf441e6b7f4574c85eb190b52390bbe61f355b514 (patch)
tree35a608dd550eb58572997f0cc8cdbd483374ab2c
parent836e6d3e021b56c84de76ff32f751ca4ea994079 (diff)
downloadnixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar.gz
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar.bz2
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar.lz
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar.xz
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.tar.zst
nixpkgs-f441e6b7f4574c85eb190b52390bbe61f355b514.zip
buildRustPackage,fetchCargoTarball: accept empty hashes
-rw-r--r--pkgs/build-support/rust/default.nix16
-rw-r--r--pkgs/build-support/rust/fetchCargoTarball.nix6
2 files changed, 8 insertions, 14 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix
index 840abb2d918..3d7057dd7d9 100644
--- a/pkgs/build-support/rust/default.nix
+++ b/pkgs/build-support/rust/default.nix
@@ -17,12 +17,6 @@
 
 { name ? "${args.pname}-${args.version}"
 
-  # SRI hash
-, cargoHash ? ""
-
-  # Legacy hash
-, cargoSha256 ? ""
-
   # Name for the vendored dependencies tarball
 , cargoDepsName ? name
 
@@ -54,7 +48,7 @@
 , buildAndTestSubdir ? null
 , ... } @ args:
 
-assert cargoVendorDir == null && cargoLock == null -> cargoSha256 == "" && cargoHash == ""
+assert cargoVendorDir == null && cargoLock == null -> !(args ? cargoSha256) && !(args ? cargoHash)
   -> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set";
 assert buildType == "release" || buildType == "debug";
 
@@ -66,15 +60,17 @@ let
     else fetchCargoTarball ({
       inherit src srcs sourceRoot unpackPhase cargoUpdateHook;
       name = cargoDepsName;
-      hash = cargoHash;
       patches = cargoPatches;
-      sha256 = cargoSha256;
+    } // lib.optionalAttrs (args ? cargoHash) {
+      hash = args.cargoHash;
+    } // lib.optionalAttrs (args ? cargoSha256) {
+      sha256 = args.cargoSha256;
     } // depsExtraArgs)
     else null;
 
   # If we have a cargoSha256 fixed-output derivation, validate it at build time
   # against the src fixed-output derivation to check consistency.
-  validateCargoDeps = !(cargoHash == "" && cargoSha256 == "");
+  validateCargoDeps = args ? cargoHash || args ? cargoSha256;
 
   target = rust.toRustTargetSpec stdenv.hostPlatform;
   targetIsJSON = lib.hasSuffix ".json" target;
diff --git a/pkgs/build-support/rust/fetchCargoTarball.nix b/pkgs/build-support/rust/fetchCargoTarball.nix
index 2e8830b4757..c2be9aac82d 100644
--- a/pkgs/build-support/rust/fetchCargoTarball.nix
+++ b/pkgs/build-support/rust/fetchCargoTarball.nix
@@ -22,15 +22,13 @@ in
 , srcs ? []
 , patches ? []
 , sourceRoot ? ""
-, hash ? ""
-, sha256 ? ""
 , cargoUpdateHook ? ""
 , ...
 } @ args:
 
 let hash_ =
-  if hash != "" then { outputHashAlgo = null; outputHash = hash; }
-  else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
+  if args ? hash then { outputHashAlgo = null; outputHash = args.hash; }
+  else if args ? sha256 then { outputHashAlgo = "sha256"; outputHash = args.sha256; }
   else throw "fetchCargoTarball requires a hash for ${name}";
 in stdenv.mkDerivation ({
   name = "${name}-vendor.tar.gz";