Skip to content

Commit

Permalink
nix-prefetch-git: respect NETRC
Browse files Browse the repository at this point in the history
This script needs to support being run both as part of a `fetchgit`
derivation and as a standalone, command-line tool.

The use of `$NIX_BUILD_TOP` only works when used in `fetchgit` but not when
invoked as a standalone tool. Instead we try to respect `$NETRC` so that
the command-line invocation behaves more like standard tools and the
`fetchgit` derivation can explicitly set `$NETRC` when `netrcPhase` is used
to avoid all ambiguity.
  • Loading branch information
Elliot Cameron authored and bjornfor committed Nov 11, 2023
1 parent 99298c3 commit 3a99d1b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkgs/build-support/fetchgit/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ stdenvNoCC.mkDerivation {
${netrcPhase}
# required that git uses the netrc file
mv {,.}netrc
export NETRC=$PWD/.netrc
export HOME=$PWD
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchgit/nix-prefetch-git
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ fi

tmpHomePath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-git-tmp-home-XXXXXXXXXX")"
exit_handlers+=(remove_tmpHomePath)
ln -s "${NETRC:-$HOME/.netrc}" "$tmpHomePath/.netrc"
HOME="$tmpHomePath"
ln -s "$NIX_BUILD_TOP/.netrc" "$HOME/"
unset XDG_CONFIG_HOME
export GIT_CONFIG_NOSYSTEM=1

Expand Down

0 comments on commit 3a99d1b

Please sign in to comment.