gnu: linux-libre: Update to 5.1.4.
[guix.git] / nix / libstore / globals.cc
blob69f6d0656328ed554936b5bd497675bb50e39fa7
1 #include "config.h"
3 #include "globals.hh"
4 #include "util.hh"
5 #include "archive.hh"
7 #include <map>
8 #include <algorithm>
11 namespace nix {
14 /* The default location of the daemon socket, relative to nixStateDir.
15 The socket is in a directory to allow you to control access to the
16 build daemon by setting the mode/ownership of the directory
17 appropriately. (This wouldn't work on the socket itself since it
18 must be deleted and recreated on startup.) */
19 #define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
22 Settings settings;
25 Settings::Settings()
27 keepFailed = false;
28 keepGoing = false;
29 tryFallback = false;
30 buildVerbosity = lvlError;
31 maxBuildJobs = 1;
32 buildCores = 1;
33 readOnlyMode = false;
34 thisSystem = SYSTEM;
35 maxSilentTime = 0;
36 buildTimeout = 0;
37 useBuildHook = true;
38 printBuildTrace = false;
39 multiplexedBuildOutput = false;
40 reservedSize = 8 * 1024 * 1024;
41 fsyncMetadata = true;
42 useSQLiteWAL = true;
43 syncBeforeRegistering = false;
44 useSubstitutes = true;
45 useChroot = false;
46 impersonateLinux26 = false;
47 keepLog = true;
48 #if HAVE_BZLIB_H
49 logCompression = COMPRESSION_BZIP2;
50 #else
51 logCompression = COMPRESSION_GZIP;
52 #endif
53 maxLogSize = 0;
54 cacheFailure = false;
55 pollInterval = 5;
56 checkRootReachability = false;
57 gcKeepOutputs = false;
58 gcKeepDerivations = true;
59 autoOptimiseStore = false;
60 envKeepDerivations = false;
61 lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
62 showTrace = false;
66 void Settings::processEnvironment()
68 nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
69 nixLogDir = canonPath(getEnv("GUIX_LOG_DIRECTORY", NIX_LOG_DIR));
70 nixStateDir = canonPath(getEnv("GUIX_STATE_DIRECTORY", NIX_STATE_DIR));
71 nixDBPath = getEnv("GUIX_DATABASE_DIRECTORY", nixStateDir + "/db");
72 nixConfDir = canonPath(getEnv("GUIX_CONFIGURATION_DIRECTORY", GUIX_CONFIGURATION_DIRECTORY));
73 nixLibexecDir = canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR));
74 nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
75 nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
79 void Settings::set(const string & name, const string & value)
81 settings[name] = value;
82 overrides[name] = value;
86 string Settings::get(const string & name, const string & def)
88 auto i = settings.find(name);
89 if (i == settings.end()) return def;
90 return i->second;
94 Strings Settings::get(const string & name, const Strings & def)
96 auto i = settings.find(name);
97 if (i == settings.end()) return def;
98 return tokenizeString<Strings>(i->second);
102 bool Settings::get(const string & name, bool def)
104 bool res = def;
105 _get(res, name);
106 return res;
109 int Settings::get(const string & name, int def)
111 int res = def;
112 _get(res, name);
113 return res;
117 void Settings::update()
119 _get(tryFallback, "build-fallback");
120 _get(maxBuildJobs, "build-max-jobs");
121 _get(buildCores, "build-cores");
122 _get(thisSystem, "system");
123 _get(multiplexedBuildOutput, "multiplexed-build-output");
124 _get(maxSilentTime, "build-max-silent-time");
125 _get(buildTimeout, "build-timeout");
126 _get(reservedSize, "gc-reserved-space");
127 _get(fsyncMetadata, "fsync-metadata");
128 _get(useSQLiteWAL, "use-sqlite-wal");
129 _get(syncBeforeRegistering, "sync-before-registering");
130 _get(useSubstitutes, "build-use-substitutes");
131 _get(buildUsersGroup, "build-users-group");
132 _get(useChroot, "build-use-chroot");
133 _get(impersonateLinux26, "build-impersonate-linux-26");
134 _get(keepLog, "build-keep-log");
135 // _get(logCompression, "build-log-compression");
136 _get(maxLogSize, "build-max-log-size");
137 _get(cacheFailure, "build-cache-failure");
138 _get(pollInterval, "build-poll-interval");
139 _get(checkRootReachability, "gc-check-reachability");
140 _get(gcKeepOutputs, "gc-keep-outputs");
141 _get(gcKeepDerivations, "gc-keep-derivations");
142 _get(autoOptimiseStore, "auto-optimise-store");
143 _get(envKeepDerivations, "env-keep-derivations");
147 void Settings::_get(string & res, const string & name)
149 SettingsMap::iterator i = settings.find(name);
150 if (i == settings.end()) return;
151 res = i->second;
155 void Settings::_get(bool & res, const string & name)
157 SettingsMap::iterator i = settings.find(name);
158 if (i == settings.end()) return;
159 if (i->second == "true") res = true;
160 else if (i->second == "false") res = false;
161 else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
162 % name % i->second);
166 void Settings::_get(StringSet & res, const string & name)
168 SettingsMap::iterator i = settings.find(name);
169 if (i == settings.end()) return;
170 res.clear();
171 Strings ss = tokenizeString<Strings>(i->second);
172 res.insert(ss.begin(), ss.end());
175 void Settings::_get(Strings & res, const string & name)
177 SettingsMap::iterator i = settings.find(name);
178 if (i == settings.end()) return;
179 res = tokenizeString<Strings>(i->second);
183 template<class N> void Settings::_get(N & res, const string & name)
185 SettingsMap::iterator i = settings.find(name);
186 if (i == settings.end()) return;
187 if (!string2Int(i->second, res))
188 throw Error(format("configuration setting `%1%' should have an integer value") % name);
192 string Settings::pack()
194 string s;
195 foreach (SettingsMap::iterator, i, settings) {
196 if (i->first.find('\n') != string::npos ||
197 i->first.find('=') != string::npos ||
198 i->second.find('\n') != string::npos)
199 throw Error("illegal option name/value");
200 s += i->first; s += '='; s += i->second; s += '\n';
202 return s;
206 Settings::SettingsMap Settings::getOverrides()
208 return overrides;
212 const string nixVersion = PACKAGE_VERSION;