Merge branch 'staging'
[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 /* Whether to keep temporary directories of failed builds. */
70 bool keepFailed;
71
72 /* Whether to keep building subgoals when a sibling (another
73 subgoal of the same goal) fails. */
74 bool keepGoing;
75
76 /* User and groud id of the client issuing the build request. Used to set
77 the owner and group of the kept temporary directories of failed
78 builds. */
79 uid_t clientUid;
80 gid_t clientGid;
81
82 /* Whether, if we cannot realise the known closure corresponding
83 to a derivation, we should try to normalise the derivation
84 instead. */
85 bool tryFallback;
86
87 /* Verbosity level for build output. */
88 Verbosity buildVerbosity;
89
90 /* Maximum number of parallel build jobs. 0 means unlimited. */
91 unsigned int maxBuildJobs;
92
93 /* Number of CPU cores to utilize in parallel within a build,
94 i.e. by passing this number to Make via '-j'. 0 means that the
95 number of actual CPU cores on the local host ought to be
96 auto-detected. */
97 unsigned int buildCores;
98
99 /* Read-only mode. Don't copy stuff to the store, don't change
100 the database. */
101 bool readOnlyMode;
102
103 /* The canonical system name, as returned by config.guess. */
104 string thisSystem;
105
106 /* The maximum time in seconds that a builer can go without
107 producing any output on stdout/stderr before it is killed. 0
108 means infinity. */
109 time_t maxSilentTime;
110
111 /* The maximum duration in seconds that a builder can run. 0
112 means infinity. */
113 time_t buildTimeout;
114
115 /* The substituters. There are programs that can somehow realise
116 a store path without building, e.g., by downloading it or
117 copying it from a CD. */
118 Paths substituters;
119
120 /* Whether to use build hooks (for distributed builds). Sometimes
121 users want to disable this from the command-line. */
122 bool useBuildHook;
123
124 /* Whether buildDerivations() should print out lines on stderr in
125 a fixed format to allow its progress to be monitored. Each
126 line starts with a "@". The following are defined:
127
128 @ build-started <drvpath> <outpath> <system> <logfile> <pid>
129 @ build-failed <drvpath> <outpath> <exitcode> <error text>
130 @ build-succeeded <drvpath> <outpath>
131 @ substituter-started <outpath> <substituter>
132 @ substituter-failed <outpath> <exitcode> <error text>
133 @ substituter-succeeded <outpath>
134
135 Best combined with --no-build-output, otherwise stderr might
136 conceivably contain lines in this format printed by the
137 builders. */
138 bool printBuildTrace;
139
140 /* When true, 'buildDerivations' prefixes lines coming from builders so
141 that clients know exactly which line comes from which builder, and
142 which line comes from the daemon itself. The prefix for data coming
143 from builders is "log:PID:LEN:DATA" where PID uniquely identifies the
144 builder (PID is given in "build-started" traces.) */
145 bool multiplexedBuildOutput;
146
147 /* Amount of reserved space for the garbage collector
148 (/nix/var/nix/db/reserved). */
149 off_t reservedSize;
150
151 /* Whether SQLite should use fsync. */
152 bool fsyncMetadata;
153
154 /* Whether SQLite should use WAL mode. */
155 bool useSQLiteWAL;
156
157 /* Whether to call sync() before registering a path as valid. */
158 bool syncBeforeRegistering;
159
160 /* Whether to use substitutes. */
161 bool useSubstitutes;
162
163 /* The Unix group that contains the build users. */
164 string buildUsersGroup;
165
166 /* Whether to build in chroot. */
167 bool useChroot;
168
169 /* Whether to impersonate a Linux 2.6 machine on newer kernels. */
170 bool impersonateLinux26;
171
172 /* Whether to store build logs. */
173 bool keepLog;
174
175 /* Whether to compress logs. */
176 enum CompressionType logCompression;
177
178 /* Maximum number of bytes a builder can write to stdout/stderr
179 before being killed (0 means no limit). */
180 unsigned long maxLogSize;
181
182 /* Whether to cache build failures. */
183 bool cacheFailure;
184
185 /* How often (in seconds) to poll for locks. */
186 unsigned int pollInterval;
187
188 /* Whether to check if new GC roots can in fact be found by the
189 garbage collector. */
190 bool checkRootReachability;
191
192 /* Whether the garbage collector should keep outputs of live
193 derivations. */
194 bool gcKeepOutputs;
195
196 /* Whether the garbage collector should keep derivers of live
197 paths. */
198 bool gcKeepDerivations;
199
200 /* Whether to automatically replace files with identical contents
201 with hard links. */
202 bool autoOptimiseStore;
203
204 /* Whether to add derivations as a dependency of user environments
205 (to prevent them from being GCed). */
206 bool envKeepDerivations;
207
208 /* Whether to lock the Nix client and worker to the same CPU. */
209 bool lockCPU;
210
211 /* Whether to show a stack trace if Nix evaluation fails. */
212 bool showTrace;
213
214 private:
215 SettingsMap settings, overrides;
216
217 void _get(string & res, const string & name);
218 void _get(bool & res, const string & name);
219 void _get(StringSet & res, const string & name);
220 void _get(Strings & res, const string & name);
221 template<class N> void _get(N & res, const string & name);
222 };
223
224
225 // FIXME: don't use a global variable.
226 extern Settings settings;
227
228
229 extern const string nixVersion;
230
231
232 }