git.iko.soy/typeable/nixpkgs
on master help sign in
fetchurl (and derived functions): Support SRI hashes

E.g. fetchFromGitHub { owner = "NixOS"; repo = "nix"; rev = "ad42a784690449873fccb20192bd2150da81c56d"; hash = "sha256-ZXeadXUJMXV5lSLz6TOBeL/SSOVwQ8ywxU5AFMCnbRU="; }

commit267c8d6b2fea05bc811c8e2c2f4529b1436eeb9a authorEelco Dolstra <edolstra@gmail.com> dateThu 11 Jul 2019, 15:48 (7 years ago) parent528a690
1 file changed+7−3
pkgs/build-support/fetchurl/default.nix+7−3
pkgs/build-support/fetchurl/default.nix+7−3
@@ -49,8 +49,11 @@ in
4949 # first element of `urls').
5050 name ? ""
5151
52− # Different ways of specifying the hash.
53−, outputHash ? ""
52+, # SRI hash.
53+ hash ? ""
54+
55+, # Legacy ways of specifying the hash.
56+ outputHash ? ""
5457, outputHashAlgo ? ""
5558, md5 ? ""
5659, sha1 ? ""
@@ -103,7 +106,8 @@ let
103106 else throw "fetchurl requires either `url` or `urls` to be set";
104107
105108 hash_ =
106− if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
109+ if hash != "" then { outputHashAlgo = null; outputHash = hash; }
110+ else if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
107111 else if (outputHash != "" && outputHashAlgo != "") then { inherit outputHashAlgo outputHash; }
108112 else if sha512 != "" then { outputHashAlgo = "sha512"; outputHash = sha512; }
109113 else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }