tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
fetchFromGitHub: Allow private repos, hosted githubs
Shea Levy
8 years ago
b71b7ee6
06767b81
+34
-5
2 changed files
expand all
collapse all
unified
split
pkgs
build-support
fetchurl
default.nix
top-level
all-packages.nix
+15
-1
pkgs/build-support/fetchurl/default.nix
···
59
59
60
60
, recursiveHash ? false
61
61
62
62
+
, # Shell code to build a netrc file for BASIC auth
63
63
+
netrcPhase ? null
64
64
+
65
65
+
, # Impure env vars (http://nixos.org/nix/manual/#sec-advanced-attributes)
66
66
+
# needed for netrcPhase
67
67
+
netrcImpureEnvVars ? []
68
68
+
62
69
, # Shell code executed after the file has been fetched
63
70
# successfully. This can do things like check or transform the file.
64
71
postFetch ? ""
···
118
125
119
126
outputHashMode = if (recursiveHash || executable) then "recursive" else "flat";
120
127
121
121
-
inherit curlOpts showURLs mirrorsFile impureEnvVars postFetch downloadToTemp executable;
128
128
+
inherit curlOpts showURLs mirrorsFile postFetch downloadToTemp executable;
129
129
+
130
130
+
impureEnvVars = impureEnvVars ++ netrcImpureEnvVars;
122
131
123
132
# Doing the download on a remote machine just duplicates network
124
133
# traffic, so don't do that.
125
134
preferLocalBuild = true;
135
135
+
136
136
+
postHook = if netrcPhase == null then null else ''
137
137
+
${netrcPhase}
138
138
+
curlOpts="$curlOpts --netrc-file $PWD/netrc"
139
139
+
'';
126
140
127
141
inherit meta;
128
142
}
+19
-4
pkgs/top-level/all-packages.nix
···
185
185
186
186
fetchFromGitHub = {
187
187
owner, repo, rev, name ? "${repo}-${rev}-src",
188
188
-
fetchSubmodules ? false,
188
188
+
fetchSubmodules ? false, private ? false,
189
189
+
githubBase ? "github.com", varPrefix ? null,
189
190
... # For hash agility
190
190
-
}@args:
191
191
+
}@args: assert private -> !fetchSubmodules;
191
192
let
192
192
-
baseUrl = "https://github.com/${owner}/${repo}";
193
193
-
passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" ];
193
193
+
baseUrl = "https://${githubBase}/${owner}/${repo}";
194
194
+
passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ];
195
195
+
varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_";
194
196
in if fetchSubmodules then
195
197
fetchgit ({
196
198
inherit name rev fetchSubmodules;
···
203
205
inherit name;
204
206
url = "${baseUrl}/archive/${rev}.tar.gz";
205
207
meta.homepage = "${baseUrl}/";
208
208
+
} // lib.optionalAttrs private {
209
209
+
netrcPhase = ''
210
210
+
if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then
211
211
+
echo "Error: Private fetchFromGitHub requires the nix building process (nix-daemon in multi user mode) to have the ${varBase}USERNAME and ${varBase}PASSWORD env vars set." >&2
212
212
+
exit 1
213
213
+
fi
214
214
+
cat > netrc <<EOF
215
215
+
machine ${githubBase}
216
216
+
login ''$${varBase}USERNAME
217
217
+
password ''$${varBase}PASSWORD
218
218
+
EOF
219
219
+
'';
220
220
+
netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ];
206
221
} // passthruAttrs) // { inherit rev; };
207
222
208
223
fetchFromBitbucket = {