projects/guix·blob python-team · refs

235 lines · 6.8 KiB

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