From 1095dc1dd2a3ec219ca58b1bc9c452fe16540e59 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:48:18 -0400 Subject: [PATCH 1/9] lib.fetchers.normalizeHash: move lib inherits to toplevel --- lib/fetchers.nix | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index 402c18ab1fc4..f05c57a898e6 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -11,6 +11,19 @@ let sha256 = lib.fakeSha256; sha512 = lib.fakeSha512; }; + + inherit (lib) + concatMapStringsSep + head + tail + throwIf + ; + inherit (lib.attrsets) + attrsToList + intersectAttrs + removeAttrs + optionalAttrs + ; in rec { @@ -94,19 +107,6 @@ rec { required ? true, }: let - inherit (lib) - concatMapStringsSep - head - tail - throwIf - ; - inherit (lib.attrsets) - attrsToList - intersectAttrs - removeAttrs - optionalAttrs - ; - inherit (commonH hashTypes) hashNames hashSet; in args: From a6ff6c6bacee9e62e7b054785af667526aef6a51 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:49:03 -0400 Subject: [PATCH 2/9] lib.fetchers.withNormalizedHash: move lib inherits to toplevel --- lib/fetchers.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index f05c57a898e6..7a8174141be6 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -24,6 +24,8 @@ let removeAttrs optionalAttrs ; + + inherit (lib.trivial) functionArgs setFunctionArgs; in rec { @@ -195,9 +197,6 @@ rec { }: fetcher: let - inherit (lib.attrsets) intersectAttrs removeAttrs; - inherit (lib.trivial) functionArgs setFunctionArgs; - inherit (commonH hashTypes) hashSet; fArgs = functionArgs fetcher; From e4d668e9641bd830b8072f3c66364660e27da5e3 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:50:19 -0400 Subject: [PATCH 3/9] lib.fetchers: inherit commonH lib functions into global scope --- lib/fetchers.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index 7a8174141be6..87fc211676c2 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -3,7 +3,7 @@ let commonH = hashTypes: rec { hashNames = [ "hash" ] ++ hashTypes; - hashSet = lib.genAttrs hashNames (lib.const { }); + hashSet = genAttrs hashNames (const { }); }; fakeH = { @@ -21,11 +21,12 @@ let inherit (lib.attrsets) attrsToList intersectAttrs + genAttrs removeAttrs optionalAttrs ; - inherit (lib.trivial) functionArgs setFunctionArgs; + inherit (lib.trivial) const functionArgs setFunctionArgs; in rec { From 0466dc5b70f668101b03a5cca30bc99303403504 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:51:08 -0400 Subject: [PATCH 4/9] lib.fetchers.normalizeHash: remove unnecessary quotes --- lib/fetchers.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index 87fc211676c2..a2abddf89de4 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -113,7 +113,7 @@ rec { inherit (commonH hashTypes) hashNames hashSet; in args: - if args ? "outputHash" then + if args ? outputHash then args else let From a64ab557a09c60d260fe2330e97b136529ccdecb Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:53:22 -0400 Subject: [PATCH 5/9] lib.fetchers.normalizeHash: avoid expensive builtins.tail call --- lib/fetchers.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index a2abddf89de4..2ce5483e86e2 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -15,7 +15,7 @@ let inherit (lib) concatMapStringsSep head - tail + length throwIf ; inherit (lib.attrsets) @@ -125,7 +125,7 @@ rec { in if hashesAsNVPairs == [ ] then throwIf required "fetcher called without `hash`" null - else if tail hashesAsNVPairs != [ ] then + else if length hashesAsNVPairs != 1 then throw "fetcher called with mutually-incompatible arguments: ${ concatMapStringsSep ", " (a: a.name) hashesAsNVPairs }" From cb3f3435bbc4ee6a2068487f9911571b5b85a8ba Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:56:30 -0400 Subject: [PATCH 6/9] lib.fetchers: reuse default hash names between calls --- lib/fetchers.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index 2ce5483e86e2..d4ae5f7dd996 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -1,10 +1,14 @@ # snippets that can be shared by multiple fetchers (pkgs/build-support) { lib }: let - commonH = hashTypes: rec { - hashNames = [ "hash" ] ++ hashTypes; - hashSet = genAttrs hashNames (const { }); - }; + commonH = + let + defaultHashNames = [ "hash" ]; + in + hashTypes: rec { + hashNames = defaultHashNames ++ hashTypes; + hashSet = genAttrs hashNames (const { }); + }; fakeH = { hash = lib.fakeHash; From 35d9631df3297b16ae9bfe4c61d437a7a736db34 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:58:32 -0400 Subject: [PATCH 7/9] lib.fetchers: share default hash types between functions --- lib/fetchers.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index d4ae5f7dd996..e24f6c45d03d 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -16,6 +16,8 @@ let sha512 = lib.fakeSha512; }; + defaultHashTypes = [ "sha256" ]; + inherit (lib) concatMapStringsSep head @@ -110,7 +112,7 @@ rec { */ normalizeHash = { - hashTypes ? [ "sha256" ], + hashTypes ? defaultHashTypes, required ? true, }: let @@ -198,7 +200,7 @@ rec { */ withNormalizedHash = { - hashTypes ? [ "sha256" ], + hashTypes ? defaultHashTypes, }: fetcher: let From 25118b87ed055a0512dbba4d96b5d0100f0bd9bd Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 21:59:53 -0400 Subject: [PATCH 8/9] lib.fetchers.withNormalizedHash: define hashSet before taking fetcher --- lib/fetchers.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index e24f6c45d03d..36178ef7acf9 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -202,9 +202,11 @@ rec { { hashTypes ? defaultHashTypes, }: - fetcher: let inherit (commonH hashTypes) hashSet; + in + fetcher: + let fArgs = functionArgs fetcher; normalize = normalizeHash { From fb84fe6d6f90f61d354a43f39b023b1922d73be4 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 19 May 2026 22:04:44 -0400 Subject: [PATCH 9/9] lib.fetchers.withNormalizedHash: share removed attributes for every call --- lib/fetchers.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fetchers.nix b/lib/fetchers.nix index 36178ef7acf9..0f4192cc6822 100644 --- a/lib/fetchers.nix +++ b/lib/fetchers.nix @@ -199,6 +199,12 @@ rec { and is implemented somewhat more efficiently. */ withNormalizedHash = + let + removedAttributes = [ + "outputHash" + "outputHashAlgo" + ]; + in { hashTypes ? defaultHashTypes, }: @@ -219,10 +225,7 @@ rec { assert intersectAttrs fArgs hashSet == { }; setFunctionArgs (args: fetcher (normalize args)) ( - removeAttrs fArgs [ - "outputHash" - "outputHashAlgo" - ] + removeAttrs fArgs removedAttributes // { hash = fArgs.outputHash; }