about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2018-02-13T16·33+0100
committerGitHub <noreply@github.com>2018-02-13T16·33+0100
commit52c777a79318c85c8fbd8c02174a03511de278db (patch)
tree7fd76a9e21c127346ff664c9618f4f62273230af /src
parent7253113fd240baea7bafe30fdb2734098ce35fc4 (diff)
parent6eb1040e909ab83fbc03983724d9c6ec223c4495 (diff)
Merge pull request #1863 from shlevy/conf-includes
Allow includes from nix.conf
Diffstat (limited to 'src')
-rw-r--r--src/libutil/config.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc
index d46ca65a3863..0e502769edf8 100644
--- a/src/libutil/config.cc
+++ b/src/libutil/config.cc
@@ -80,7 +80,31 @@ void Config::applyConfigFile(const Path & path, bool fatal)
             vector<string> tokens = tokenizeString<vector<string> >(line);
             if (tokens.empty()) continue;
 
-            if (tokens.size() < 2 || tokens[1] != "=")
+            if (tokens.size() < 2)
+                throw UsageError("illegal configuration line '%1%' in '%2%'", line, path);
+
+            auto include = false;
+            auto ignoreMissing = false;
+            if (tokens[0] == "include")
+                include = true;
+            else if (tokens[0] == "!include") {
+                include = true;
+                ignoreMissing = true;
+            }
+
+            if (include) {
+                if (tokens.size() != 2)
+                    throw UsageError("illegal configuration line '%1%' in '%2%'", line, path);
+                auto p = absPath(tokens[1], dirOf(path));
+                if (pathExists(p)) {
+                    applyConfigFile(p, fatal);
+                } else if (!ignoreMissing) {
+                    throw Error("file '%1%' included from '%2%' not found", p, path);
+                }
+                continue;
+            }
+
+            if (tokens[1] != "=")
                 throw UsageError("illegal configuration line '%1%' in '%2%'", line, path);
 
             string name = tokens[0];