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