From 1d6c7d66505debebd6bdc5877d45f8833c4616b5 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Fri, 14 Nov 2025 13:27:51 +0800 Subject: [PATCH 01/13] fetchgit: move assertions down to argument values --- pkgs/build-support/fetchgit/default.nix | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 5a8ea3cf0488..4d0c2c7af8b1 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -128,10 +128,6 @@ lib.makeOverridable ( server admins start using the new version? */ - assert nonConeMode -> (sparseCheckout != [ ]); - assert fetchTags -> leaveDotGit; - assert rootDir != "" -> !leaveDotGit; - if builtins.isString sparseCheckout then # Changed to throw on 2023-06-04 throw @@ -154,14 +150,15 @@ lib.makeOverridable ( inherit outputHash outputHashAlgo; outputHashMode = "recursive"; - # git-sparse-checkout(1) says: - # > When the --stdin option is provided, the directories or patterns are read - # > from standard in as a newline-delimited list instead of from the arguments. - sparseCheckout = builtins.concatStringsSep "\n" sparseCheckout; + sparseCheckout = + assert nonConeMode -> (sparseCheckout != [ ]); + # git-sparse-checkout(1) says: + # > When the --stdin option is provided, the directories or patterns are read + # > from standard in as a newline-delimited list instead of from the arguments. + builtins.concatStringsSep "\n" sparseCheckout; inherit url - leaveDotGit fetchLFS fetchSubmodules deepClone @@ -173,6 +170,10 @@ lib.makeOverridable ( rootDir gitConfigFile ; + leaveDotGit = + assert fetchTags -> leaveDotGit; + assert rootDir != "" -> !leaveDotGit; + leaveDotGit; inherit tag; revCustom = rev; rev = getRevWithTag { From 9fe4e65f3cbf46dbdf575b63a04df96acf27874a Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 16 Nov 2025 01:03:28 +0800 Subject: [PATCH 02/13] fetchgit: default argument leaveDotGit to null --- pkgs/build-support/fetchgit/default.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 4d0c2c7af8b1..ef2c2cd43093 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -66,7 +66,8 @@ lib.makeOverridable ( # when rootDir is specified, avoid invalidating the result when rev changes append = if rootDir != "" then "-${lib.strings.sanitizeDerivationName rootDir}" else ""; }, - leaveDotGit ? deepClone || fetchTags, + # When null, will default to: `deepClone || fetchTags` + leaveDotGit ? null, outputHash ? lib.fakeHash, outputHashAlgo ? null, fetchSubmodules ? true, @@ -171,9 +172,12 @@ lib.makeOverridable ( gitConfigFile ; leaveDotGit = - assert fetchTags -> leaveDotGit; - assert rootDir != "" -> !leaveDotGit; - leaveDotGit; + if leaveDotGit != null then + assert fetchTags -> leaveDotGit; + assert rootDir != "" -> !leaveDotGit; + leaveDotGit + else + deepClone || fetchTags; inherit tag; revCustom = rev; rev = getRevWithTag { From d461ad81b21a1253a92dac886d5ee89fc849217d Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 16 Nov 2025 03:53:47 +0800 Subject: [PATCH 03/13] fetchFromGitHub: pass leaveDotGit unconditionally using the null default --- pkgs/build-support/fetchgithub/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index ae5ff338264a..46fed2304871 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -68,7 +68,7 @@ lib.makeOverridable ( varBase = "NIX${lib.optionalString (varPrefix != null) "_${varPrefix}"}_GITHUB_PRIVATE_"; useFetchGit = fetchSubmodules - || (leaveDotGit == true) + || lib.defaultTo false leaveDotGit == true || deepClone || forceFetchGit || fetchLFS @@ -122,6 +122,7 @@ lib.makeOverridable ( rev deepClone fetchSubmodules + leaveDotGit sparseCheckout fetchLFS ; @@ -135,7 +136,6 @@ lib.makeOverridable ( ; }; } - // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } else let revWithTag = finalAttrs.rev; From 59168687f99b8c1eadba9edb814d95200e99e53a Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 03:34:58 +0800 Subject: [PATCH 04/13] fetchFromGitHub: elaborate the fetchSubmodules default choice --- 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 46fed2304871..c02732a90e96 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -13,6 +13,8 @@ lib.makeOverridable ( rev ? null, # TODO(@ShamrockLee): Add back after reconstruction with lib.extendMkDerivation # name ? repoRevToNameMaybe finalAttrs.repo (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) "github", + # `fetchFromGitHub` defaults to use `fetchzip` for better hash stability. + # We default not to fetch submodules, which is contrary to `fetchgit`'s default. fetchSubmodules ? false, leaveDotGit ? null, deepClone ? false, From 6c5dc5d57f446a9c65d01699a9b16963d54d4e06 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 03:39:53 +0800 Subject: [PATCH 05/13] fetchgit: default nonConeMode to null and manage its default internally --- 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 ef2c2cd43093..eac73f713c74 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -74,7 +74,8 @@ lib.makeOverridable ( deepClone ? false, branchName ? null, sparseCheckout ? lib.optional (rootDir != "") rootDir, - nonConeMode ? rootDir != "", + # When null, will default to: `rootDir != ""` + nonConeMode ? null, nativeBuildInputs ? [ ], # Shell code executed before the file has been fetched. This, in # particular, can do things like set NIX_PREFETCH_GIT_CHECKOUT_HOOK to @@ -164,7 +165,6 @@ lib.makeOverridable ( fetchSubmodules deepClone branchName - nonConeMode preFetch postFetch fetchTags @@ -178,6 +178,7 @@ lib.makeOverridable ( leaveDotGit else deepClone || fetchTags; + nonConeMode = lib.defaultTo (rootDir != "") nonConeMode; inherit tag; revCustom = rev; rev = getRevWithTag { From ea5b3c6d5d2de8241377d31292b20c21f53af488 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 4 Dec 2025 15:25:35 +0800 Subject: [PATCH 06/13] fetchgit: nonConeMode: reference depending attributes from finalAttrs --- pkgs/build-support/fetchgit/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index eac73f713c74..64a51e2a8059 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -178,7 +178,7 @@ lib.makeOverridable ( leaveDotGit else deepClone || fetchTags; - nonConeMode = lib.defaultTo (rootDir != "") nonConeMode; + nonConeMode = lib.defaultTo (finalAttrs.rootDir != "") nonConeMode; inherit tag; revCustom = rev; rev = getRevWithTag { From 83b42e34eca9347f410f3b41c71e50d3c2536f81 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 01:26:38 +0800 Subject: [PATCH 07/13] fetchgit: keep sparseCheckout a list and stringify as sparseCheckoutText --- pkgs/build-support/fetchgit/builder.sh | 2 +- pkgs/build-support/fetchgit/default.nix | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh index 8f72881d3b91..704f14598dea 100644 --- a/pkgs/build-support/fetchgit/builder.sh +++ b/pkgs/build-support/fetchgit/builder.sh @@ -19,7 +19,7 @@ $SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" --name "$name" ${deepClone:+--deepClone} \ ${fetchSubmodules:+--fetch-submodules} \ ${fetchTags:+--fetch-tags} \ - ${sparseCheckout:+--sparse-checkout "$sparseCheckout"} \ + ${sparseCheckoutText:+--sparse-checkout "$sparseCheckoutText"} \ ${nonConeMode:+--non-cone-mode} \ ${branchName:+--branch-name "$branchName"} \ ${rootDir:+--root-dir "$rootDir"} diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 64a51e2a8059..7d634f684fa1 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -152,8 +152,9 @@ lib.makeOverridable ( inherit outputHash outputHashAlgo; outputHashMode = "recursive"; - sparseCheckout = - assert nonConeMode -> (sparseCheckout != [ ]); + inherit sparseCheckout; + sparseCheckoutText = + assert finalAttrs.nonConeMode -> (finalAttrs.sparseCheckout != [ ]); # git-sparse-checkout(1) says: # > When the --stdin option is provided, the directories or patterns are read # > from standard in as a newline-delimited list instead of from the arguments. From dd264228ff306e3cce538e4281f834476483393d Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 01:44:17 +0800 Subject: [PATCH 08/13] fetchgit: default sparseCheckout to null and handle the default internally --- 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 7d634f684fa1..76539d213183 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -73,7 +73,8 @@ lib.makeOverridable ( fetchSubmodules ? true, deepClone ? false, branchName ? null, - sparseCheckout ? lib.optional (rootDir != "") rootDir, + # When null, will default to: `lib.optional (rootdir != "") rootdir` + sparseCheckout ? null, # When null, will default to: `rootDir != ""` nonConeMode ? null, nativeBuildInputs ? [ ], @@ -152,7 +153,7 @@ lib.makeOverridable ( inherit outputHash outputHashAlgo; outputHashMode = "recursive"; - inherit sparseCheckout; + sparseCheckout = lib.defaultTo (lib.optional (rootDir != "") rootDir) sparseCheckout; sparseCheckoutText = assert finalAttrs.nonConeMode -> (finalAttrs.sparseCheckout != [ ]); # git-sparse-checkout(1) says: From d1275c4ff19cd51361d9474a306c85bb6b4b251e Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 01:36:04 +0800 Subject: [PATCH 09/13] fetchgit: move sparseCheckout type check down to sparseCheckoutText --- pkgs/build-support/fetchgit/default.nix | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 76539d213183..450103027b6b 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -131,11 +131,6 @@ lib.makeOverridable ( server admins start using the new version? */ - if builtins.isString sparseCheckout then - # Changed to throw on 2023-06-04 - 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; @@ -155,11 +150,15 @@ lib.makeOverridable ( sparseCheckout = lib.defaultTo (lib.optional (rootDir != "") rootDir) sparseCheckout; sparseCheckoutText = + # Changed to throw on 2023-06-04 + assert ( + lib.assertMsg (lib.isList finalAttrs.sparseCheckout) "Please provide directories/patterns for sparse checkout as a list of strings. Passing a (multi-line) string is not supported any more." + ); assert finalAttrs.nonConeMode -> (finalAttrs.sparseCheckout != [ ]); # git-sparse-checkout(1) says: # > When the --stdin option is provided, the directories or patterns are read # > from standard in as a newline-delimited list instead of from the arguments. - builtins.concatStringsSep "\n" sparseCheckout; + builtins.concatStringsSep "\n" finalAttrs.sparseCheckout; inherit url From 8c8557860213f05a58dbbc6b2dba80cef31d96b0 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 01:52:24 +0800 Subject: [PATCH 10/13] fetchgit: format expression after eliminating global assertions --- pkgs/build-support/fetchgit/default.nix | 172 ++++++++++++------------ 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 450103027b6b..3bcda3af1c59 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -131,103 +131,103 @@ lib.makeOverridable ( server admins start using the new version? */ - derivationArgs - // { - inherit name; + derivationArgs + // { + inherit name; - builder = ./builder.sh; - fetcher = ./nix-prefetch-git; + builder = ./builder.sh; + fetcher = ./nix-prefetch-git; - nativeBuildInputs = [ - git - cacert - ] - ++ lib.optionals fetchLFS [ git-lfs ] - ++ nativeBuildInputs; + nativeBuildInputs = [ + git + cacert + ] + ++ lib.optionals fetchLFS [ git-lfs ] + ++ nativeBuildInputs; - inherit outputHash outputHashAlgo; - outputHashMode = "recursive"; + inherit outputHash outputHashAlgo; + outputHashMode = "recursive"; - sparseCheckout = lib.defaultTo (lib.optional (rootDir != "") rootDir) sparseCheckout; - sparseCheckoutText = - # Changed to throw on 2023-06-04 - assert ( - lib.assertMsg (lib.isList finalAttrs.sparseCheckout) "Please provide directories/patterns for sparse checkout as a list of strings. Passing a (multi-line) string is not supported any more." - ); - assert finalAttrs.nonConeMode -> (finalAttrs.sparseCheckout != [ ]); - # git-sparse-checkout(1) says: - # > When the --stdin option is provided, the directories or patterns are read - # > from standard in as a newline-delimited list instead of from the arguments. - builtins.concatStringsSep "\n" finalAttrs.sparseCheckout; + sparseCheckout = lib.defaultTo (lib.optional (rootDir != "") rootDir) sparseCheckout; + sparseCheckoutText = + # Changed to throw on 2023-06-04 + assert ( + lib.assertMsg (lib.isList finalAttrs.sparseCheckout) "Please provide directories/patterns for sparse checkout as a list of strings. Passing a (multi-line) string is not supported any more." + ); + assert finalAttrs.nonConeMode -> (finalAttrs.sparseCheckout != [ ]); + # git-sparse-checkout(1) says: + # > When the --stdin option is provided, the directories or patterns are read + # > from standard in as a newline-delimited list instead of from the arguments. + builtins.concatStringsSep "\n" finalAttrs.sparseCheckout; - inherit - url - fetchLFS - fetchSubmodules - deepClone - branchName - preFetch - postFetch - fetchTags - rootDir - gitConfigFile - ; - leaveDotGit = - if leaveDotGit != null then - assert fetchTags -> leaveDotGit; - assert rootDir != "" -> !leaveDotGit; - leaveDotGit - else - deepClone || fetchTags; - nonConeMode = lib.defaultTo (finalAttrs.rootDir != "") nonConeMode; - inherit tag; - revCustom = rev; - rev = getRevWithTag { - inherit (finalAttrs) tag; - rev = finalAttrs.revCustom; - }; + inherit + url + fetchLFS + fetchSubmodules + deepClone + branchName + preFetch + postFetch + fetchTags + rootDir + gitConfigFile + ; + leaveDotGit = + if leaveDotGit != null then + assert fetchTags -> leaveDotGit; + assert rootDir != "" -> !leaveDotGit; + leaveDotGit + else + deepClone || fetchTags; + nonConeMode = lib.defaultTo (finalAttrs.rootDir != "") nonConeMode; + inherit tag; + revCustom = rev; + rev = getRevWithTag { + inherit (finalAttrs) tag; + rev = finalAttrs.revCustom; + }; - postHook = - if netrcPhase == null then - null - else - '' - ${netrcPhase} - # required that git uses the netrc file - mv {,.}netrc - export NETRC=$PWD/.netrc - export HOME=$PWD - ''; + postHook = + if netrcPhase == null then + null + else + '' + ${netrcPhase} + # required that git uses the netrc file + mv {,.}netrc + export NETRC=$PWD/.netrc + export HOME=$PWD + ''; - impureEnvVars = - lib.fetchers.proxyImpureEnvVars - ++ netrcImpureEnvVars - ++ [ - "GIT_PROXY_COMMAND" - "NIX_GIT_SSL_CAINFO" - "SOCKS_SERVER" + impureEnvVars = + lib.fetchers.proxyImpureEnvVars + ++ netrcImpureEnvVars + ++ [ + "GIT_PROXY_COMMAND" + "NIX_GIT_SSL_CAINFO" + "SOCKS_SERVER" - # This is a parameter intended to be set by setup hooks or preFetch - # scripts that want per-URL control over HTTP proxies used by Git - # (if per-URL control isn't needed, `http_proxy` etc. will - # suffice). It must be a whitespace-separated (with backslash as an - # escape character) list of pairs like this: - # - # http://domain1/path1 proxy1 https://domain2/path2 proxy2 - # - # where the URLs are as documented in the `git-config` manual page - # under `http..*`, and the proxies are as documented on the - # same page under `http.proxy`. - "FETCHGIT_HTTP_PROXIES" - ]; + # This is a parameter intended to be set by setup hooks or preFetch + # scripts that want per-URL control over HTTP proxies used by Git + # (if per-URL control isn't needed, `http_proxy` etc. will + # suffice). It must be a whitespace-separated (with backslash as an + # escape character) list of pairs like this: + # + # http://domain1/path1 proxy1 https://domain2/path2 proxy2 + # + # where the URLs are as documented in the `git-config` manual page + # under `http..*`, and the proxies are as documented on the + # same page under `http.proxy`. + "FETCHGIT_HTTP_PROXIES" + ]; - inherit preferLocalBuild meta allowedRequisites; + inherit preferLocalBuild meta allowedRequisites; - passthru = { - gitRepoUrl = url; - } - // passthru; + passthru = { + gitRepoUrl = url; } + // passthru; + } ); # No ellipsis. From 4c681c7ce093f04f7a12cc948fe16a055dc2ae59 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Nov 2025 03:29:12 +0800 Subject: [PATCH 11/13] fetchFromGitHub: default sparseCheckout to null --- pkgs/build-support/fetchgithub/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index c02732a90e96..1283dcd7d25a 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -22,7 +22,7 @@ lib.makeOverridable ( forceFetchGit ? false, fetchLFS ? false, rootDir ? "", - sparseCheckout ? lib.optional (rootDir != "") rootDir, + sparseCheckout ? null, githubBase ? "github.com", varPrefix ? null, passthru ? { }, @@ -75,7 +75,7 @@ lib.makeOverridable ( || forceFetchGit || fetchLFS || (rootDir != "") - || (sparseCheckout != [ ]); + || lib.defaultTo [ ] sparseCheckout != [ ]; # We prefer fetchzip in cases we don't need submodules as the hash # is more stable in that case. fetcher = From 5c51547b2287da9504b125b804ad4829ac0fa031 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Thu, 4 Dec 2025 15:28:38 +0800 Subject: [PATCH 12/13] fetchgit: sparseCheckout: reference depending attributes from finalAttrs --- pkgs/build-support/fetchgit/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 3bcda3af1c59..6c5abd592e55 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -148,7 +148,7 @@ lib.makeOverridable ( inherit outputHash outputHashAlgo; outputHashMode = "recursive"; - sparseCheckout = lib.defaultTo (lib.optional (rootDir != "") rootDir) sparseCheckout; + sparseCheckout = lib.defaultTo (lib.optional (finalAttrs.rootDir != "") finalAttrs.rootDir) sparseCheckout; sparseCheckoutText = # Changed to throw on 2023-06-04 assert ( From ea1e4d73d84b48c188c1c315411830ea53f48482 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 8 Dec 2025 21:29:11 +0800 Subject: [PATCH 13/13] fetchgit: adjust format for sparseCheckout default Co-authored-by: Matt Sturgeon --- pkgs/build-support/fetchgit/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 6c5abd592e55..7a8f689df439 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -148,7 +148,11 @@ lib.makeOverridable ( inherit outputHash outputHashAlgo; outputHashMode = "recursive"; - sparseCheckout = lib.defaultTo (lib.optional (finalAttrs.rootDir != "") finalAttrs.rootDir) sparseCheckout; + sparseCheckout = + let + default = lib.optional (finalAttrs.rootDir != "") finalAttrs.rootDir; + in + lib.defaultTo default sparseCheckout; sparseCheckoutText = # Changed to throw on 2023-06-04 assert (