mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-13 00:34:04 +00:00
fetchgit: reference hash from finalAttrs.hash
This commit is contained in:
@@ -47,7 +47,7 @@ lib.makeOverridable (
|
||||
|
||||
# Hashes, handled by `lib.fetchers.withNormalizedHash`
|
||||
# whose outputs contain outputHash* attributes.
|
||||
"hash"
|
||||
# Use `hash` when overriding with `<pkg>.overrideAttrs`.
|
||||
"sha256"
|
||||
];
|
||||
|
||||
@@ -131,6 +131,11 @@ lib.makeOverridable (
|
||||
server admins start using the new version?
|
||||
*/
|
||||
|
||||
let
|
||||
finalHashHasColon = lib.hasInfix ":" finalAttrs.hash;
|
||||
finalHashColonMatch = lib.match "([^:]+)[:](.*)" finalAttrs.hash;
|
||||
in
|
||||
|
||||
derivationArgs
|
||||
// {
|
||||
inherit name;
|
||||
@@ -145,7 +150,20 @@ lib.makeOverridable (
|
||||
++ lib.optionals fetchLFS [ git-lfs ]
|
||||
++ 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";
|
||||
|
||||
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 =
|
||||
let
|
||||
src-with-sha256 = pkgs.fetchurl {
|
||||
|
||||
Reference in New Issue
Block a user