WIP: bees service
[jackhill/guix/guix.git] / nix / libstore / globals.cc
CommitLineData
36457566
LC
1#include "config.h"
2
3#include "globals.hh"
4#include "util.hh"
2bb04905 5#include "archive.hh"
36457566
LC
6
7#include <map>
8#include <algorithm>
9
10
11namespace nix {
12
13
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
8327e733 16 build daemon by setting the mode/ownership of the directory
36457566
LC
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"
20
21
22Settings settings;
23
24
25Settings::Settings()
26{
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;
6ef61cc4 39 multiplexedBuildOutput = false;
322eeb87 40 reservedSize = 8 * 1024 * 1024;
36457566
LC
41 fsyncMetadata = true;
42 useSQLiteWAL = true;
43 syncBeforeRegistering = false;
44 useSubstitutes = true;
45 useChroot = false;
36457566
LC
46 impersonateLinux26 = false;
47 keepLog = true;
f997137d 48#if HAVE_BZLIB_H
29a68668 49 logCompression = COMPRESSION_BZIP2;
f997137d
LC
50#else
51 logCompression = COMPRESSION_GZIP;
52#endif
36457566
LC
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;
63}
64
65
66void Settings::processEnvironment()
67{
68 nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
a87d66f3
LC
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");
9dd674db 72 nixConfDir = canonPath(getEnv("GUIX_CONFIGURATION_DIRECTORY", GUIX_CONFIGURATION_DIRECTORY));
36457566
LC
73 nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
74 nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
2e3e5d21 75 guixProgram = canonPath(getEnv("GUIX", nixBinDir + "/guix"));
36457566
LC
76}
77
78
36457566
LC
79void Settings::set(const string & name, const string & value)
80{
81 settings[name] = value;
82 overrides[name] = value;
83}
84
85
2bb04905
LC
86string Settings::get(const string & name, const string & def)
87{
88 auto i = settings.find(name);
89 if (i == settings.end()) return def;
90 return i->second;
91}
92
93
94Strings Settings::get(const string & name, const Strings & def)
95{
96 auto i = settings.find(name);
97 if (i == settings.end()) return def;
98 return tokenizeString<Strings>(i->second);
99}
100
101
102bool Settings::get(const string & name, bool def)
103{
104 bool res = def;
105 _get(res, name);
106 return res;
107}
108
b23b4d39
ED
109int Settings::get(const string & name, int def)
110{
111 int res = def;
112 _get(res, name);
113 return res;
114}
115
2bb04905 116
36457566
LC
117void Settings::update()
118{
2bb04905
LC
119 _get(tryFallback, "build-fallback");
120 _get(maxBuildJobs, "build-max-jobs");
121 _get(buildCores, "build-cores");
122 _get(thisSystem, "system");
6ef61cc4 123 _get(multiplexedBuildOutput, "multiplexed-build-output");
2bb04905
LC
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");
29a68668 135 // _get(logCompression, "build-log-compression");
2bb04905
LC
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");
36457566
LC
144}
145
146
2bb04905 147void Settings::_get(string & res, const string & name)
36457566
LC
148{
149 SettingsMap::iterator i = settings.find(name);
150 if (i == settings.end()) return;
151 res = i->second;
152}
153
154
2bb04905 155void Settings::_get(bool & res, const string & name)
36457566
LC
156{
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);
163}
164
165
2bb04905 166void Settings::_get(StringSet & res, const string & name)
36457566
LC
167{
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());
173}
174
2bb04905 175void Settings::_get(Strings & res, const string & name)
36457566
LC
176{
177 SettingsMap::iterator i = settings.find(name);
178 if (i == settings.end()) return;
179 res = tokenizeString<Strings>(i->second);
180}
181
182
2bb04905 183template<class N> void Settings::_get(N & res, const string & name)
36457566
LC
184{
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);
189}
190
191
192string Settings::pack()
193{
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)
76533c52 199 throw Error("invalid option name/value");
36457566
LC
200 s += i->first; s += '='; s += i->second; s += '\n';
201 }
202 return s;
203}
204
205
36457566
LC
206Settings::SettingsMap Settings::getOverrides()
207{
208 return overrides;
209}
210
211
212const string nixVersion = PACKAGE_VERSION;
213
214
215}