Pass configuration settings to the substituters

Previously substituters could read nix.conf themselves, but this
didn't take --option flags into account.
This commit is contained in:
Eelco Dolstra 2012-07-30 16:09:54 -04:00
parent f9613da180
commit d059bf48e4
5 changed files with 37 additions and 6 deletions

View file

@ -19,6 +19,14 @@ $useBindings = "@perlbindings@" eq "yes";
%config = (); %config = ();
sub readConfig { sub readConfig {
if (defined $ENV{'_NIX_OPTIONS'}) {
foreach my $s (split '\n', $ENV{'_NIX_OPTIONS'}) {
my ($n, $v) = split '=', $s, 2;
$config{$n} = $v;
}
return;
}
my $config = "$confDir/nix.conf"; my $config = "$confDir/nix.conf";
return unless -f $config; return unless -f $config;

View file

@ -2494,6 +2494,10 @@ void SubstitutionGoal::tryToRun()
outPipe.readSide.close(); outPipe.readSide.close();
outPipe.writeSide.close(); outPipe.writeSide.close();
/* Pass configuration options (including those overriden
with --option) to the substituter. */
setenv("_NIX_OPTIONS", packSettings().c_str(), 1);
/* Fill in the arguments. */ /* Fill in the arguments. */
Strings args; Strings args;
args.push_back(baseNameOf(sub)); args.push_back(baseNameOf(sub));

View file

@ -36,10 +36,12 @@ bool printBuildTrace = false;
static bool settingsRead = false; static bool settingsRead = false;
static std::map<string, Strings> settings; typedef std::map<string, Strings> Settings;
static Settings settings;
/* Overriden settings. */ /* Overriden settings. */
std::map<string, Strings> settingsCmdline; Settings settingsCmdline;
string & at(Strings & ss, unsigned int n) string & at(Strings & ss, unsigned int n)
@ -90,7 +92,7 @@ static void readSettings()
Strings querySetting(const string & name, const Strings & def) Strings querySetting(const string & name, const Strings & def)
{ {
if (!settingsRead) readSettings(); if (!settingsRead) readSettings();
std::map<string, Strings>::iterator i = settings.find(name); Settings::iterator i = settings.find(name);
return i == settings.end() ? def : i->second; return i == settings.end() ? def : i->second;
} }
@ -170,4 +172,15 @@ void setDefaultsFromEnvironment()
} }
string packSettings()
{
string s;
if (!settingsRead) readSettings();
foreach (Settings::iterator, i, settings) {
s += i->first; s += '='; s += concatStringsSep(" ", i->second); s += '\n';
}
return s;
}
} }

View file

@ -115,5 +115,7 @@ void reloadSettings();
void setDefaultsFromEnvironment(); void setDefaultsFromEnvironment();
string packSettings();
} }

View file

@ -931,6 +931,10 @@ void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter &
written in Perl (i.e. all of them) fail. */ written in Perl (i.e. all of them) fail. */
unsetenv("DYLD_LIBRARY_PATH"); unsetenv("DYLD_LIBRARY_PATH");
/* Pass configuration options (including those overriden
with --option) to the substituter. */
setenv("_NIX_OPTIONS", packSettings().c_str(), 1);
fromPipe.readSide.close(); fromPipe.readSide.close();
toPipe.writeSide.close(); toPipe.writeSide.close();
if (dup2(toPipe.readSide, STDIN_FILENO) == -1) if (dup2(toPipe.readSide, STDIN_FILENO) == -1)