about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--perl/lib/Nix/Config.pm.in10
-rw-r--r--src/libstore/build.cc4
-rw-r--r--src/libstore/globals.cc23
-rw-r--r--src/libstore/globals.hh2
-rw-r--r--src/libstore/local-store.cc4
5 files changed, 37 insertions, 6 deletions
diff --git a/perl/lib/Nix/Config.pm.in b/perl/lib/Nix/Config.pm.in
index ed197821e89f..8c902ab6edc5 100644
--- a/perl/lib/Nix/Config.pm.in
+++ b/perl/lib/Nix/Config.pm.in
@@ -19,9 +19,17 @@ $useBindings = "@perlbindings@" eq "yes";
 %config = ();
 
 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";
     return unless -f $config;
-    
+
     open CONFIG, "<$config" or die "cannot open `$config'";
     while (<CONFIG>) {
         /^\s*([\w|-]+)\s*=\s*(.*)$/ or next;
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 887858fce30c..4a2bc5218b69 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -2494,6 +2494,10 @@ void SubstitutionGoal::tryToRun()
             outPipe.readSide.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. */
             Strings args;
             args.push_back(baseNameOf(sub));
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 9636bf49d987..a28e08427da5 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -36,10 +36,12 @@ bool printBuildTrace = false;
 
 static bool settingsRead = false;
 
-static std::map<string, Strings> settings;
+typedef std::map<string, Strings> Settings;
+
+static Settings settings;
 
 /* Overriden settings. */
-std::map<string, Strings> settingsCmdline;
+Settings settingsCmdline;
 
 
 string & at(Strings & ss, unsigned int n)
@@ -82,7 +84,7 @@ static void readSettings()
     };
 
     settings.insert(settingsCmdline.begin(), settingsCmdline.end());
-    
+
     settingsRead = true;
 }
 
@@ -90,7 +92,7 @@ static void readSettings()
 Strings querySetting(const string & name, const Strings & def)
 {
     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;
 }
 
@@ -169,5 +171,16 @@ void setDefaultsFromEnvironment()
     buildTimeout = queryIntSetting("build-timeout", 0);
 }
 
- 
+
+string packSettings()
+{
+    string s;
+    if (!settingsRead) readSettings();
+    foreach (Settings::iterator, i, settings) {
+        s += i->first; s += '='; s += concatStringsSep(" ", i->second); s += '\n';
+    }
+    return s;
+}
+
+
 }
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 1c0877a5e1e9..30acf59ef54f 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -115,5 +115,7 @@ void reloadSettings();
 
 void setDefaultsFromEnvironment();
 
+string packSettings();
+
 
 }
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 023bf417e59a..aaa1abb56921 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -931,6 +931,10 @@ void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter &
                written in Perl (i.e. all of them) fail. */
             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();
             toPipe.writeSide.close();
             if (dup2(toPipe.readSide, STDIN_FILENO) == -1)