download-from-binary-cache: add nix.conf options

This commit is contained in:
Eelco Dolstra 2012-07-09 10:57:28 -04:00
parent 98a423b75a
commit 099125435f
3 changed files with 30 additions and 6 deletions

View file

@ -288,6 +288,26 @@ build-use-chroot = /dev /proc /bin</programlisting>
</varlistentry>
<varlistentry><term><literal>binary-caches</literal></term>
<listitem><para>A list of URLs of binary caches, separated by
whitespace. It can be overriden through the environment variable
<envar>NIX_BINARY_CACHES</envar>. The default is
<literal>http://nixos.org/binary-cache</literal>.</para></listitem>
</varlistentry>
<varlistentry><term><literal>binary-caches-parallel-connections</literal></term>
<listitem><para>The maximum number of parallel HTTP connections
used by the binary cache substituter to get NAR info files. This
number should be high to minimise latency. It defaults to
150.</para></listitem>
</varlistentry>
<varlistentry><term><literal>system</literal></term>
<listitem><para>This option specifies the canonical Nix system

View file

@ -14,16 +14,16 @@ $curl = "@curl@";
$useBindings = "@perlbindings@" eq "yes";
%config = ();
sub readConfig {
my %config;
my $config = "@sysconfdir@/nix/nix.conf";
my $config = "$confDir/nix.conf";
return unless -f $config;
open CONFIG, "<$config" or die "cannot open `$config'";
while (<CONFIG>) {
/^\s*([\w|-]+)\s*=\s*(.*)$/ or next;
$config{$1} = $2;
print "|$1| -> |$2|\n";
}
close CONFIG;
}

View file

@ -10,9 +10,13 @@ use WWW::Curl::Multi;
use strict;
my @binaryCacheUrls = map { s/\/+$//; $_ } split(/ /, ($ENV{"NIX_BINARY_CACHES"} || ""));
Nix::Config::readConfig;
my $maxParallelRequests = 150;
my @binaryCacheUrls = map { s/\/+$//; $_ } split(/ /,
($ENV{"NIX_BINARY_CACHES"} // $Nix::Config::config{"binary-caches"} // "http://nixos.org/binary-cache"));
my $maxParallelRequests = int($Nix::Config::config{"binary-caches-parallel-connections"} // 150);
$maxParallelRequests = 1 if $maxParallelRequests < 1;
my ($dbh, $insertNAR, $queryNAR, $insertNegativeNAR, $queryNegativeNAR);
my %cacheIds;
@ -22,7 +26,7 @@ my $activeRequests = 0;
my $curlIdCount = 1;
my %requests;
my %scheduled;
my $caBundle = $ENV{"CURL_CA_BUNDLE"} || $ENV{"OPENSSL_X509_CERT_FILE"};
my $caBundle = $ENV{"CURL_CA_BUNDLE"} // $ENV{"OPENSSL_X509_CERT_FILE"};
sub addRequest {