Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgit/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
193 changes: 102 additions & 91 deletions pkgs/build-support/fetchgit/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.<url>.*`, 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.<url>.*`, 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.
Expand Down
10 changes: 6 additions & 4 deletions pkgs/build-support/fetchgithub/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ 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,
private ? false,
forceFetchGit ? false,
fetchLFS ? false,
rootDir ? "",
sparseCheckout ? lib.optional (rootDir != "") rootDir,
sparseCheckout ? null,
githubBase ? "github.com",
varPrefix ? null,
passthru ? { },
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -122,6 +124,7 @@ lib.makeOverridable (
rev
deepClone
fetchSubmodules
leaveDotGit
sparseCheckout
fetchLFS
;
Expand All @@ -135,7 +138,6 @@ lib.makeOverridable (
;
};
}
// lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
else
let
revWithTag = finalAttrs.rev;
Expand Down
Loading