about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorWeijia Wang <9713184+wegank@users.noreply.github.com>2023-04-22 23:42:32 +0300
committerGitHub <noreply@github.com>2023-04-22 23:42:32 +0300
commit1d76b4d7f17bbd7ac686499837c14911c3a0c7aa (patch)
tree3ce74ad0bbf208cd03665317dd8664495542f622 /pkgs/build-support
parent38594268d2e0eadf5e519d85b08e7f4f6721ab58 (diff)
parent3687bee81c0c06f06c3aa0b112232a6e1dac4623 (diff)
Merge pull request #227634 from GenericNerdyUsername/requireFile-hash
`requireFile`: allow using `hash` instead of `sha256`/`sha1`
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/trivial-builders.nix13
1 files changed, 9 insertions, 4 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 8694c602a3b91..e90d0a6d20229 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -785,12 +785,13 @@ rec {
   requireFile = { name ? null
                 , sha256 ? null
                 , sha1 ? null
+                , hash ? null
                 , url ? null
                 , message ? null
                 , hashMode ? "flat"
                 } :
     assert (message != null) || (url != null);
-    assert (sha256 != null) || (sha1 != null);
+    assert (sha256 != null) || (sha1 != null) || (hash != null);
     assert (name != null) || (url != null);
     let msg =
       if message != null then message
@@ -802,15 +803,19 @@ rec {
         or
           nix-prefetch-url --type ${hashAlgo} file:///path/to/${name_}
       '';
-      hashAlgo = if sha256 != null then "sha256" else "sha1";
-      hash = if sha256 != null then sha256 else sha1;
+      hashAlgo = if hash != null then ""
+            else if sha256 != null then "sha256"
+            else "sha1";
+      hash_ = if hash != null then hash
+         else if sha256 != null then sha256
+         else sha1;
       name_ = if name == null then baseNameOf (toString url) else name;
     in
     stdenvNoCC.mkDerivation {
       name = name_;
       outputHashMode = hashMode;
       outputHashAlgo = hashAlgo;
-      outputHash = hash;
+      outputHash = hash_;
       preferLocalBuild = true;
       allowSubstitutes = false;
       builder = writeScript "restrict-message" ''