From 52cd75da89af85a3850f5b32651bc29d24016183 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 4 Jun 2026 11:45:38 +0800 Subject: [PATCH 1/3] tests.overriding: attach fetchgit tests tests-fetchgit was implemented in commit 4e37d03ba265 ("fetchgit: reference hash from finalAttrs.hash"), but not attach to tests.overriding, hence this fix. (cherry picked from commit c7816616742f057d529e42963e2887115e5c060d) --- pkgs/test/overriding.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/test/overriding.nix b/pkgs/test/overriding.nix index 5e6fe09b7890..4f3f6cd0245e 100644 --- a/pkgs/test/overriding.nix +++ b/pkgs/test/overriding.nix @@ -8,6 +8,7 @@ let tests = tests-stdenv // test-extendMkDerivation + // tests-fetchgit // tests-fetchhg // tests-fetchurl // tests-go From 3ba6473fefb7c327ad672e8b7afa7ccbaef1c225 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 7 Jun 2026 13:25:38 +0800 Subject: [PATCH 2/3] tests.overriding: tests-fetchgit: use generated non-zero hashes Don't use zero hashes where the hash is supposed to be non-zero. Don't depend on nix.src.hash as nix.src might be wrapped to accept patches. (cherry picked from commit 7328b0d9f1a29debcdb29ab6c141fbacc292f6a6) --- pkgs/test/overriding.nix | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/pkgs/test/overriding.nix b/pkgs/test/overriding.nix index 4f3f6cd0245e..2c38c6bf17e8 100644 --- a/pkgs/test/overriding.nix +++ b/pkgs/test/overriding.nix @@ -148,11 +148,41 @@ let }; }; + /** + Take two positional arguments `fakeHash` and `partialHash`, + and return a modified version of fakeHash whose hash body is partially substituted by `partialHash` from the beginning, + used to assert a specific fake hash variant is used by an overridden FOD. + + # Inputs + + `fakeHash` + + : The specified zero fake hash + + `partialHash` + + : A trimmed non-zero hash body, to substitute the beginning of the zero hash body. + */ + genNonzeroFakeHash = + fakeHash: + let + isSRIHash = lib.hasInfix "-" fakeHash; + defaultHashAlgo = lib.optionalString isSRIHash lib.head (lib.splitString "-" lib.fakeHash); + defaultHashPrefix = lib.optionalString isSRIHash (defaultHashAlgo + "-"); + defaultHashBody = lib.removePrefix defaultHashPrefix fakeHash; + in + partialHash: + defaultHashPrefix + + partialHash + + (lib.substring (lib.stringLength partialHash) (lib.stringLength defaultHashBody) defaultHashBody); + tests-fetchgit = let + fakeSha256-1 = genNonzeroFakeHash lib.fakeSha256 "1"; + fakeHash-2 = genNonzeroFakeHash lib.fakeHash "B"; src-with-sha256 = pkgs.fetchgit { url = "https://example.com/source.git"; - sha256 = lib.fakeSha256; + sha256 = fakeSha256-1; }; in { @@ -164,19 +194,19 @@ let ; }; expected = { - outputHash = lib.fakeSha256; + outputHash = fakeSha256-1; outputHashAlgo = "sha256"; }; }; test-fetchgit-overrideAttrs-hash = { expr = { - inherit (src-with-sha256.overrideAttrs { hash = pkgs.nix.src.hash; }) + inherit (src-with-sha256.overrideAttrs { hash = fakeHash-2; }) outputHash outputHashAlgo ; }; expected = { - outputHash = pkgs.nix.src.hash; + outputHash = fakeHash-2; outputHashAlgo = null; }; }; From e360c79eb563097eae87c5f7b8cd9129302cb995 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 7 Jun 2026 13:25:38 +0800 Subject: [PATCH 3/3] tests.overriding: tests-fetchurl: use generated non-zero hashes Don't use zero hashes where the hash is supposed to be non-zero. Don't depend on nix.src.hash as nix.src might be wrapped to accept patches. (cherry picked from commit eb76b98770601cfd6888240612b68499010f04c1) --- pkgs/test/overriding.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/test/overriding.nix b/pkgs/test/overriding.nix index 2c38c6bf17e8..f0244c530bf4 100644 --- a/pkgs/test/overriding.nix +++ b/pkgs/test/overriding.nix @@ -226,9 +226,11 @@ let tests-fetchurl = let + fakeSha256-1 = genNonzeroFakeHash lib.fakeSha256 "1"; + fakeHash-2 = genNonzeroFakeHash lib.fakeHash "B"; src-with-sha256 = pkgs.fetchurl { url = "https://example.com/source.tar.gz"; - sha256 = lib.fakeSha256; + sha256 = fakeSha256-1; }; in { @@ -240,19 +242,19 @@ let ; }; expected = { - outputHash = lib.fakeSha256; + outputHash = fakeSha256-1; outputHashAlgo = "sha256"; }; }; test-fetchurl-overrideAttrs-hash = { expr = { - inherit (src-with-sha256.overrideAttrs { hash = pkgs.hello.src.hash; }) + inherit (src-with-sha256.overrideAttrs { hash = fakeHash-2; }) outputHash outputHashAlgo ; }; expected = { - outputHash = pkgs.hello.src.hash; + outputHash = fakeHash-2; outputHashAlgo = null; }; };