2011-11-22 18:28:41 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
#include "globals.hh"
|
2006-09-04 23:06:23 +02:00
|
|
|
#include "util.hh"
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2005-02-01 23:07:48 +01:00
|
|
|
#include <map>
|
2005-09-22 17:43:22 +02:00
|
|
|
#include <algorithm>
|
2005-02-01 23:07:48 +01:00
|
|
|
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
Settings settings;
|
2003-07-31 15:47:13 +02:00
|
|
|
|
2005-02-01 23:07:48 +01:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
Settings::Settings()
|
|
|
|
{
|
|
|
|
keepFailed = false;
|
|
|
|
keepGoing = false;
|
|
|
|
tryFallback = false;
|
|
|
|
buildVerbosity = lvlError;
|
|
|
|
maxBuildJobs = 1;
|
|
|
|
buildCores = 1;
|
|
|
|
readOnlyMode = false;
|
|
|
|
thisSystem = SYSTEM;
|
|
|
|
maxSilentTime = 0;
|
|
|
|
buildTimeout = 0;
|
|
|
|
useBuildHook = true;
|
|
|
|
printBuildTrace = false;
|
|
|
|
reservedSize = 1024 * 1024;
|
|
|
|
fsyncMetadata = true;
|
|
|
|
useSQLiteWAL = true;
|
|
|
|
syncBeforeRegistering = false;
|
|
|
|
useSubstitutes = true;
|
|
|
|
useChroot = false;
|
|
|
|
dirsInChroot.insert("/dev");
|
|
|
|
dirsInChroot.insert("/dev/pts");
|
|
|
|
impersonateLinux26 = false;
|
|
|
|
keepLog = true;
|
|
|
|
compressLog = true;
|
|
|
|
cacheFailure = false;
|
|
|
|
pollInterval = 5;
|
|
|
|
checkRootReachability = false;
|
|
|
|
gcKeepOutputs = false;
|
|
|
|
gcKeepDerivations = true;
|
2012-09-13 16:28:20 +02:00
|
|
|
autoOptimiseStore = false;
|
2012-07-31 01:55:41 +02:00
|
|
|
envKeepDerivations = false;
|
|
|
|
}
|
2005-02-01 23:07:48 +01:00
|
|
|
|
2012-07-30 22:09:54 +02:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::processEnvironment()
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db");
|
|
|
|
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));
|
2005-09-22 17:43:22 +02:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
string subs = getEnv("NIX_SUBSTITUTERS", "default");
|
|
|
|
if (subs == "default") {
|
2012-11-09 14:58:10 +01:00
|
|
|
if (getEnv("NIX_OTHER_STORES") != "")
|
|
|
|
substituters.push_back(nixLibexecDir + "/nix/substituters/copy-from-other-stores.pl");
|
2012-07-31 01:55:41 +02:00
|
|
|
substituters.push_back(nixLibexecDir + "/nix/substituters/download-using-manifests.pl");
|
|
|
|
substituters.push_back(nixLibexecDir + "/nix/substituters/download-from-binary-cache.pl");
|
|
|
|
} else
|
2012-09-19 21:43:23 +02:00
|
|
|
substituters = tokenizeString<Strings>(subs, ":");
|
2005-09-22 17:43:22 +02:00
|
|
|
}
|
2005-02-01 23:07:48 +01:00
|
|
|
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::loadConfFile()
|
2005-02-01 23:07:48 +01: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 04:19:43 +02:00
|
|
|
string::size_type hash = line.find('#');
|
2005-02-01 23:07:48 +01:00
|
|
|
if (hash != string::npos)
|
|
|
|
line = string(line, 0, hash);
|
|
|
|
|
2012-09-19 21:43:23 +02:00
|
|
|
vector<string> tokens = tokenizeString<vector<string> >(line);
|
2005-09-22 17:43:22 +02:00
|
|
|
if (tokens.empty()) continue;
|
2005-02-01 23:07:48 +01:00
|
|
|
|
2012-09-19 21:43:23 +02:00
|
|
|
if (tokens.size() < 2 || tokens[1] != "=")
|
2005-02-14 14:07:09 +01:00
|
|
|
throw Error(format("illegal configuration line `%1%' in `%2%'") % line % settingsFile);
|
2005-09-22 17:43:22 +02:00
|
|
|
|
2012-09-19 21:43:23 +02:00
|
|
|
string name = tokens[0];
|
2005-09-22 17:43:22 +02:00
|
|
|
|
2012-09-19 21:43:23 +02:00
|
|
|
vector<string>::iterator i = tokens.begin();
|
2005-09-22 17:43:22 +02:00
|
|
|
advance(i, 2);
|
2012-07-31 01:55:41 +02:00
|
|
|
settings[name] = concatStringsSep(" ", Strings(i, tokens.end())); // FIXME: slow
|
2005-02-01 23:07:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::set(const string & name, const string & value)
|
2005-02-01 23:07:48 +01:00
|
|
|
{
|
2012-07-31 01:55:41 +02:00
|
|
|
settings[name] = value;
|
2012-08-01 00:19:44 +02:00
|
|
|
overrides[name] = value;
|
2005-02-01 23:07:48 +01:00
|
|
|
}
|
2005-02-14 14:07:09 +01:00
|
|
|
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::update()
|
2005-02-14 14:07:09 +01:00
|
|
|
{
|
2012-07-31 23:56:02 +02:00
|
|
|
get(tryFallback, "build-fallback");
|
2012-07-31 01:55:41 +02:00
|
|
|
get(maxBuildJobs, "build-max-jobs");
|
|
|
|
get(buildCores, "build-cores");
|
2012-07-31 23:56:02 +02:00
|
|
|
get(thisSystem, "system");
|
2012-07-31 01:55:41 +02:00
|
|
|
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(useChroot, "build-use-chroot");
|
|
|
|
get(dirsInChroot, "build-chroot-dirs");
|
|
|
|
get(impersonateLinux26, "build-impersonate-linux-26");
|
|
|
|
get(keepLog, "build-keep-log");
|
|
|
|
get(compressLog, "build-compress-log");
|
|
|
|
get(cacheFailure, "build-cache-failure");
|
|
|
|
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");
|
2006-02-16 14:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::get(string & res, const string & name)
|
2006-02-16 14:58:10 +01:00
|
|
|
{
|
2012-07-31 01:55:41 +02:00
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
res = i->second;
|
2005-02-14 14:07:09 +01:00
|
|
|
}
|
2006-09-04 23:06:23 +02:00
|
|
|
|
2006-12-08 16:44:00 +01:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
void Settings::get(bool & res, const string & name)
|
2006-12-08 16:44:00 +01:00
|
|
|
{
|
2012-07-31 01:55:41 +02: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;
|
|
|
|
else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
|
|
|
|
% name % i->second);
|
2009-02-27 12:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-29 23:04:02 +01:00
|
|
|
void Settings::get(StringSet & res, const string & name)
|
2008-11-20 13:25:11 +01:00
|
|
|
{
|
2012-07-31 01:55:41 +02:00
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
res.clear();
|
2012-09-19 21:43:23 +02:00
|
|
|
Strings ss = tokenizeString<Strings>(i->second);
|
2012-07-31 01:55:41 +02:00
|
|
|
res.insert(ss.begin(), ss.end());
|
2008-11-20 13:25:11 +01:00
|
|
|
}
|
|
|
|
|
2011-11-22 18:28:41 +01:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
template<class N> void Settings::get(N & res, const string & name)
|
2011-11-22 18:28:41 +01:00
|
|
|
{
|
2012-07-31 01:55:41 +02:00
|
|
|
SettingsMap::iterator i = settings.find(name);
|
|
|
|
if (i == settings.end()) return;
|
|
|
|
if (!string2Int(i->second, res))
|
|
|
|
throw Error(format("configuration setting `%1%' should have an integer value") % name);
|
2011-11-22 18:28:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-30 22:09:54 +02:00
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
string Settings::pack()
|
2012-07-30 22:09:54 +02:00
|
|
|
{
|
|
|
|
string s;
|
2012-07-31 01:55:41 +02:00
|
|
|
foreach (SettingsMap::iterator, i, settings) {
|
2012-08-01 00:50:32 +02:00
|
|
|
if (i->first.find('\n') != string::npos ||
|
|
|
|
i->first.find('=') != string::npos ||
|
|
|
|
i->second.find('\n') != string::npos)
|
|
|
|
throw Error("illegal option name/value");
|
2012-07-31 01:55:41 +02:00
|
|
|
s += i->first; s += '='; s += i->second; s += '\n';
|
2012-07-30 22:09:54 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-01 00:19:44 +02:00
|
|
|
Settings::SettingsMap Settings::getOverrides()
|
|
|
|
{
|
|
|
|
return overrides;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-27 13:29:55 +01:00
|
|
|
const string nixVersion = NIX_VERSION;
|
|
|
|
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
}
|