Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchurl: accept SRI in hex and base32 #199660

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/firefox/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rec {
version = "106.0.5";
src = fetchurl {
url = "mirror://mozilla/firefox/releases/${version}/source/firefox-${version}.source.tar.xz";
sha512 = "879b054340d632c5d972888ceb67da0d02f28f6755e9683c8e4e7fb71b55bde0e588b98e24bae448ffea8ddd3e30c44dc0563554ecd69506862796a64ca040d7";
hash = "sha512-879b054340d632c5d972888ceb67da0d02f28f6755e9683c8e4e7fb71b55bde0e588b98e24bae448ffea8ddd3e30c44dc0563554ecd69506862796a64ca040d7";
};

# This patch could be applied anywhere (just rebuild, no effect)
Expand Down
11 changes: 10 additions & 1 deletion pkgs/build-support/fetchurl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,20 @@ let
else throw "`url` is not a string")
else throw "fetchurl requires either `url` or `urls` to be set";

hash_split = lib.splitString "-" hash; # note: our base64 never allows "-" inside
hash_hash = if lib.length hash_split != 2 then "" else lib.elemAt hash_split 1;

hash_ =
# Many other combinations don't make sense, but this is the most common one:
if hash != "" && sha256 != "" then throw "multiple hashes passed to fetchurl" else

if hash != "" then { outputHashAlgo = null; outputHash = hash; }
if lib.head hash_split == "sha256"
&& (lib.stringLength hash_hash == 64 || lib.stringLength hash_hash == 52)
then { outputHashAlgo = "sha256"; outputHash = hash_hash; }
else if lib.head hash_split == "sha512"
&& (lib.stringLength hash_hash == 128 || lib.stringLength hash_hash == 103)
then { outputHashAlgo = "sha512"; outputHash = hash_hash; }
else if hash != "" then { outputHashAlgo = null; outputHash = hash; }
else if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
else if (outputHash != "" && outputHashAlgo != "") then { inherit outputHashAlgo outputHash; }
else if sha512 != "" then { outputHashAlgo = "sha512"; outputHash = sha512; }
Expand Down
2 changes: 1 addition & 1 deletion pkgs/servers/dns/knot-resolver/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ unwrapped = stdenv.mkDerivation rec {

src = fetchurl {
url = "https://secure.nic.cz/files/knot-resolver/${pname}-${version}.tar.xz";
sha256 = "a38f57c68b7d237d662784d8406e6098aad66a148f44dcf498d1e9664c5fed2d";
hash = "sha256-a38f57c68b7d237d662784d8406e6098aad66a148f44dcf498d1e9664c5fed2d";
};

outputs = [ "out" "dev" ];
Expand Down