Skip to content

Commit 6f53c06

Browse files
fetchgit: add support for netrc file through impure NIX_GIT_SSL_CAINFO env
1 parent e3b5143 commit 6f53c06

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

pkgs/build-support/fetchgit/default.nix

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ in
2121
postFetch ? ""
2222
, preferLocalBuild ? true
2323
, fetchLFS ? false
24+
, # Shell code to build a netrc file for BASIC auth
25+
netrcPhase ? null
26+
, # Impure env vars (https://nixos.org/nix/manual/#sec-advanced-attributes)
27+
# needed for netrcPhase
28+
netrcImpureEnvVars ? []
2429
}:
2530

2631
/* NOTE:
@@ -64,10 +69,17 @@ stdenvNoCC.mkDerivation {
6469

6570
inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName postFetch;
6671

72+
postHook = if netrcPhase == null then null else ''
73+
${netrcPhase}
74+
# required that git uses the netrc file
75+
mv {,.}netrc
76+
export HOME=$PWD
77+
'';
78+
6779
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
6880

69-
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
70-
"GIT_PROXY_COMMAND" "SOCKS_SERVER"
81+
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ netrcImpureEnvVars ++ [
82+
"GIT_PROXY_COMMAND" "NIX_GIT_SSL_CAINFO" "SOCKS_SERVER"
7183
];
7284

7385
inherit preferLocalBuild;

pkgs/build-support/fetchgit/nix-prefetch-git

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
1717
out=${out:-}
1818
http_proxy=${http_proxy:-}
1919

20+
# allow overwritting cacert's ca-bundle.crt with a custom one
21+
# this can be done by setting NIX_GIT_SSL_CAINFO and NIX_SSL_CERT_FILE enviroment variables for the nix-daemon
22+
GIT_SSL_CAINFO=${NIX_GIT_SSL_CAINFO:-$GIT_SSL_CAINFO}
23+
2024
# populated by clone_user_rev()
2125
fullRev=
2226
humanReadableRev=

0 commit comments

Comments
 (0)