2011-10-10 23:11:08 +02:00
|
|
|
|
package Nix::Config;
|
|
|
|
|
|
2015-02-04 16:43:32 +01:00
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
2013-11-25 17:38:33 +01:00
|
|
|
|
$version = "@PACKAGE_VERSION@";
|
2012-07-12 00:05:30 +02:00
|
|
|
|
|
2011-10-10 23:11:08 +02:00
|
|
|
|
$binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
|
|
|
$libexecDir = $ENV{"NIX_LIBEXEC_DIR"} || "@libexecdir@";
|
2012-01-03 02:51:38 +01:00
|
|
|
|
$stateDir = $ENV{"NIX_STATE_DIR"} || "@localstatedir@/nix";
|
2011-10-10 23:11:08 +02:00
|
|
|
|
$logDir = $ENV{"NIX_LOG_DIR"} || "@localstatedir@/log/nix";
|
2011-11-23 13:21:35 +01:00
|
|
|
|
$confDir = $ENV{"NIX_CONF_DIR"} || "@sysconfdir@/nix";
|
2012-06-30 00:28:52 +02:00
|
|
|
|
$storeDir = $ENV{"NIX_STORE_DIR"} || "@storedir@";
|
2011-10-10 23:11:08 +02:00
|
|
|
|
|
2012-06-29 20:26:31 +02:00
|
|
|
|
$bzip2 = "@bzip2@";
|
|
|
|
|
$xz = "@xz@";
|
2011-10-10 23:11:08 +02:00
|
|
|
|
$curl = "@curl@";
|
2006-05-31 11:24:54 +02:00
|
|
|
|
|
2012-05-11 01:03:23 +02:00
|
|
|
|
$useBindings = "@perlbindings@" eq "yes";
|
|
|
|
|
|
2012-07-09 16:57:28 +02:00
|
|
|
|
%config = ();
|
|
|
|
|
|
2015-02-04 16:43:32 +01:00
|
|
|
|
%binaryCachePublicKeys = ();
|
|
|
|
|
|
2015-06-01 17:14:03 +02:00
|
|
|
|
$defaultPublicKeys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
|
|
|
|
|
|
2006-05-31 11:24:54 +02:00
|
|
|
|
sub readConfig {
|
2012-07-30 22:09:54 +02:00
|
|
|
|
if (defined $ENV{'_NIX_OPTIONS'}) {
|
|
|
|
|
foreach my $s (split '\n', $ENV{'_NIX_OPTIONS'}) {
|
|
|
|
|
my ($n, $v) = split '=', $s, 2;
|
|
|
|
|
$config{$n} = $v;
|
|
|
|
|
}
|
2015-02-04 16:43:32 +01:00
|
|
|
|
} else {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
close CONFIG;
|
2012-07-30 22:09:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 17:14:03 +02:00
|
|
|
|
foreach my $s (split(/ /, $config{"binary-cache-public-keys"} // $defaultPublicKeys)) {
|
2015-02-04 16:43:32 +01:00
|
|
|
|
my ($keyName, $publicKey) = split ":", $s;
|
|
|
|
|
next unless defined $keyName && defined $publicKey;
|
|
|
|
|
$binaryCachePublicKeys{$keyName} = decode_base64($publicKey);
|
2006-05-31 11:24:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|