Skip to content

Commit

Permalink
fetchurl (and derived functions): Support SRI hashes
Browse files Browse the repository at this point in the history
E.g.

  fetchFromGitHub {
    owner = "NixOS";
    repo = "nix";
    rev = "ad42a784690449873fccb20192bd2150da81c56d";
    hash = "sha256-ZXeadXUJMXV5lSLz6TOBeL/SSOVwQ8ywxU5AFMCnbRU=";
  }
  • Loading branch information
edolstra committed Jul 11, 2019
1 parent 528a690 commit 267c8d6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkgs/build-support/fetchurl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ in
# first element of `urls').
name ? ""

# Different ways of specifying the hash.
, outputHash ? ""
, # SRI hash.
hash ? ""

, # Legacy ways of specifying the hash.
outputHash ? ""
, outputHashAlgo ? ""
, md5 ? ""
, sha1 ? ""
Expand Down Expand Up @@ -103,7 +106,8 @@ let
else throw "fetchurl requires either `url` or `urls` to be set";

hash_ =
if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
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; }
else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
Expand Down

0 comments on commit 267c8d6

Please sign in to comment.