diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh index 8f72881d3b911..704f14598deae 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 5a8ea3cf04880..7a8f689df4398 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -66,14 +66,17 @@ 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, deepClone ? false, branchName ? null, - sparseCheckout ? lib.optional (rootDir != "") rootDir, - nonConeMode ? rootDir != "", + # When null, will default to: `lib.optional (rootdir != "") rootdir` + sparseCheckout ? null, + # 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 @@ -128,99 +131,107 @@ 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 - "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; - fetcher = ./nix-prefetch-git; - - nativeBuildInputs = [ - git - cacert - ] - ++ lib.optionals fetchLFS [ git-lfs ] - ++ nativeBuildInputs; - - inherit outputHash outputHashAlgo; - outputHashMode = "recursive"; - + derivationArgs + // { + inherit name; + + builder = ./builder.sh; + fetcher = ./nix-prefetch-git; + + nativeBuildInputs = [ + git + cacert + ] + ++ lib.optionals fetchLFS [ git-lfs ] + ++ nativeBuildInputs; + + inherit outputHash outputHashAlgo; + outputHashMode = "recursive"; + + sparseCheckout = + let + default = lib.optional (finalAttrs.rootDir != "") finalAttrs.rootDir; + in + lib.defaultTo default 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. - sparseCheckout = builtins.concatStringsSep "\n" sparseCheckout; - - inherit - url + 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 - fetchLFS - fetchSubmodules - deepClone - branchName - nonConeMode - preFetch - postFetch - fetchTags - rootDir - gitConfigFile - ; - 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 - ''; - - 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" - ]; - - inherit preferLocalBuild meta allowedRequisites; - - passthru = { - gitRepoUrl = url; - } - // passthru; + 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 + ''; + + 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" + ]; + + inherit preferLocalBuild meta allowedRequisites; + + passthru = { + gitRepoUrl = url; } + // passthru; + } ); # No ellipsis. diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index ae5ff338264a2..1283dcd7d25ad 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, @@ -20,7 +22,7 @@ lib.makeOverridable ( forceFetchGit ? false, fetchLFS ? false, rootDir ? "", - sparseCheckout ? lib.optional (rootDir != "") rootDir, + sparseCheckout ? null, githubBase ? "github.com", varPrefix ? null, passthru ? { }, @@ -68,12 +70,12 @@ lib.makeOverridable ( varBase = "NIX${lib.optionalString (varPrefix != null) "_${varPrefix}"}_GITHUB_PRIVATE_"; useFetchGit = fetchSubmodules - || (leaveDotGit == true) + || lib.defaultTo false leaveDotGit == true || deepClone || 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 = @@ -122,6 +124,7 @@ lib.makeOverridable ( rev deepClone fetchSubmodules + leaveDotGit sparseCheckout fetchLFS ; @@ -135,7 +138,6 @@ lib.makeOverridable ( ; }; } - // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } else let revWithTag = finalAttrs.rev;