about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-05-02T12·36+0200
committerEelco Dolstra <edolstra@gmail.com>2017-05-02T13·46+0200
commit7f6837a0f6e7702a9e8c6da622873b955aa414cd (patch)
tree660f7c6134cc9343139df7eb13f227083b803f6b
parentcd4d2705ec6e641ffa3b11dc1aabad22fc38251a (diff)
Replace $NIX_REMOTE_SYSTEMS with an option "builder-files"
Also, to unify with hydra-queue-runner, allow it to be a list of
files.
-rw-r--r--src/libstore/globals.cc4
-rw-r--r--src/libstore/globals.hh4
-rw-r--r--src/libstore/machines.cc36
-rw-r--r--src/libstore/machines.hh4
4 files changed, 34 insertions, 14 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 953bf6aaaa0a..4bdbde989ab2 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -43,6 +43,10 @@ Settings::Settings()
     lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
     caFile = getEnv("NIX_SSL_CERT_FILE", getEnv("SSL_CERT_FILE", "/etc/ssl/certs/ca-certificates.crt"));
 
+    /* Backwards compatibility. */
+    auto s = getEnv("NIX_REMOTE_SYSTEMS");
+    if (s != "") builderFiles = tokenizeString<Strings>(s, ":");
+
 #if __linux__
     sandboxPaths = tokenizeString<StringSet>("/bin/sh=" BASH_PATH);
 #endif
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index d7a0b86a0889..ac6f6a2cfa36 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -133,6 +133,10 @@ public:
     Setting<std::string> builders{this, "", "builders",
         "A semicolon-separated list of build machines, in the format of nix.machines."};
 
+    Setting<Strings> builderFiles{this,
+        {nixConfDir + "/machines"}, "builder-files",
+        "A list of files specifying build 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 479ed1432fb5..c1d9047537d3 100644
--- a/src/libstore/machines.cc
+++ b/src/libstore/machines.cc
@@ -12,7 +12,8 @@ Machine::Machine(decltype(storeUri) storeUri,
     decltype(maxJobs) maxJobs,
     decltype(speedFactor) speedFactor,
     decltype(supportedFeatures) supportedFeatures,
-    decltype(mandatoryFeatures) mandatoryFeatures) :
+    decltype(mandatoryFeatures) mandatoryFeatures,
+    decltype(sshPublicHostKey) sshPublicHostKey) :
     storeUri(
         // Backwards compatibility: if the URI is a hostname,
         // prepend ssh://.
@@ -24,7 +25,8 @@ Machine::Machine(decltype(storeUri) storeUri,
     maxJobs(maxJobs),
     speedFactor(std::max(1U, speedFactor)),
     supportedFeatures(supportedFeatures),
-    mandatoryFeatures(mandatoryFeatures)
+    mandatoryFeatures(mandatoryFeatures),
+    sshPublicHostKey(sshPublicHostKey)
 {}
 
 bool Machine::allSupported(const std::set<string> & features) const {
@@ -52,13 +54,19 @@ void parseMachines(const std::string & s, Machines & machines)
         auto sz = tokens.size();
         if (sz < 1)
             throw FormatError("bad machine specification ‘%s’", line);
+
+        auto isSet = [&](int n) {
+            return tokens.size() > n && tokens[n] != "" && tokens[n] != "-";
+        };
+
         machines.emplace_back(tokens[0],
-            sz >= 2 ? tokenizeString<std::vector<string>>(tokens[1], ",") : std::vector<string>{settings.thisSystem},
-            sz >= 3 ? tokens[2] : "",
-            sz >= 4 ? std::stoull(tokens[3]) : 1LL,
-            sz >= 5 ? std::stoull(tokens[4]) : 1LL,
-            sz >= 6 ? tokenizeString<std::set<string>>(tokens[5], ",") : std::set<string>{},
-            sz >= 7 ? tokenizeString<std::set<string>>(tokens[6], ",") : std::set<string>{});
+            isSet(1) ? tokenizeString<std::vector<string>>(tokens[1], ",") : std::vector<string>{settings.thisSystem},
+            isSet(2) ? tokens[2] : "",
+            isSet(3) ? std::stoull(tokens[3]) : 1LL,
+            isSet(4) ? std::stoull(tokens[4]) : 1LL,
+            isSet(5) ? tokenizeString<std::set<string>>(tokens[5], ",") : std::set<string>{},
+            isSet(6) ? tokenizeString<std::set<string>>(tokens[6], ",") : std::set<string>{},
+            isSet(7) ? tokens[7] : "");
     }
 }
 
@@ -66,11 +74,13 @@ Machines getMachines()
 {
     Machines machines;
 
-    try {
-        parseMachines(readFile(getEnv("NIX_REMOTE_SYSTEMS", settings.nixConfDir + "/machines")), machines);
-    } catch (const SysError & e) {
-        if (e.errNo != ENOENT)
-            throw;
+    for (auto & file : settings.builderFiles.get()) {
+        try {
+            parseMachines(readFile(file), machines);
+        } catch (const SysError & e) {
+            if (e.errNo != ENOENT)
+                throw;
+        }
     }
 
     parseMachines(settings.builders, machines);
diff --git a/src/libstore/machines.hh b/src/libstore/machines.hh
index e0455742844b..de92eb924e4a 100644
--- a/src/libstore/machines.hh
+++ b/src/libstore/machines.hh
@@ -13,6 +13,7 @@ struct Machine {
     const unsigned int speedFactor;
     const std::set<string> supportedFeatures;
     const std::set<string> mandatoryFeatures;
+    const std::string sshPublicHostKey;
     bool enabled = true;
 
     bool allSupported(const std::set<string> & features) const;
@@ -25,7 +26,8 @@ struct Machine {
         decltype(maxJobs) maxJobs,
         decltype(speedFactor) speedFactor,
         decltype(supportedFeatures) supportedFeatures,
-        decltype(mandatoryFeatures) mandatoryFeatures);
+        decltype(mandatoryFeatures) mandatoryFeatures,
+        decltype(sshPublicHostKey) sshPublicHostKey);
 };
 
 typedef std::vector<Machine> Machines;