From 4ab091862ab9f03a867d7ad34c7dfbbcae31db27 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:26:04 +0800 Subject: [PATCH 01/14] fetchurl: take derivationArgs --- pkgs/build-support/fetchurl/default.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index 88e7bfaa7809b..b9a640563e36a 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -60,6 +60,9 @@ lib.extendMkDerivation { # Passed via passthru "url" + # Additional stdenv.mkDerivation arguments from derived fetchers. + "derivationArgs" + # Hash attributes will be map to the corresponding outputHash* "hash" "sha1" @@ -139,6 +142,11 @@ lib.extendMkDerivation { # Additional packages needed as part of a fetch nativeBuildInputs ? [ ], + + # Additional stdenvNoCC.mkDerivation arguments. + # It is typically for derived fetchers to pass down additional arguments, + # and the specified arguments have lower precedence than other mkDerivation arguments. + derivationArgs ? { }, }@args: let @@ -228,7 +236,8 @@ lib.extendMkDerivation { "${lib.head mirrorList}${lib.elemAt mirrorSplit 1}"; in - { + derivationArgs + // { name = if pname != null && version != null then "${finalAttrs.pname}-${finalAttrs.version}" From b29af41b6e685738ac710000f51d4b56954413bf Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:35:31 +0800 Subject: [PATCH 02/14] fetchzip: make overridable extension and stripRoot with derivationArgs --- pkgs/build-support/fetchzip/default.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index 830f68085f762..d25f1f0e39436 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -20,7 +20,7 @@ lib.extendMkDerivation { excludeDrvArgNames = [ "extraPostFetch" - # TODO(@ShamrockLee): Move these arguments to derivationArgs when available. + # Pass via derivationArgs "extension" "stripRoot" ]; @@ -48,8 +48,8 @@ lib.extendMkDerivation { let tmpFilename = - if extension != null then - "download.${extension}" + if finalAttrs.extension != null then + "download.${finalAttrs.extension}" else baseNameOf (if url != "" then url else builtins.head urls); in @@ -81,7 +81,7 @@ lib.extendMkDerivation { chmod -R +w "$unpackDir" '' + ( - if stripRoot then + if finalAttrs.stripRoot then '' if [ $(ls -A "$unpackDir" | wc -l) != 1 ]; then echo "error: zip file must contain a single file or directory." @@ -109,5 +109,12 @@ lib.extendMkDerivation { ''; # ^ Remove non-owner write permissions # Fixes https://github.com/NixOS/nixpkgs/issues/38649 + + derivationArgs = { + inherit + extension + stripRoot + ; + }; }; } From 0fc9eec2e5d2cf8e69be5516752ffa657ab36336 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:36:33 +0800 Subject: [PATCH 03/14] fetchzip: take derivationArgs --- pkgs/build-support/fetchzip/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index d25f1f0e39436..4376fef410854 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -42,6 +42,11 @@ lib.extendMkDerivation { # an appropriate unpacking tool. extension ? null, + # Additional stdenvNoCC.mkDerivation arguments. + # It is typically for derived fetchers to pass down additional arguments, + # and the specified arguments have lower precedence than other mkDerivation arguments. + derivationArgs ? { }, + # the rest are given to fetchurl as is ... }@args: @@ -110,7 +115,7 @@ lib.extendMkDerivation { # ^ Remove non-owner write permissions # Fixes https://github.com/NixOS/nixpkgs/issues/38649 - derivationArgs = { + derivationArgs = derivationArgs // { inherit extension stripRoot From 38f61c3f10b92e92933a5e048a93618493527c35 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:39:21 +0800 Subject: [PATCH 04/14] fetchgit: take derivationArgs --- pkgs/build-support/fetchgit/default.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 4ffb998ee205d..e3566f5627eec 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -30,6 +30,9 @@ lib.makeOverridable ( # Passed via `passthru` "tag" + # Additional stdenv.mkDerivation arguments from derived fetchers. + "derivationArgs" + # Hashes, handled by `lib.fetchers.withNormalizedHash` # whose outputs contain outputHash* attributes. "hash" @@ -84,6 +87,10 @@ lib.makeOverridable ( rootDir ? "", # GIT_CONFIG_GLOBAL (as a file) gitConfigFile ? config.gitConfigFile, + # Additional stdenvNoCC.mkDerivation arguments. + # It is typically for derived fetchers to pass down additional arguments, + # and the specified arguments have lower precedence than other mkDerivation arguments. + derivationArgs ? { }, }: /* @@ -135,7 +142,8 @@ lib.makeOverridable ( throw "Please provide directories/patterns for sparse checkout as a list of strings. Passing a (multi-line) string is not supported any more." else - { + derivationArgs + // { inherit name; builder = ./builder.sh; From 076076e946319c40a9f787dc0a148c6025d73906 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:52:38 +0800 Subject: [PATCH 05/14] fetchgit: abstract and simplify revWithTag --- pkgs/build-support/fetchgit/default.nix | 34 ++++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index e3566f5627eec..80d56ff501cac 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -20,6 +20,21 @@ let appendShort = lib.optionalString ((builtins.match "[a-f0-9]*" rev) != null) "-${shortRev}"; in "${lib.sources.urlToName url}${if append == "" then appendShort else append}"; + + getRevWithTag = + { + rev ? null, + tag ? null, + }: + if tag != null && rev != null then + throw "fetchgit requires one of either `rev` or `tag` to be provided (not both)." + else if tag != null then + "refs/tags/${tag}" + else if rev != null then + rev + else + # FIXME fetching HEAD if no rev or tag is provided is problematic at best + "HEAD"; in lib.makeOverridable ( @@ -120,23 +135,6 @@ lib.makeOverridable ( assert fetchTags -> leaveDotGit; assert rootDir != "" -> !leaveDotGit; - let - revWithTag = - let - warningMsg = "fetchgit requires one of either `rev` or `tag` to be provided (not both)."; - otherIsNull = other: lib.assertMsg (other == null) warningMsg; - in - if tag != null then - assert (otherIsNull rev); - "refs/tags/${tag}" - else if rev != null then - assert (otherIsNull tag); - rev - else - # FIXME fetching HEAD if no rev or tag is provided is problematic at best - "HEAD"; - in - if builtins.isString sparseCheckout then # Changed to throw on 2023-06-04 throw @@ -178,7 +176,7 @@ lib.makeOverridable ( rootDir gitConfigFile ; - rev = revWithTag; + rev = getRevWithTag { inherit tag rev; }; postHook = if netrcPhase == null then From dbf76b7c1befc9702c8ba81ef3f5448ba4642b1e Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:55:50 +0800 Subject: [PATCH 06/14] fetchgit: pass tag directly and make overridable --- pkgs/build-support/fetchgit/default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 80d56ff501cac..9b6085f1c7fd8 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -42,9 +42,6 @@ lib.makeOverridable ( constructDrv = stdenvNoCC.mkDerivation; excludeDrvArgNames = [ - # Passed via `passthru` - "tag" - # Additional stdenv.mkDerivation arguments from derived fetchers. "derivationArgs" @@ -65,7 +62,7 @@ lib.makeOverridable ( rev ? null, name ? urlToName { inherit url; - rev = lib.revOrTag rev tag; + rev = lib.revOrTag rev finalAttrs.tag; # when rootDir is specified, avoid invalidating the result when rev changes append = if rootDir != "" then "-${lib.strings.sanitizeDerivationName rootDir}" else ""; }, @@ -176,7 +173,11 @@ lib.makeOverridable ( rootDir gitConfigFile ; - rev = getRevWithTag { inherit tag rev; }; + inherit tag; + rev = getRevWithTag { + inherit (finalAttrs) tag; + inherit rev; + }; postHook = if netrcPhase == null then @@ -216,7 +217,6 @@ lib.makeOverridable ( passthru = { gitRepoUrl = url; - inherit tag; } // passthru; } From 21677a6bd861ff4b15389dc909bae58201de86ec Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 21:59:05 +0800 Subject: [PATCH 07/14] fetchgit: pass rev as revCustom and make overridable --- pkgs/build-support/fetchgit/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 9b6085f1c7fd8..445b11347c635 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -62,7 +62,7 @@ lib.makeOverridable ( rev ? null, name ? urlToName { inherit url; - rev = lib.revOrTag rev finalAttrs.tag; + rev = lib.revOrTag finalAttrs.revCustom finalAttrs.tag; # when rootDir is specified, avoid invalidating the result when rev changes append = if rootDir != "" then "-${lib.strings.sanitizeDerivationName rootDir}" else ""; }, @@ -174,9 +174,10 @@ lib.makeOverridable ( gitConfigFile ; inherit tag; + revCustom = rev; rev = getRevWithTag { inherit (finalAttrs) tag; - inherit rev; + rev = finalAttrs.revCustom; }; postHook = From 29465554113e2b7bb110c27ab436bf551acb239a Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:01:21 +0800 Subject: [PATCH 08/14] fetchgit: expose getRevWithTag as fetchgit.getRevWithTag --- pkgs/build-support/fetchgit/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 445b11347c635..5a8ea3cf04880 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -227,3 +227,6 @@ lib.makeOverridable ( inheritFunctionArgs = false; } ) +// { + inherit getRevWithTag; +} From e0ba367c2bfc078426b746ec0c3d8275b7b40f68 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:01:57 +0800 Subject: [PATCH 09/14] fetchFromGitHub: pass meta via fetcherArgs --- pkgs/build-support/fetchgithub/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index c25c86e6f772e..e25ee6bc53ed6 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -158,12 +158,12 @@ lib.makeOverridable ( // privateAttrs // { inherit name; + meta = newMeta; }; in fetcher fetcherArgs // { - meta = newMeta; inherit owner repo tag; rev = revWithTag; } From dd9af80094766dbbf27364b0cb81d53f21d383f0 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:09:11 +0800 Subject: [PATCH 10/14] fetchFromGitHub: pass owner and repo via derivationArgs --- pkgs/build-support/fetchgithub/default.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index e25ee6bc53ed6..481de15afa91f 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -113,6 +113,7 @@ lib.makeOverridable ( revWithTag = if tag != null then "refs/tags/${tag}" else rev; fetcherArgs = + finalAttrs: passthruAttrs // ( if useFetchGit then @@ -127,6 +128,12 @@ lib.makeOverridable ( ; url = gitRepoUrl; inherit passthru; + derivationArgs = { + inherit + owner + repo + ; + }; } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } else @@ -139,7 +146,7 @@ lib.makeOverridable ( url = if private then let - endpoint = "/repos/${owner}/${repo}/tarball/${revWithTag}"; + endpoint = "/repos/${finalAttrs.owner}/${finalAttrs.repo}/tarball/${revWithTag}"; in if githubBase == "github.com" then "https://api.github.com${endpoint}" @@ -148,7 +155,12 @@ lib.makeOverridable ( else "${baseUrl}/archive/${revWithTag}.tar.gz"; extension = "tar.gz"; - + derivationArgs = { + inherit + owner + repo + ; + }; passthru = { inherit gitRepoUrl; } From 3754cf57cf224d5d6d4ac753cba052fe23451e34 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:11:54 +0800 Subject: [PATCH 11/14] fetchFromGitHub: pass tag to mkDerivation uniformly --- pkgs/build-support/fetchgithub/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index 481de15afa91f..ea40c6adbd555 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -159,6 +159,7 @@ lib.makeOverridable ( inherit owner repo + tag ; }; passthru = { @@ -176,7 +177,6 @@ lib.makeOverridable ( fetcher fetcherArgs // { - inherit owner repo tag; rev = revWithTag; } ) From aede4d203cdb2a3d2d0cecb1d56320538e123a70 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:16:10 +0800 Subject: [PATCH 12/14] fetchFromGitHub: pass rev uniformly --- pkgs/build-support/fetchgithub/default.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index ea40c6adbd555..4c3ea354fa688 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -110,8 +110,6 @@ lib.makeOverridable ( gitRepoUrl = "${baseUrl}.git"; - revWithTag = if tag != null then "refs/tags/${tag}" else rev; - fetcherArgs = finalAttrs: passthruAttrs @@ -137,6 +135,9 @@ lib.makeOverridable ( } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } else + let + revWithTag = finalAttrs.rev; + in { # Use the API endpoint for private repos, as the archive URI doesn't # support access with GitHub's fine-grained access tokens. @@ -161,6 +162,11 @@ lib.makeOverridable ( repo tag ; + rev = fetchgit.getRevWithTag { + inherit (finalAttrs) tag; + rev = finalAttrs.revCustom; + }; + revCustom = rev; }; passthru = { inherit gitRepoUrl; @@ -176,7 +182,4 @@ lib.makeOverridable ( in fetcher fetcherArgs - // { - rev = revWithTag; - } ) From 4e996b39209dbb39495e7d6b3b272101bba7ba95 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 29 Oct 2025 22:34:11 +0800 Subject: [PATCH 13/14] fetchFromGitHub: make name respect overridden arguments --- pkgs/build-support/fetchgithub/default.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index 4c3ea354fa688..ac8698caeb29d 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -11,7 +11,8 @@ lib.makeOverridable ( repo, tag ? null, rev ? null, - name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "github", + # TODO(@ShamrockLee): Add back after reconstruction with lib.extendMkDerivation + # name ? repoRevToNameMaybe finalAttrs.repo (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) "github", fetchSubmodules ? false, leaveDotGit ? null, deepClone ? false, @@ -176,7 +177,10 @@ lib.makeOverridable ( ) // privateAttrs // { - inherit name; + # TODO(@ShamrockLee): Change back to `inherit name;` after reconstruction with lib.extendMkDerivation + name = + args.name + or (repoRevToNameMaybe finalAttrs.repo (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) "github"); meta = newMeta; }; in From 8bb3bbbf44c5af916de98e01829ca1e207df3679 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 30 Oct 2025 04:44:07 +0800 Subject: [PATCH 14/14] fetchFromGitHub: pass githubBase to mkDerivation via derivationArgs Reduce future test rebuilds when making githubBase overridable. --- pkgs/build-support/fetchgithub/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index ac8698caeb29d..ae5ff338264a2 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -129,6 +129,7 @@ lib.makeOverridable ( inherit passthru; derivationArgs = { inherit + githubBase owner repo ; @@ -159,6 +160,7 @@ lib.makeOverridable ( extension = "tar.gz"; derivationArgs = { inherit + githubBase owner repo tag