about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-02T11·44+0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-02T13·42+0200
commit1a68710d4dff609bbaf61db3e17a2573f0aadf17 (patch)
tree433ebeb119f209dd69870a9d9b80c0de99de2846 /src
parentebc9f36a8111ddecc8e265e8a6a70048218f244d (diff)
Add an option for specifying remote builders
This is useful for one-off situations where you want to specify a
builder on the command line instead of having to mess with
nix.machines. E.g.

  $ nix-build -A hello --argstr system x86_64-darwin \
    --option builders 'root@macstadium1 x86_64-darwin'

will perform the specified build on "macstadium1".

It also removes the need for a separate nix.machines file since you
can specify builders in nix.conf directly. (In fact nix.machines is
yet another hack that predates the general nix.conf configuration
file, IIRC.)

Note: this option is supported by the daemon for trusted users. The
fact that this allows trusted users to specify paths to SSH keys to
which they don't normally have access is maybe a bit too much trust...
Diffstat (limited to 'src')
-rw-r--r--src/build-remote/build-remote.cc11
-rw-r--r--src/build-remote/local.mk2
-rw-r--r--src/libstore/build.cc3
-rw-r--r--src/libstore/globals.hh3
-rw-r--r--src/libstore/machines.cc18
-rw-r--r--src/libstore/machines.hh2
6 files changed, 27 insertions, 12 deletions
diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc
index 8a9d4571fe..5cd3c518b7 100644
--- a/src/build-remote/build-remote.cc
+++ b/src/build-remote/build-remote.cc
@@ -45,7 +45,7 @@ int main (int argc, char * * argv)
         unsetenv("DISPLAY");
         unsetenv("SSH_ASKPASS");
 
-        if (argc != 5)
+        if (argc != 6)
             throw UsageError("called without required arguments");
 
         auto store = openStore();
@@ -54,6 +54,7 @@ int main (int argc, char * * argv)
         settings.maxSilentTime = std::stoll(argv[2]);
         settings.buildTimeout = std::stoll(argv[3]);
         verbosity = (Verbosity) std::stoll(argv[4]);
+        settings.builders = argv[5];
 
         /* It would be more appropriate to use $XDG_RUNTIME_DIR, since
            that gets cleared on reboot, but it wouldn't work on OS X. */
@@ -62,13 +63,7 @@ int main (int argc, char * * argv)
         std::shared_ptr<Store> sshStore;
         AutoCloseFD bestSlotLock;
 
-        Machines machines;
-        try {
-            parseMachines(readFile(getEnv("NIX_REMOTE_SYSTEMS", SYSCONFDIR "/nix/machines")), machines);
-        } catch (const SysError & e) {
-            if (e.errNo != ENOENT)
-                throw;
-        }
+        auto machines = getMachines();
         debug("got %d remote builders", machines.size());
 
         if (machines.empty()) {
diff --git a/src/build-remote/local.mk b/src/build-remote/local.mk
index 62d5a010c2..64368a43ff 100644
--- a/src/build-remote/local.mk
+++ b/src/build-remote/local.mk
@@ -7,5 +7,3 @@ build-remote_INSTALL_DIR := $(libexecdir)/nix
 build-remote_LIBS = libmain libutil libformat libstore
 
 build-remote_SOURCES := $(d)/build-remote.cc
-
-build-remote_CXXFLAGS = -DSYSCONFDIR="\"$(sysconfdir)\""
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index e756d3377c..8c2602a701 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -614,7 +614,8 @@ HookInstance::HookInstance()
             settings.thisSystem,
             std::to_string(settings.maxSilentTime),
             std::to_string(settings.buildTimeout),
-            std::to_string(verbosity)
+            std::to_string(verbosity),
+            settings.builders
         };
 
         execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data());
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 25cc3e068e..d7a0b86a08 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -130,6 +130,9 @@ public:
     PathSetting buildHook{this, true, nixLibexecDir + "/nix/build-remote", "build-hook",
         "The path of the helper program that executes builds to remote machines."};
 
+    Setting<std::string> builders{this, "", "builders",
+        "A semicolon-separated list of build machines, in the format of nix.machines."};
+
     Setting<off_t> reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space",
         "Amount of reserved disk space for the garbage collector."};
 
diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc
index 471ce8efb9..479ed1432f 100644
--- a/src/libstore/machines.cc
+++ b/src/libstore/machines.cc
@@ -44,7 +44,7 @@ bool Machine::mandatoryMet(const std::set<string> & features) const {
 
 void parseMachines(const std::string & s, Machines & machines)
 {
-    for (auto line : tokenizeString<std::vector<string>>(s, "\n")) {
+    for (auto line : tokenizeString<std::vector<string>>(s, "\n;")) {
         chomp(line);
         line.erase(std::find(line.begin(), line.end(), '#'), line.end());
         if (line.empty()) continue;
@@ -62,4 +62,20 @@ void parseMachines(const std::string & s, Machines & machines)
     }
 }
 
+Machines getMachines()
+{
+    Machines machines;
+
+    try {
+        parseMachines(readFile(getEnv("NIX_REMOTE_SYSTEMS", settings.nixConfDir + "/machines")), machines);
+    } catch (const SysError & e) {
+        if (e.errNo != ENOENT)
+            throw;
+    }
+
+    parseMachines(settings.builders, machines);
+
+    return machines;
+}
+
 }
diff --git a/src/libstore/machines.hh b/src/libstore/machines.hh
index 96c4bd81a4..e045574284 100644
--- a/src/libstore/machines.hh
+++ b/src/libstore/machines.hh
@@ -32,4 +32,6 @@ typedef std::vector<Machine> Machines;
 
 void parseMachines(const std::string & s, Machines & machines);
 
+Machines getMachines();
+
 }