2003-06-16 16:33:38 +03:00
|
|
|
|
#include "globals.hh"
|
2006-09-05 00:06:23 +03:00
|
|
|
|
#include "util.hh"
|
2014-07-16 17:02:05 +03:00
|
|
|
|
#include "archive.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
|
|
2005-09-22 18:43:22 +03:00
|
|
|
|
#include <algorithm>
|
2017-02-27 17:01:54 +02:00
|
|
|
|
#include <map>
|
|
|
|
|
#include <thread>
|
2005-02-02 00:07:48 +02:00
|
|
|
|
|
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
2013-03-08 02:24:59 +02:00
|
|
|
|
/* The default location of the daemon socket, relative to nixStateDir.
|
|
|
|
|
The socket is in a directory to allow you to control access to the
|
|
|
|
|
Nix daemon by setting the mode/ownership of the directory
|
|
|
|
|
appropriately. (This wouldn't work on the socket itself since it
|
|
|
|
|
must be deleted and recreated on startup.) */
|
|
|
|
|
#define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
|
|
|
|
|
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
/* chroot-like behavior from Apple's sandbox */
|
|
|
|
|
#if __APPLE__
|
|
|
|
|
#define DEFAULT_ALLOWED_IMPURE_PREFIXES "/System/Library /usr/lib /dev /bin/sh"
|
|
|
|
|
#else
|
|
|
|
|
#define DEFAULT_ALLOWED_IMPURE_PREFIXES ""
|
|
|
|
|
#endif
|
2013-03-08 02:24:59 +02:00
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
Settings settings;
|
2003-07-31 16:47:13 +03:00
|
|
|
|
|
2005-02-02 00:07:48 +02:00
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
Settings::Settings()
|
|
|
|
|
{
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
deprecatedOptions = StringSet({
|
|
|
|
|
"build-use-chroot", "build-chroot-dirs", "build-extra-chroot-dirs",
|
|
|
|
|
"this-option-never-existed-but-who-will-know"
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-16 15:46:36 +02:00
|
|
|
|
nixPrefix = NIX_PREFIX;
|
|
|
|
|
nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
|
|
|
|
|
nixDataDir = canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR));
|
|
|
|
|
nixLogDir = canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR));
|
|
|
|
|
nixStateDir = canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR));
|
|
|
|
|
nixConfDir = canonPath(getEnv("NIX_CONF_DIR", NIX_CONF_DIR));
|
|
|
|
|
nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR));
|
|
|
|
|
nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
|
|
|
|
|
nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
|
|
|
|
|
|
|
|
|
|
// should be set with the other config options, but depends on nixLibexecDir
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
preBuildHook = nixLibexecDir + "/nix/resolve-system-dependencies";
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
keepFailed = false;
|
|
|
|
|
keepGoing = false;
|
|
|
|
|
tryFallback = false;
|
|
|
|
|
maxBuildJobs = 1;
|
2017-02-27 17:01:54 +02:00
|
|
|
|
buildCores = std::max(1U, std::thread::hardware_concurrency());
|
2012-07-31 02:55:41 +03:00
|
|
|
|
readOnlyMode = false;
|
|
|
|
|
thisSystem = SYSTEM;
|
|
|
|
|
maxSilentTime = 0;
|
|
|
|
|
buildTimeout = 0;
|
2014-07-19 03:25:47 +03:00
|
|
|
|
useBuildHook = true;
|
2015-06-22 16:47:40 +03:00
|
|
|
|
reservedSize = 8 * 1024 * 1024;
|
2012-07-31 02:55:41 +03:00
|
|
|
|
fsyncMetadata = true;
|
|
|
|
|
useSQLiteWAL = true;
|
|
|
|
|
syncBeforeRegistering = false;
|
|
|
|
|
useSubstitutes = true;
|
2014-05-02 13:46:03 +03:00
|
|
|
|
buildUsersGroup = getuid() == 0 ? "nixbld" : "";
|
2014-07-25 13:57:12 +03:00
|
|
|
|
useSshSubstituter = true;
|
2012-07-31 02:55:41 +03:00
|
|
|
|
impersonateLinux26 = false;
|
|
|
|
|
keepLog = true;
|
|
|
|
|
compressLog = true;
|
2013-09-02 12:58:18 +03:00
|
|
|
|
maxLogSize = 0;
|
2012-07-31 02:55:41 +03:00
|
|
|
|
pollInterval = 5;
|
|
|
|
|
checkRootReachability = false;
|
|
|
|
|
gcKeepOutputs = false;
|
|
|
|
|
gcKeepDerivations = true;
|
2012-09-13 17:28:20 +03:00
|
|
|
|
autoOptimiseStore = false;
|
2012-07-31 02:55:41 +03:00
|
|
|
|
envKeepDerivations = false;
|
2013-09-06 17:36:56 +03:00
|
|
|
|
lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
|
2013-11-12 13:51:59 +02:00
|
|
|
|
showTrace = false;
|
2017-03-30 15:04:21 +03:00
|
|
|
|
enableNativeCode = false;
|
2017-02-16 15:46:36 +02:00
|
|
|
|
netrcFile = fmt("%s/%s", nixConfDir, "netrc");
|
2017-03-06 21:30:35 +02:00
|
|
|
|
caFile = getEnv("NIX_SSL_CERT_FILE", getEnv("SSL_CERT_FILE", "/etc/ssl/certs/ca-certificates.crt"));
|
2017-03-08 15:46:12 +02:00
|
|
|
|
enableImportFromDerivation = true;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
useSandbox = "false"; // TODO: make into an enum
|
|
|
|
|
|
|
|
|
|
#if __linux__
|
|
|
|
|
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" BASH_PATH);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
restrictEval = false;
|
|
|
|
|
buildRepeat = 0;
|
|
|
|
|
allowedImpureHostPrefixes = tokenizeString<StringSet>(DEFAULT_ALLOWED_IMPURE_PREFIXES);
|
|
|
|
|
sandboxShmSize = "50%";
|
|
|
|
|
darwinLogSandboxViolations = false;
|
|
|
|
|
runDiffHook = false;
|
|
|
|
|
diffHook = "";
|
|
|
|
|
enforceDeterminism = true;
|
2017-04-13 17:15:51 +03:00
|
|
|
|
binaryCachePublicKeys = Strings{"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="};
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
secretKeyFiles = Strings();
|
|
|
|
|
binaryCachesParallelConnections = 25;
|
|
|
|
|
enableHttp2 = true;
|
|
|
|
|
tarballTtl = 60 * 60;
|
|
|
|
|
signedBinaryCaches = "";
|
|
|
|
|
substituters = Strings();
|
2017-04-13 17:15:51 +03:00
|
|
|
|
binaryCaches = nixStore == "/nix/store" ? Strings{"https://cache.nixos.org/"} : Strings();
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
extraBinaryCaches = Strings();
|
|
|
|
|
trustedUsers = Strings({"root"});
|
|
|
|
|
allowedUsers = Strings({"*"});
|
|
|
|
|
printMissing = true;
|
2005-09-22 18:43:22 +03:00
|
|
|
|
}
|
2005-02-02 00:07:48 +02:00
|
|
|
|
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
void Settings::loadConfFile()
|
2005-02-02 00:07:48 +02:00
|
|
|
|
{
|
|
|
|
|
Path settingsFile = (format("%1%/%2%") % nixConfDir % "nix.conf").str();
|
|
|
|
|
if (!pathExists(settingsFile)) return;
|
|
|
|
|
string contents = readFile(settingsFile);
|
|
|
|
|
|
|
|
|
|
unsigned int pos = 0;
|
|
|
|
|
|
|
|
|
|
while (pos < contents.size()) {
|
|
|
|
|
string line;
|
|
|
|
|
while (pos < contents.size() && contents[pos] != '\n')
|
|
|
|
|
line += contents[pos++];
|
|
|
|
|
pos++;
|
|
|
|
|
|
2006-05-11 05:19:43 +03:00
|
|
|
|
string::size_type hash = line.find('#');
|
2005-02-02 00:07:48 +02:00
|
|
|
|
if (hash != string::npos)
|
|
|
|
|
line = string(line, 0, hash);
|
|
|
|
|
|
2012-09-19 22:43:23 +03:00
|
|
|
|
vector<string> tokens = tokenizeString<vector<string> >(line);
|
2005-09-22 18:43:22 +03:00
|
|
|
|
if (tokens.empty()) continue;
|
2005-02-02 00:07:48 +02:00
|
|
|
|
|
2012-09-19 22:43:23 +03:00
|
|
|
|
if (tokens.size() < 2 || tokens[1] != "=")
|
2016-11-26 01:37:43 +02:00
|
|
|
|
throw Error(format("illegal configuration line ‘%1%’ in ‘%2%’") % line % settingsFile);
|
2005-09-22 18:43:22 +03:00
|
|
|
|
|
2012-09-19 22:43:23 +03:00
|
|
|
|
string name = tokens[0];
|
2005-09-22 18:43:22 +03:00
|
|
|
|
|
2012-09-19 22:43:23 +03:00
|
|
|
|
vector<string>::iterator i = tokens.begin();
|
2005-09-22 18:43:22 +03:00
|
|
|
|
advance(i, 2);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings[name] = concatStringsSep(" ", Strings(i, tokens.end())); // FIXME: slow
|
2005-02-02 00:07:48 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
void Settings::set(const string & name, const string & value)
|
2005-02-02 00:07:48 +02:00
|
|
|
|
{
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings[name] = value;
|
2012-08-01 01:19:44 +03:00
|
|
|
|
overrides[name] = value;
|
2005-02-02 00:07:48 +02:00
|
|
|
|
}
|
2005-02-14 15:07:09 +02:00
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
void Settings::update()
|
2005-02-14 15:07:09 +02:00
|
|
|
|
{
|
2014-08-04 19:02:29 +03:00
|
|
|
|
_get(tryFallback, "build-fallback");
|
2017-02-28 13:54:50 +02:00
|
|
|
|
|
2017-04-13 17:15:51 +03:00
|
|
|
|
std::string s = "1";
|
|
|
|
|
_get(s, "build-max-jobs");
|
2017-02-28 13:54:50 +02:00
|
|
|
|
if (s == "auto")
|
|
|
|
|
maxBuildJobs = std::max(1U, std::thread::hardware_concurrency());
|
|
|
|
|
else
|
|
|
|
|
if (!string2Int(s, maxBuildJobs))
|
|
|
|
|
throw Error("configuration setting ‘build-max-jobs’ should be ‘auto’ or an integer");
|
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
_get(buildCores, "build-cores");
|
|
|
|
|
_get(thisSystem, "system");
|
|
|
|
|
_get(maxSilentTime, "build-max-silent-time");
|
|
|
|
|
_get(buildTimeout, "build-timeout");
|
|
|
|
|
_get(reservedSize, "gc-reserved-space");
|
|
|
|
|
_get(fsyncMetadata, "fsync-metadata");
|
|
|
|
|
_get(useSQLiteWAL, "use-sqlite-wal");
|
|
|
|
|
_get(syncBeforeRegistering, "sync-before-registering");
|
|
|
|
|
_get(useSubstitutes, "build-use-substitutes");
|
|
|
|
|
_get(buildUsersGroup, "build-users-group");
|
|
|
|
|
_get(impersonateLinux26, "build-impersonate-linux-26");
|
|
|
|
|
_get(keepLog, "build-keep-log");
|
|
|
|
|
_get(compressLog, "build-compress-log");
|
|
|
|
|
_get(maxLogSize, "build-max-log-size");
|
|
|
|
|
_get(pollInterval, "build-poll-interval");
|
|
|
|
|
_get(checkRootReachability, "gc-check-reachability");
|
|
|
|
|
_get(gcKeepOutputs, "gc-keep-outputs");
|
|
|
|
|
_get(gcKeepDerivations, "gc-keep-derivations");
|
|
|
|
|
_get(autoOptimiseStore, "auto-optimise-store");
|
|
|
|
|
_get(envKeepDerivations, "env-keep-derivations");
|
|
|
|
|
_get(sshSubstituterHosts, "ssh-substituter-hosts");
|
|
|
|
|
_get(useSshSubstituter, "use-ssh-substituter");
|
2017-03-30 15:04:21 +03:00
|
|
|
|
_get(enableNativeCode, "allow-unsafe-native-code-during-evaluation");
|
2014-08-04 19:02:29 +03:00
|
|
|
|
_get(useCaseHack, "use-case-hack");
|
2015-04-18 23:56:02 +03:00
|
|
|
|
_get(preBuildHook, "pre-build-hook");
|
2016-10-27 19:49:34 +03:00
|
|
|
|
_get(keepGoing, "keep-going");
|
|
|
|
|
_get(keepFailed, "keep-failed");
|
2017-02-16 15:46:36 +02:00
|
|
|
|
_get(netrcFile, "netrc-file");
|
2017-03-08 15:46:12 +02:00
|
|
|
|
_get(enableImportFromDerivation, "allow-import-from-derivation");
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
_get(useSandbox, "build-use-sandbox", "build-use-chroot");
|
|
|
|
|
_get(sandboxPaths, "build-sandbox-paths", "build-chroot-dirs");
|
|
|
|
|
_get(extraSandboxPaths, "build-extra-sandbox-paths", "build-extra-chroot-dirs");
|
|
|
|
|
_get(restrictEval, "restrict-eval");
|
|
|
|
|
_get(buildRepeat, "build-repeat");
|
|
|
|
|
_get(allowedImpureHostPrefixes, "allowed-impure-host-deps");
|
|
|
|
|
_get(sandboxShmSize, "sandbox-dev-shm-size");
|
|
|
|
|
_get(darwinLogSandboxViolations, "darwin-log-sandbox-violations");
|
|
|
|
|
_get(runDiffHook, "run-diff-hook");
|
|
|
|
|
_get(diffHook, "diff-hook");
|
|
|
|
|
_get(enforceDeterminism, "enforce-determinism");
|
|
|
|
|
_get(binaryCachePublicKeys, "binary-cache-public-keys");
|
|
|
|
|
_get(secretKeyFiles, "secret-key-files");
|
|
|
|
|
_get(binaryCachesParallelConnections, "binary-caches-parallel-connections");
|
|
|
|
|
_get(enableHttp2, "enable-http2");
|
|
|
|
|
_get(tarballTtl, "tarball-ttl");
|
|
|
|
|
_get(signedBinaryCaches, "signed-binary-caches");
|
|
|
|
|
_get(substituters, "substituters");
|
|
|
|
|
_get(binaryCaches, "binary-caches");
|
|
|
|
|
_get(extraBinaryCaches, "extra-binary-caches");
|
|
|
|
|
_get(trustedUsers, "trusted-users");
|
|
|
|
|
_get(allowedUsers, "allowed-users");
|
|
|
|
|
_get(printMissing, "print-missing");
|
|
|
|
|
|
|
|
|
|
/* Clear out any deprecated options that might be left, so users know we recognize the option
|
|
|
|
|
but aren't processing it anymore */
|
|
|
|
|
for (auto &i : deprecatedOptions) {
|
|
|
|
|
if (settings.find(i) != settings.end()) {
|
|
|
|
|
printError(format("warning: deprecated option '%1%' is no longer supported and will be ignored") % i);
|
|
|
|
|
settings.erase(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.size() != 0) {
|
|
|
|
|
string bad;
|
|
|
|
|
for (auto &i : settings)
|
|
|
|
|
bad += "'" + i.first + "', ";
|
|
|
|
|
bad.pop_back();
|
|
|
|
|
bad.pop_back();
|
|
|
|
|
throw Error(format("unrecognized options: %s") % bad);
|
|
|
|
|
}
|
2006-02-16 15:58:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
void Settings::checkDeprecated(const string & name)
|
|
|
|
|
{
|
|
|
|
|
if (deprecatedOptions.find(name) != deprecatedOptions.end())
|
|
|
|
|
printError(format("warning: deprecated option '%1%' will soon be unsupported") % name);
|
|
|
|
|
}
|
2006-02-16 15:58:10 +02:00
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
void Settings::_get(string & res, const string & name)
|
2006-02-16 15:58:10 +02:00
|
|
|
|
{
|
2012-07-31 02:55:41 +03:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
|
|
|
|
res = i->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::_get(string & res, const string & name1, const string & name2)
|
|
|
|
|
{
|
|
|
|
|
SettingsMap::iterator i = settings.find(name1);
|
|
|
|
|
if (i == settings.end()) i = settings.find(name2);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
res = i->second;
|
2005-02-14 15:07:09 +02:00
|
|
|
|
}
|
2006-09-05 00:06:23 +03:00
|
|
|
|
|
2006-12-08 17:44:00 +02:00
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
void Settings::_get(bool & res, const string & name)
|
2006-12-08 17:44:00 +02:00
|
|
|
|
{
|
2012-07-31 02:55:41 +03:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
if (i->second == "true") res = true;
|
|
|
|
|
else if (i->second == "false") res = false;
|
2016-11-26 01:37:43 +02:00
|
|
|
|
else throw Error(format("configuration option ‘%1%’ should be either ‘true’ or ‘false’, not ‘%2%’")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
% name % i->second);
|
2009-02-27 13:04:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
void Settings::_get(StringSet & res, const string & name)
|
2008-11-20 14:25:11 +02:00
|
|
|
|
{
|
2012-07-31 02:55:41 +03:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
|
|
|
|
res.clear();
|
|
|
|
|
Strings ss = tokenizeString<Strings>(i->second);
|
|
|
|
|
res.insert(ss.begin(), ss.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::_get(StringSet & res, const string & name1, const string & name2)
|
|
|
|
|
{
|
|
|
|
|
SettingsMap::iterator i = settings.find(name1);
|
|
|
|
|
if (i == settings.end()) i = settings.find(name2);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
res.clear();
|
2012-09-19 22:43:23 +03:00
|
|
|
|
Strings ss = tokenizeString<Strings>(i->second);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
res.insert(ss.begin(), ss.end());
|
2008-11-20 14:25:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
void Settings::_get(Strings & res, const string & name)
|
2014-02-08 07:05:46 +02:00
|
|
|
|
{
|
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
2014-02-08 07:05:46 +02:00
|
|
|
|
res = tokenizeString<Strings>(i->second);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-22 19:28:41 +02:00
|
|
|
|
|
2014-08-04 19:02:29 +03:00
|
|
|
|
template<class N> void Settings::_get(N & res, const string & name)
|
2011-11-22 19:28:41 +02:00
|
|
|
|
{
|
2012-07-31 02:55:41 +03:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
Explicitly model all settings and fail on unrecognized ones
Previously, the Settings class allowed other code to query for string
properties, which led to a proliferation of code all over the place making
up new options without any sort of central registry of valid options. This
commit pulls all those options back into the central Settings class and
removes the public get() methods, to discourage future abuses like that.
Furthermore, because we know the full set of options ahead of time, we
now fail loudly if someone enters an unrecognized option, thus preventing
subtle typos. With some template fun, we could probably also dump the full
set of options (with documentation, defaults, etc.) to the command line,
but I'm not doing that yet here.
2017-02-22 05:50:18 +02:00
|
|
|
|
checkDeprecated(i->first);
|
|
|
|
|
settings.erase(i);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
if (!string2Int(i->second, res))
|
2016-11-26 01:37:43 +02:00
|
|
|
|
throw Error(format("configuration setting ‘%1%’ should have an integer value") % name);
|
2011-11-22 19:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 23:09:54 +03:00
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
string Settings::pack()
|
2012-07-30 23:09:54 +03:00
|
|
|
|
{
|
|
|
|
|
string s;
|
2015-07-17 20:24:28 +03:00
|
|
|
|
for (auto & i : settings) {
|
|
|
|
|
if (i.first.find('\n') != string::npos ||
|
|
|
|
|
i.first.find('=') != string::npos ||
|
|
|
|
|
i.second.find('\n') != string::npos)
|
2012-08-01 01:50:32 +03:00
|
|
|
|
throw Error("illegal option name/value");
|
2015-07-17 20:24:28 +03:00
|
|
|
|
s += i.first; s += '='; s += i.second; s += '\n';
|
2012-07-30 23:09:54 +03:00
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-14 12:48:42 +02:00
|
|
|
|
void Settings::unpack(const string & pack) {
|
2014-02-08 07:05:46 +02:00
|
|
|
|
Strings lines = tokenizeString<Strings>(pack, "\n");
|
2015-07-17 20:24:28 +03:00
|
|
|
|
for (auto & i : lines) {
|
|
|
|
|
string::size_type eq = i.find('=');
|
2014-02-08 07:05:46 +02:00
|
|
|
|
if (eq == string::npos)
|
|
|
|
|
throw Error("illegal option name/value");
|
2015-07-17 20:24:28 +03:00
|
|
|
|
set(i.substr(0, eq), i.substr(eq + 1));
|
2014-02-08 07:05:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-08-01 01:19:44 +03:00
|
|
|
|
Settings::SettingsMap Settings::getOverrides()
|
|
|
|
|
{
|
|
|
|
|
return overrides;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-22 21:30:24 +02:00
|
|
|
|
const string nixVersion = PACKAGE_VERSION;
|
2012-11-27 14:29:55 +02:00
|
|
|
|
|
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
}
|