fetchgit: reference hash from finalAttrs.hash
This commit is contained in:
@@ -47,7 +47,7 @@ lib.makeOverridable (
|
|||||||
|
|
||||||
# Hashes, handled by `lib.fetchers.withNormalizedHash`
|
# Hashes, handled by `lib.fetchers.withNormalizedHash`
|
||||||
# whose outputs contain outputHash* attributes.
|
# whose outputs contain outputHash* attributes.
|
||||||
"hash"
|
# Use `hash` when overriding with `<pkg>.overrideAttrs`.
|
||||||
"sha256"
|
"sha256"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -131,6 +131,11 @@ lib.makeOverridable (
|
|||||||
server admins start using the new version?
|
server admins start using the new version?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let
|
||||||
|
finalHashHasColon = lib.hasInfix ":" finalAttrs.hash;
|
||||||
|
finalHashColonMatch = lib.match "([^:]+)[:](.*)" finalAttrs.hash;
|
||||||
|
in
|
||||||
|
|
||||||
derivationArgs
|
derivationArgs
|
||||||
// {
|
// {
|
||||||
inherit name;
|
inherit name;
|
||||||
@@ -145,7 +150,20 @@ lib.makeOverridable (
|
|||||||
++ lib.optionals fetchLFS [ git-lfs ]
|
++ lib.optionals fetchLFS [ git-lfs ]
|
||||||
++ nativeBuildInputs;
|
++ nativeBuildInputs;
|
||||||
|
|
||||||
inherit outputHash outputHashAlgo;
|
hash =
|
||||||
|
if outputHashAlgo == null || outputHash == "" || lib.hasPrefix outputHashAlgo outputHash then
|
||||||
|
outputHash
|
||||||
|
else
|
||||||
|
"${outputHashAlgo}:${outputHash}";
|
||||||
|
|
||||||
|
outputHash =
|
||||||
|
if finalAttrs.hash == "" then
|
||||||
|
lib.fakeHash
|
||||||
|
else if finalHashHasColon then
|
||||||
|
lib.elemAt finalHashColonMatch 1
|
||||||
|
else
|
||||||
|
finalAttrs.hash;
|
||||||
|
outputHashAlgo = if finalHashHasColon then lib.head finalHashColonMatch else null;
|
||||||
outputHashMode = "recursive";
|
outputHashMode = "recursive";
|
||||||
|
|
||||||
sparseCheckout =
|
sparseCheckout =
|
||||||
|
|||||||
@@ -137,6 +137,52 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tests-fetchgit =
|
||||||
|
let
|
||||||
|
src-with-sha256 = pkgs.fetchgit {
|
||||||
|
url = "https://example.com/source.git";
|
||||||
|
sha256 = lib.fakeSha256;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
test-fetchgit-hash-compat = {
|
||||||
|
expr = {
|
||||||
|
inherit (src-with-sha256)
|
||||||
|
outputHash
|
||||||
|
outputHashAlgo
|
||||||
|
;
|
||||||
|
};
|
||||||
|
expected = {
|
||||||
|
outputHash = lib.fakeSha256;
|
||||||
|
outputHashAlgo = "sha256";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
test-fetchgit-overrideAttrs-hash = {
|
||||||
|
expr = {
|
||||||
|
inherit (src-with-sha256.overrideAttrs { hash = pkgs.nix.src.hash; })
|
||||||
|
outputHash
|
||||||
|
outputHashAlgo
|
||||||
|
;
|
||||||
|
};
|
||||||
|
expected = {
|
||||||
|
outputHash = pkgs.nix.src.hash;
|
||||||
|
outputHashAlgo = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
test-fetchurl-overrideAttrs-hash-empty = {
|
||||||
|
expr = {
|
||||||
|
inherit (src-with-sha256.overrideAttrs { hash = ""; })
|
||||||
|
outputHash
|
||||||
|
outputHashAlgo
|
||||||
|
;
|
||||||
|
};
|
||||||
|
expected = {
|
||||||
|
outputHash = lib.fakeHash;
|
||||||
|
outputHashAlgo = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
tests-fetchurl =
|
tests-fetchurl =
|
||||||
let
|
let
|
||||||
src-with-sha256 = pkgs.fetchurl {
|
src-with-sha256 = pkgs.fetchurl {
|
||||||
|
|||||||
Reference in New Issue
Block a user