mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
Merge pull request #1259 from shlevy/1.11-netrc
Backport netrc-file option to 1.11
This commit is contained in:
commit
d8638ae6b4
5 changed files with 38 additions and 1 deletions
|
@ -457,6 +457,29 @@ flag, e.g. <literal>--option gc-keep-outputs false</literal>.</para>
|
|||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry><term><literal>netrc-file</literal></term>
|
||||
|
||||
<listitem><para>If set to an absolute path to a <filename>netrc</filename>
|
||||
file, Nix will use the HTTP authentication credentials in this file when
|
||||
trying to download from a remote host through HTTP or HTTPS. Defaults to
|
||||
<filename>$NIX_CONF_DIR/netrc</filename>.</para>
|
||||
|
||||
<para>The <filename>netrc</filename> file consists of a list of
|
||||
accounts in the following format:
|
||||
|
||||
<screen>
|
||||
machine <replaceable>my-machine</replaceable>
|
||||
login <replaceable>my-username</replaceable>
|
||||
password <replaceable>my-password</replaceable>
|
||||
</screen>
|
||||
|
||||
For the exact syntax, see <link
|
||||
xlink:href="https://ec.haxx.se/usingcurl-netrc.html">the
|
||||
<literal>curl</literal> documentation.</link></para></listitem>
|
||||
|
||||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry><term><literal>system</literal></term>
|
||||
|
||||
<listitem><para>This option specifies the canonical Nix system
|
||||
|
|
|
@ -62,6 +62,8 @@ my $curlConnectTimeout = int(
|
|||
$Nix::Config::config{"connect-timeout"} //
|
||||
$ENV{"NIX_CONNECT_TIMEOUT"} // 0);
|
||||
|
||||
my $netrcFile = $Nix::Config::config{"netrc-file"} //
|
||||
"$Nix::Config::confDir/netrc";
|
||||
|
||||
sub addRequest {
|
||||
my ($storePath, $url, $head) = @_;
|
||||
|
@ -88,6 +90,8 @@ sub addRequest {
|
|||
$curl->setopt(CURLOPT_FAILONERROR, 1);
|
||||
$curl->setopt(CURLOPT_CONNECTTIMEOUT, $curlConnectTimeout);
|
||||
$curl->setopt(CURLOPT_TIMEOUT, 20 * 60);
|
||||
$curl->setopt(CURLOPT_NETRC_FILE, $netrcFile);
|
||||
$curl->setopt(CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
|
||||
|
||||
if ($activeRequests >= $maxParallelRequests) {
|
||||
$scheduled{$curlId} = 1;
|
||||
|
@ -563,7 +567,7 @@ sub downloadBinary {
|
|||
die if $requireSignedBinaryCaches && !defined $info->{signedBy};
|
||||
print STDERR "\n*** Downloading ‘$url’ ", ($requireSignedBinaryCaches ? "(signed by ‘$info->{signedBy}’) " : ""), "to ‘$storePath’...\n";
|
||||
checkURL $url;
|
||||
if (system("$Nix::Config::curl --fail --location --connect-timeout $curlConnectTimeout -A '$userAgent' $Nix::Config::curlCaFlag '$url' $decompressor | $Nix::Config::binDir/nix-store --restore $destPath") != 0) {
|
||||
if (system("$Nix::Config::curl --fail --location --netrc-file $netrcFile --netrc-optional --connect-timeout $curlConnectTimeout -A '$userAgent' $Nix::Config::curlCaFlag '$url' $decompressor | $Nix::Config::binDir/nix-store --restore $destPath") != 0) {
|
||||
warn "download of ‘$url’ failed" . ($! ? ": $!" : "") . "\n";
|
||||
next;
|
||||
}
|
||||
|
|
|
@ -114,6 +114,10 @@ struct Curl
|
|||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback_);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *) &curl);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||
/* If no file exist in the specified path, curl continues to work
|
||||
* anyway as if netrc support was disabled. */
|
||||
curl_easy_setopt(curl, CURLOPT_NETRC_FILE, settings.netrcFile.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
|
||||
}
|
||||
|
||||
~Curl()
|
||||
|
|
|
@ -62,6 +62,7 @@ Settings::Settings()
|
|||
lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
|
||||
showTrace = false;
|
||||
enableImportNative = false;
|
||||
netrcFile = (format("%1%/%2%") % nixConfDir % "netrc").str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -190,6 +191,7 @@ void Settings::update()
|
|||
_get(preBuildHook, "pre-build-hook");
|
||||
_get(keepGoing, "keep-going");
|
||||
_get(keepFailed, "keep-failed");
|
||||
_get(netrcFile, "netrc-file");
|
||||
|
||||
string subs = getEnv("NIX_SUBSTITUTERS", "default");
|
||||
if (subs == "default") {
|
||||
|
|
|
@ -210,6 +210,10 @@ struct Settings {
|
|||
build settings */
|
||||
Path preBuildHook;
|
||||
|
||||
/* Path to the netrc file used to obtain usernames/passwords for
|
||||
downloads. */
|
||||
Path netrcFile;
|
||||
|
||||
private:
|
||||
SettingsMap settings, overrides;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue