Skip to content

Commit

Permalink
fetchgit: Sync hash support with fetchurl
Browse files Browse the repository at this point in the history
Including SRI hash support
  • Loading branch information
jtojnar committed Feb 13, 2020
1 parent a01d0bc commit 292a499
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions pkgs/build-support/fetchgit/default.nix
Expand Up @@ -12,7 +12,22 @@
else "";
in "${if matched == null then base else builtins.head matched}${appendShort}";
in
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
{ url
, rev ? "HEAD"

, # SRI hash.
hash ? ""

, # Legacy ways of specifying the hash.
outputHash ? ""
, outputHashAlgo ? ""
, md5 ? ""
, sha1 ? ""
, sha256 ? ""
, sha512 ? ""

, # Git-related options.
leaveDotGit ? deepClone
, fetchSubmodules ? true, deepClone ? false
, branchName ? null
, name ? urlToName url rev
Expand Down Expand Up @@ -46,18 +61,23 @@ in

assert deepClone -> leaveDotGit;

if md5 != "" then
throw "fetchgit does not support md5 anymore, please use sha256"
else
stdenvNoCC.mkDerivation {
let
hash_ =
if hash != "" then { outputHashAlgo = null; outputHash = hash; }
else if md5 != "" then throw "fetchgit 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; }
else if sha1 != "" then { outputHashAlgo = "sha1"; outputHash = sha1; }
else throw "fetchgit requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}";
in stdenvNoCC.mkDerivation {
inherit name;
builder = ./builder.sh;
fetcher = ./nix-prefetch-git; # This must be a string to ensure it's called with bash.
nativeBuildInputs = [git];

outputHashAlgo = "sha256";
inherit (_hash) outputHashAlgo outputHash;
outputHashMode = "recursive";
outputHash = sha256;

inherit url rev leaveDotGit fetchSubmodules deepClone branchName postFetch;

Expand Down

0 comments on commit 292a499

Please sign in to comment.