2003-06-16 13:33:38 +00:00
|
|
|
|
#include "globals.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
|
#include "util.hh"
|
2014-07-16 14:02:05 +00:00
|
|
|
|
#include "archive.hh"
|
2003-06-16 13:33:38 +00:00
|
|
|
|
|
2005-09-22 15:43:22 +00:00
|
|
|
|
#include <algorithm>
|
2017-02-27 15:01:54 +00:00
|
|
|
|
#include <map>
|
|
|
|
|
#include <thread>
|
2005-02-01 22:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
2013-03-08 00:24:59 +00: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"
|
|
|
|
|
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
Settings settings;
|
2003-07-31 13:47:13 +00:00
|
|
|
|
|
2005-02-01 22:07:48 +00:00
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
Settings::Settings()
|
|
|
|
|
{
|
2017-02-16 13:46:36 +00: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-30 23:55:41 +00:00
|
|
|
|
keepFailed = false;
|
|
|
|
|
keepGoing = false;
|
|
|
|
|
tryFallback = false;
|
|
|
|
|
maxBuildJobs = 1;
|
2017-02-27 15:01:54 +00:00
|
|
|
|
buildCores = std::max(1U, std::thread::hardware_concurrency());
|
2012-07-30 23:55:41 +00:00
|
|
|
|
readOnlyMode = false;
|
|
|
|
|
thisSystem = SYSTEM;
|
|
|
|
|
maxSilentTime = 0;
|
|
|
|
|
buildTimeout = 0;
|
2014-07-19 00:25:47 +00:00
|
|
|
|
useBuildHook = true;
|
2015-06-22 13:47:40 +00:00
|
|
|
|
reservedSize = 8 * 1024 * 1024;
|
2012-07-30 23:55:41 +00:00
|
|
|
|
fsyncMetadata = true;
|
|
|
|
|
useSQLiteWAL = true;
|
|
|
|
|
syncBeforeRegistering = false;
|
|
|
|
|
useSubstitutes = true;
|
2014-05-02 10:46:03 +00:00
|
|
|
|
buildUsersGroup = getuid() == 0 ? "nixbld" : "";
|
2014-07-25 10:57:12 +00:00
|
|
|
|
useSshSubstituter = true;
|
2012-07-30 23:55:41 +00:00
|
|
|
|
impersonateLinux26 = false;
|
|
|
|
|
keepLog = true;
|
|
|
|
|
compressLog = true;
|
2013-09-02 09:58:18 +00:00
|
|
|
|
maxLogSize = 0;
|
2012-07-30 23:55:41 +00:00
|
|
|
|
pollInterval = 5;
|
|
|
|
|
checkRootReachability = false;
|
|
|
|
|
gcKeepOutputs = false;
|
|
|
|
|
gcKeepDerivations = true;
|
2012-09-13 14:28:20 +00:00
|
|
|
|
autoOptimiseStore = false;
|
2012-07-30 23:55:41 +00:00
|
|
|
|
envKeepDerivations = false;
|
2013-09-06 14:36:56 +00:00
|
|
|
|
lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
|
2013-11-12 11:51:59 +00:00
|
|
|
|
showTrace = false;
|
2017-03-30 12:04:21 +00:00
|
|
|
|
enableNativeCode = false;
|
2017-02-16 13:46:36 +00:00
|
|
|
|
netrcFile = fmt("%s/%s", nixConfDir, "netrc");
|
2017-03-06 19:30:35 +00:00
|
|
|
|
caFile = getEnv("NIX_SSL_CERT_FILE", getEnv("SSL_CERT_FILE", "/etc/ssl/certs/ca-certificates.crt"));
|
2017-03-08 13:46:12 +00:00
|
|
|
|
enableImportFromDerivation = true;
|
2005-09-22 15:43:22 +00:00
|
|
|
|
}
|
2005-02-01 22:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
void Settings::loadConfFile()
|
2005-02-01 22:07:48 +00: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 02:19:43 +00:00
|
|
|
|
string::size_type hash = line.find('#');
|
2005-02-01 22:07:48 +00:00
|
|
|
|
if (hash != string::npos)
|
|
|
|
|
line = string(line, 0, hash);
|
|
|
|
|
|
2012-09-19 19:43:23 +00:00
|
|
|
|
vector<string> tokens = tokenizeString<vector<string> >(line);
|
2005-09-22 15:43:22 +00:00
|
|
|
|
if (tokens.empty()) continue;
|
2005-02-01 22:07:48 +00:00
|
|
|
|
|
2012-09-19 19:43:23 +00:00
|
|
|
|
if (tokens.size() < 2 || tokens[1] != "=")
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("illegal configuration line ‘%1%’ in ‘%2%’") % line % settingsFile);
|
2005-09-22 15:43:22 +00:00
|
|
|
|
|
2012-09-19 19:43:23 +00:00
|
|
|
|
string name = tokens[0];
|
2005-09-22 15:43:22 +00:00
|
|
|
|
|
2012-09-19 19:43:23 +00:00
|
|
|
|
vector<string>::iterator i = tokens.begin();
|
2005-09-22 15:43:22 +00:00
|
|
|
|
advance(i, 2);
|
2012-07-30 23:55:41 +00:00
|
|
|
|
settings[name] = concatStringsSep(" ", Strings(i, tokens.end())); // FIXME: slow
|
2005-02-01 22:07:48 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
void Settings::set(const string & name, const string & value)
|
2005-02-01 22:07:48 +00:00
|
|
|
|
{
|
2012-07-30 23:55:41 +00:00
|
|
|
|
settings[name] = value;
|
2012-07-31 22:19:44 +00:00
|
|
|
|
overrides[name] = value;
|
2005-02-01 22:07:48 +00:00
|
|
|
|
}
|
2005-02-14 13:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
2014-07-25 16:02:48 +00:00
|
|
|
|
string Settings::get(const string & name, const string & def)
|
|
|
|
|
{
|
|
|
|
|
auto i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return def;
|
|
|
|
|
return i->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-04 16:13:14 +00:00
|
|
|
|
Strings Settings::get(const string & name, const Strings & def)
|
|
|
|
|
{
|
|
|
|
|
auto i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return def;
|
|
|
|
|
return tokenizeString<Strings>(i->second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:18:13 +00:00
|
|
|
|
bool Settings::get(const string & name, bool def)
|
|
|
|
|
{
|
|
|
|
|
bool res = def;
|
|
|
|
|
_get(res, name);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-04-09 09:55:36 +00:00
|
|
|
|
int Settings::get(const string & name, int def)
|
|
|
|
|
{
|
|
|
|
|
int res = def;
|
|
|
|
|
_get(res, name);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
void Settings::update()
|
2005-02-14 13:07:09 +00:00
|
|
|
|
{
|
2014-08-04 16:02:29 +00:00
|
|
|
|
_get(tryFallback, "build-fallback");
|
2017-02-28 11:54:50 +00:00
|
|
|
|
|
|
|
|
|
auto s = get("build-max-jobs", std::string("1"));
|
|
|
|
|
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 16:02:29 +00: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 12:04:21 +00:00
|
|
|
|
_get(enableNativeCode, "allow-unsafe-native-code-during-evaluation");
|
2014-08-04 16:02:29 +00:00
|
|
|
|
_get(useCaseHack, "use-case-hack");
|
2015-04-18 20:56:02 +00:00
|
|
|
|
_get(preBuildHook, "pre-build-hook");
|
2016-10-27 16:49:34 +00:00
|
|
|
|
_get(keepGoing, "keep-going");
|
|
|
|
|
_get(keepFailed, "keep-failed");
|
2017-02-16 13:46:36 +00:00
|
|
|
|
_get(netrcFile, "netrc-file");
|
2017-03-08 13:46:12 +00:00
|
|
|
|
_get(enableImportFromDerivation, "allow-import-from-derivation");
|
2006-02-16 13:58:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-04 16:02:29 +00:00
|
|
|
|
void Settings::_get(string & res, const string & name)
|
2006-02-16 13:58:10 +00:00
|
|
|
|
{
|
2012-07-30 23:55:41 +00:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
res = i->second;
|
2005-02-14 13:07:09 +00:00
|
|
|
|
}
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
2006-12-08 15:44:00 +00:00
|
|
|
|
|
2014-08-04 16:02:29 +00:00
|
|
|
|
void Settings::_get(bool & res, const string & name)
|
2006-12-08 15:44:00 +00:00
|
|
|
|
{
|
2012-07-30 23:55:41 +00:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
if (i->second == "true") res = true;
|
|
|
|
|
else if (i->second == "false") res = false;
|
2016-11-25 23:37:43 +00:00
|
|
|
|
else throw Error(format("configuration option ‘%1%’ should be either ‘true’ or ‘false’, not ‘%2%’")
|
2012-07-30 23:55:41 +00:00
|
|
|
|
% name % i->second);
|
2009-02-27 11:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-04 16:02:29 +00:00
|
|
|
|
void Settings::_get(StringSet & res, const string & name)
|
2008-11-20 12:25:11 +00:00
|
|
|
|
{
|
2012-07-30 23:55:41 +00:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
res.clear();
|
2012-09-19 19:43:23 +00:00
|
|
|
|
Strings ss = tokenizeString<Strings>(i->second);
|
2012-07-30 23:55:41 +00:00
|
|
|
|
res.insert(ss.begin(), ss.end());
|
2008-11-20 12:25:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-04 16:02:29 +00:00
|
|
|
|
void Settings::_get(Strings & res, const string & name)
|
2014-02-08 05:05:46 +00:00
|
|
|
|
{
|
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
res = tokenizeString<Strings>(i->second);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-22 17:28:41 +00:00
|
|
|
|
|
2014-08-04 16:02:29 +00:00
|
|
|
|
template<class N> void Settings::_get(N & res, const string & name)
|
2011-11-22 17:28:41 +00:00
|
|
|
|
{
|
2012-07-30 23:55:41 +00:00
|
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
|
if (!string2Int(i->second, res))
|
2016-11-25 23:37:43 +00:00
|
|
|
|
throw Error(format("configuration setting ‘%1%’ should have an integer value") % name);
|
2011-11-22 17:28:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 20:09:54 +00:00
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
string Settings::pack()
|
2012-07-30 20:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
string s;
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : settings) {
|
|
|
|
|
if (i.first.find('\n') != string::npos ||
|
|
|
|
|
i.first.find('=') != string::npos ||
|
|
|
|
|
i.second.find('\n') != string::npos)
|
2012-07-31 22:50:32 +00:00
|
|
|
|
throw Error("illegal option name/value");
|
2015-07-17 17:24:28 +00:00
|
|
|
|
s += i.first; s += '='; s += i.second; s += '\n';
|
2012-07-30 20:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-14 10:48:42 +00:00
|
|
|
|
void Settings::unpack(const string & pack) {
|
2014-02-08 05:05:46 +00:00
|
|
|
|
Strings lines = tokenizeString<Strings>(pack, "\n");
|
2015-07-17 17:24:28 +00:00
|
|
|
|
for (auto & i : lines) {
|
|
|
|
|
string::size_type eq = i.find('=');
|
2014-02-08 05:05:46 +00:00
|
|
|
|
if (eq == string::npos)
|
|
|
|
|
throw Error("illegal option name/value");
|
2015-07-17 17:24:28 +00:00
|
|
|
|
set(i.substr(0, eq), i.substr(eq + 1));
|
2014-02-08 05:05:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-31 22:19:44 +00:00
|
|
|
|
Settings::SettingsMap Settings::getOverrides()
|
|
|
|
|
{
|
|
|
|
|
return overrides;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-22 19:30:24 +00:00
|
|
|
|
const string nixVersion = PACKAGE_VERSION;
|
2012-11-27 12:29:55 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
|
}
|