diff --git a/doc/manual/conf-file.xml b/doc/manual/conf-file.xml index 25a009de9..e2890b103 100644 --- a/doc/manual/conf-file.xml +++ b/doc/manual/conf-file.xml @@ -288,6 +288,26 @@ build-use-chroot = /dev /proc /bin + binary-caches + + A list of URLs of binary caches, separated by + whitespace. It can be overriden through the environment variable + NIX_BINARY_CACHES. The default is + http://nixos.org/binary-cache. + + + + + binary-caches-parallel-connections + + 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. + + + + system This option specifies the canonical Nix system diff --git a/perl/lib/Nix/Config.pm.in b/perl/lib/Nix/Config.pm.in index 64aaccd7c..57751b6b4 100644 --- a/perl/lib/Nix/Config.pm.in +++ b/perl/lib/Nix/Config.pm.in @@ -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 () { /^\s*([\w|-]+)\s*=\s*(.*)$/ or next; $config{$1} = $2; - print "|$1| -> |$2|\n"; } close CONFIG; } diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in index 37f8db0a9..f062d17e6 100644 --- a/scripts/download-from-binary-cache.pl.in +++ b/scripts/download-from-binary-cache.pl.in @@ -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 {