daemon: Invoke 'guix gc --list-busy' instead of 'list-runtime-roots'.
[jackhill/guix/guix.git] / nix / libstore / globals.hh
1 #pragma once
2
3 #include "config.h"
4 #include "types.hh"
5
6 #include <map>
7 #include <sys/types.h>
8
9
10 namespace nix {
11
12 enum CompressionType
13 {
14 COMPRESSION_NONE = 0,
15 COMPRESSION_GZIP = 1
16 #if HAVE_BZLIB_H
17 , COMPRESSION_BZIP2 = 2
18 #endif
19 };
20
21 struct Settings {
22
23 typedef std::map<string, string> SettingsMap;
24
25 Settings();
26
27 void processEnvironment();
28
29 void set(const string & name, const string & value);
30
31 string get(const string & name, const string & def);
32
33 Strings get(const string & name, const Strings & def);
34
35 bool get(const string & name, bool def);
36
37 int get(const string & name, int def);
38
39 void update();
40
41 string pack();
42
43 SettingsMap getOverrides();
44
45 /* The directory where we store sources and derived files. */
46 Path nixStore;
47
48 /* The directory where we log various operations. */
49 Path nixLogDir;
50
51 /* The directory where state is stored. */
52 Path nixStateDir;
53
54 /* The directory where we keep the SQLite database. */
55 Path nixDBPath;
56
57 /* The directory where configuration files are stored. */
58 Path nixConfDir;
59
60 /* The directory where internal helper programs are stored. */
61 Path nixLibexecDir;
62
63 /* The directory where the main programs are stored. */
64 Path nixBinDir;
65
66 /* File name of the socket the daemon listens to. */
67 Path nixDaemonSocketFile;
68
69 /* Absolute file name of the 'guix' program. */
70 Path guixProgram;
71
72 /* Whether to keep temporary directories of failed builds. */
73 bool keepFailed;
74
75 /* Whether to keep building subgoals when a sibling (another
76 subgoal of the same goal) fails. */
77 bool keepGoing;
78
79 /* User and groud id of the client issuing the build request. Used to set
80 the owner and group of the kept temporary directories of failed
81 builds. */
82 uid_t clientUid;
83 gid_t clientGid;
84
85 /* Whether, if we cannot realise the known closure corresponding
86 to a derivation, we should try to normalise the derivation
87 instead. */
88 bool tryFallback;
89
90 /* Verbosity level for build output. */
91 Verbosity buildVerbosity;
92
93 /* Maximum number of parallel build jobs. 0 means unlimited. */
94 unsigned int maxBuildJobs;
95
96 /* Number of CPU cores to utilize in parallel within a build,
97 i.e. by passing this number to Make via '-j'. 0 means that the
98 number of actual CPU cores on the local host ought to be
99 auto-detected. */
100 unsigned int buildCores;
101
102 /* Read-only mode. Don't copy stuff to the store, don't change
103 the database. */
104 bool readOnlyMode;
105
106 /* The canonical system name, as returned by config.guess. */
107 string thisSystem;
108
109 /* The maximum time in seconds that a builer can go without
110 producing any output on stdout/stderr before it is killed. 0
111 means infinity. */
112 time_t maxSilentTime;
113
114 /* The maximum duration in seconds that a builder can run. 0
115 means infinity. */
116 time_t buildTimeout;
117
118 /* The substituters. There are programs that can somehow realise
119 a store path without building, e.g., by downloading it or
120 copying it from a CD. */
121 Paths substituters;
122
123 /* Whether to use build hooks (for distributed builds). Sometimes
124 users want to disable this from the command-line. */
125 bool useBuildHook;
126
127 /* Whether buildDerivations() should print out lines on stderr in
128 a fixed format to allow its progress to be monitored. Each
129 line starts with a "@". The following are defined:
130
131 @ build-started <drvpath> <outpath> <system> <logfile> <pid>
132 @ build-failed <drvpath> <outpath> <exitcode> <error text>
133 @ build-succeeded <drvpath> <outpath>
134 @ substituter-started <outpath> <substituter>
135 @ substituter-failed <outpath> <exitcode> <error text>
136 @ substituter-succeeded <outpath>
137
138 Best combined with --no-build-output, otherwise stderr might
139 conceivably contain lines in this format printed by the
140 builders. */
141 bool printBuildTrace;
142
143 /* When true, 'buildDerivations' prefixes lines coming from builders so
144 that clients know exactly which line comes from which builder, and
145 which line comes from the daemon itself. The prefix for data coming
146 from builders is "log:PID:LEN:DATA" where PID uniquely identifies the
147 builder (PID is given in "build-started" traces.) */
148 bool multiplexedBuildOutput;
149
150 /* Amount of reserved space for the garbage collector
151 (/nix/var/nix/db/reserved). */
152 off_t reservedSize;
153
154 /* Whether SQLite should use fsync. */
155 bool fsyncMetadata;
156
157 /* Whether SQLite should use WAL mode. */
158 bool useSQLiteWAL;
159
160 /* Whether to call sync() before registering a path as valid. */
161 bool syncBeforeRegistering;
162
163 /* Whether to use substitutes. */
164 bool useSubstitutes;
165
166 /* The Unix group that contains the build users. */
167 string buildUsersGroup;
168
169 /* Whether to build in chroot. */
170 bool useChroot;
171
172 /* Whether to impersonate a Linux 2.6 machine on newer kernels. */
173 bool impersonateLinux26;
174
175 /* Whether to store build logs. */
176 bool keepLog;
177
178 /* Whether to compress logs. */
179 enum CompressionType logCompression;
180
181 /* Maximum number of bytes a builder can write to stdout/stderr
182 before being killed (0 means no limit). */
183 unsigned long maxLogSize;
184
185 /* Whether to cache build failures. */
186 bool cacheFailure;
187
188 /* How often (in seconds) to poll for locks. */
189 unsigned int pollInterval;
190
191 /* Whether to check if new GC roots can in fact be found by the
192 garbage collector. */
193 bool checkRootReachability;
194
195 /* Whether the garbage collector should keep outputs of live
196 derivations. */
197 bool gcKeepOutputs;
198
199 /* Whether the garbage collector should keep derivers of live
200 paths. */
201 bool gcKeepDerivations;
202
203 /* Whether to automatically replace files with identical contents
204 with hard links. */
205 bool autoOptimiseStore;
206
207 /* Whether to add derivations as a dependency of user environments
208 (to prevent them from being GCed). */
209 bool envKeepDerivations;
210
211 /* Whether to lock the Nix client and worker to the same CPU. */
212 bool lockCPU;
213
214 /* Whether to show a stack trace if Nix evaluation fails. */
215 bool showTrace;
216
217 private:
218 SettingsMap settings, overrides;
219
220 void _get(string & res, const string & name);
221 void _get(bool & res, const string & name);
222 void _get(StringSet & res, const string & name);
223 void _get(Strings & res, const string & name);
224 template<class N> void _get(N & res, const string & name);
225 };
226
227
228 // FIXME: don't use a global variable.
229 extern Settings settings;
230
231
232 extern const string nixVersion;
233
234
235 }