Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
globals.hh
Go to the documentation of this file.
1#pragma once
3
4#include <sys/types.h>
5
6#include "nix/util/types.hh"
13
14#include "nix/store/config.hh"
15
16namespace nix {
17
18struct ProfileDirsOptions;
19
20struct LogFileSettings : public virtual Config
21{
22private:
23 void anchor() override;
24
25public:
26 Setting<bool> keepLog{
27 this,
28 true,
29 "keep-build-log",
30 R"(
31 If set to `true` (the default), Nix writes the build log of a
32 derivation (i.e. the standard output and error of its builder) to
33 the directory `/nix/var/log/nix/drvs`. The build log can be
34 retrieved using the command `nix-store -l path`.
35 )",
36 {"build-keep-log"}};
37
38 Setting<bool> compressLog{
39 this,
40 true,
41 "compress-build-log",
42 R"(
43 If set to `true` (the default), build logs written to
44 `/nix/var/log/nix/drvs` are compressed on the fly using bzip2.
45 Otherwise, they are not compressed.
46 )",
47 {"build-compress-log"}};
48};
49
50struct NarInfoDiskCacheSettings : public virtual Config
51{
52private:
53 void anchor() override;
54
55public:
56 Setting<unsigned int> ttlNegative{
57 this,
58 3600,
59 "narinfo-cache-negative-ttl",
60 R"(
61 The TTL in seconds for negative lookups.
62 If a store path is queried from a [substituter](#conf-substituters) but was not found, a negative lookup is cached in the local disk cache database for the specified duration.
63
64 Set to `0` to force updating the lookup cache.
65
66 To wipe the lookup cache completely:
67
68 ```shell-session
69 $ rm $HOME/.cache/nix/binary-cache-v*.sqlite*
70 # rm /root/.cache/nix/binary-cache-v*.sqlite*
71 ```
72 )"};
73
74 Setting<unsigned int> ttlPositive{
75 this,
76 30 * 24 * 3600,
77 "narinfo-cache-positive-ttl",
78 R"(
79 The TTL in seconds for positive lookups. If a store path is queried
80 from a substituter, the result of the query is cached in the
81 local disk cache database including some of the NAR metadata. The
82 default TTL is a month, setting a shorter TTL for positive lookups
83 can be useful for binary caches that have frequent garbage
84 collection, in which case having a more frequent cache invalidation
85 would prevent trying to pull the path again and failing with a hash
86 mismatch if the build isn't reproducible.
87 )"};
88
90 this,
91 7 * 24 * 3600,
92 "narinfo-cache-meta-ttl",
93 R"(
94 The TTL in seconds for caching binary cache metadata (i.e.
95 `/nix-cache-info`). This determines how long information about a
96 binary cache (such as its store directory, priority, and whether it
97 wants mass queries) is considered valid before being refreshed.
98 )"};
99};
100
101class Settings : public virtual Config,
102 private LocalSettings,
103 private LogFileSettings,
104 private WorkerSettings,
106{
107private:
108 void anchor() override;
109public:
110 StringSet getDefaultSystemFeatures();
111
112 StringSet getDefaultExtraPlatforms();
113
114 bool isWSL1();
115
116public:
117
118 Settings();
119
124 {
125 return *this;
126 }
127
128 const LocalSettings & getLocalSettings() const
129 {
130 return *this;
131 }
132
137 {
138 return *this;
139 }
140
141 const LogFileSettings & getLogFileSettings() const
142 {
143 return *this;
144 }
145
149 WorkerSettings & getWorkerSettings()
150 {
151 return *this;
152 }
153
154 const WorkerSettings & getWorkerSettings() const
155 {
156 return *this;
157 }
158
163 {
164 return *this;
165 }
166
168 {
169 return *this;
170 }
171
172 static unsigned int getDefaultCores();
173
177 std::filesystem::path nixStateDir;
178
180 this,
181 StoreReference::parse(getEnv("NIX_REMOTE").value_or("auto")),
182 "store",
183 R"(
184 The [URL of the Nix store](@docroot@/store/types/index.md#store-url-format)
185 to use for most operations.
186
187 See the
188 [Store Types](@docroot@/store/types/index.md)
189 section of the manual for supported store types and settings.
190
191 Can be overridden by the [`NIX_REMOTE`](@docroot@/command-ref/env-common.md#env-NIX_REMOTE) environment variable.
192
193 The default value is [`auto`](@docroot@/store/types/index.md#auto).
194 )"};
195
196 Setting<bool> useSQLiteWAL{this, !isWSL1(), "use-sqlite-wal", "Whether SQLite should use WAL mode."};
197
198 Setting<bool> keepFailed{this, false, "keep-failed", "Whether to keep temporary directories of failed builds."};
199
203 bool verboseBuild = true;
204
209 bool readOnlyMode = false;
210
211 Setting<std::string> thisSystem{
212 this,
213 NIX_LOCAL_SYSTEM,
214 "system",
215 R"(
216 The system type of the current Nix installation.
217 Nix only builds a given [store derivation](@docroot@/glossary.md#gloss-store-derivation) locally when its `system` attribute equals any of the values specified here or in [`extra-platforms`](#conf-extra-platforms).
218
219 The default value is set when Nix itself is compiled for the system it will run on.
220 The following system types are widely used, as Nix is actively supported on these platforms:
221
222 - `x86_64-linux`
223 - `x86_64-darwin` (only via Rosetta 2)
224 - `i686-linux`
225 - `aarch64-linux`
226 - `aarch64-darwin`
227 - `armv6l-linux`
228 - `armv7l-linux`
229
230 In general, you do not have to modify this setting.
231 While you can force Nix to run a Darwin-specific `builder` executable on a Linux machine, the result would obviously be wrong.
232
233 This value is available in the Nix language as
234 [`builtins.currentSystem`](@docroot@/language/builtins.md#builtins-currentSystem)
235 if the
236 [`eval-system`](#conf-eval-system)
237 configuration option is set as the empty string.
238 )"};
239
240 Setting<Strings> trustedPublicKeys{
241 this,
242 {"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="},
243 "trusted-public-keys",
244 R"(
245 A whitespace-separated list of public keys.
246
247 At least one of the following condition must be met
248 for Nix to accept copying a store object from another
249 Nix store (such as a [substituter](#conf-substituters)):
250
251 - the store object has been signed using a key in the trusted keys list
252 - the [`require-sigs`](#conf-require-sigs) option has been set to `false`
253 - the store URL is configured with `trusted=true`
254 - the store object is [content-addressed](@docroot@/glossary.md#gloss-content-addressed-store-object)
255 )",
256 {"binary-cache-public-keys"}};
257
258 Setting<Strings> secretKeyFiles{
259 this,
260 {},
261 "secret-key-files",
262 R"(
263 A whitespace-separated list of files containing secret (private)
264 keys. These are used to sign locally-built paths. They can be
265 generated using `nix-store --generate-binary-cache-key`. The
266 corresponding public key can be distributed to other users, who
267 can add it to `trusted-public-keys` in their `nix.conf`.
268 )"};
269
270 Setting<bool> requireSigs{
271 this,
272 true,
273 "require-sigs",
274 R"(
275 If set to `true` (the default), any non-content-addressed path added
276 or copied to the Nix store (e.g. when substituting from a binary
277 cache) must have a signature by a trusted key. A trusted key is one
278 listed in `trusted-public-keys`, or a public key counterpart to a
279 private key stored in a file listed in `secret-key-files`.
280
281 Set to `false` to disable signature checking and trust all
282 non-content-addressed paths unconditionally.
283
284 (Content-addressed paths are inherently trustworthy and thus
285 unaffected by this configuration option.)
286 )"};
287
288 Setting<StringSet> extraPlatforms{
289 this,
290 getDefaultExtraPlatforms(),
291 "extra-platforms",
292 R"(
293 System types of executables that can be run on this machine.
294
295 Nix only builds a given [store derivation](@docroot@/glossary.md#gloss-store-derivation) locally when its `system` attribute equals any of the values specified here or in the [`system` option](#conf-system).
296
297 Setting this can be useful to build derivations locally on compatible machines:
298 - `i686-linux` executables can be run on `x86_64-linux` machines (set by default)
299 - `x86_64-darwin` executables can be run on macOS `aarch64-darwin` with Rosetta 2 (set by default where applicable)
300 - `armv6` and `armv5tel` executables can be run on `armv7`
301 - some `aarch64` machines can also natively run 32-bit ARM code
302 - `qemu-user` may be used to support non-native platforms (though this
303 may be slow and buggy)
304
305 Build systems usually detect the target platform to be the current physical system and therefore produce machine code incompatible with what may be intended in the derivation.
306 You should design your derivation's `builder` accordingly and cross-check the results when using this option against natively-built versions of your derivation.
307 )",
308 {},
309 // Don't document the machine-specific default value
310 false};
311
312 Setting<StringSet> systemFeatures{
313 this,
314 getDefaultSystemFeatures(),
315 "system-features",
316 R"(
317 A set of system “features” supported by this machine.
318
319 This complements the [`system`](#conf-system) and [`extra-platforms`](#conf-extra-platforms) configuration options and the corresponding [`system`](@docroot@/language/derivations.md#attr-system) attribute on derivations.
320
321 A derivation can require system features in the [`requiredSystemFeatures` attribute](@docroot@/language/advanced-attributes.md#adv-attr-requiredSystemFeatures), and the machine to build the derivation must have them.
322
323 System features are user-defined, but Nix sets the following defaults:
324
325 - `apple-virt`
326
327 Included on Darwin if virtualization is available.
328
329 - `kvm`
330
331 Included on Linux if `/dev/kvm` is accessible.
332
333 - `nixos-test`, `benchmark`, `big-parallel`
334
335 These historical pseudo-features are always enabled for backwards compatibility, as they are used in Nixpkgs to route Hydra builds to specific machines.
336
337 - `ca-derivations`
338
339 Included by default if the [`ca-derivations` experimental feature](@docroot@/development/experimental-features.md#xp-feature-ca-derivations) is enabled.
340
341 This system feature is implicitly required by derivations with the [`__contentAddressed` attribute](@docroot@/language/advanced-attributes.md#adv-attr-__contentAddressed).
342
343 - `recursive-nix`
344
345 Included by default if the [`recursive-nix` experimental feature](@docroot@/development/experimental-features.md#xp-feature-recursive-nix) is enabled.
346
347 - `uid-range`
348
349 On Linux, Nix can run builds in a user namespace where they run as root (UID 0) and have 65,536 UIDs available.
350 This is primarily useful for running containers such as `systemd-nspawn` inside a Nix build. For an example, see [`tests/systemd-nspawn/nix`][nspawn].
351
352 [nspawn]: https://github.com/NixOS/nix/blob/67bcb99700a0da1395fa063d7c6586740b304598/tests/systemd-nspawn.nix
353
354 Included by default on Linux if the [`auto-allocate-uids`](#conf-auto-allocate-uids) setting is enabled.
355 )",
356 {},
357 // Don't document the machine-specific default value
358 false};
359
360 // move to daemonsettings in another pass
361 //
362 // we'll add a another parameter to processConnection to thread it through
363 Setting<std::set<StoreReference>> trustedSubstituters{
364 this,
365 {},
366 "trusted-substituters",
367 R"(
368 A list of [Nix store URLs](@docroot@/store/types/index.md#store-url-format), separated by whitespace.
369 These are not used by default, but users of the Nix daemon can enable them by specifying [`substituters`](#conf-substituters).
370
371 Unprivileged users (those set in only [`allowed-users`](#conf-allowed-users) but not [`trusted-users`](#conf-trusted-users)) can pass as `substituters` only those URLs listed in `trusted-substituters`.
372 )",
373 {"trusted-binary-caches"}};
374
375 // move it out in the 2nd pass
376 Setting<bool> printMissing{
377 this, true, "print-missing", "Whether to print what paths need to be built or downloaded."};
378
379 Setting<bool> useXDGBaseDirectories{
380 this,
381 false,
382 "use-xdg-base-directories",
383 R"(
384 If set to `true`, Nix conforms to the [XDG Base Directory Specification] for files in `$HOME`.
385 The environment variables used to implement this are documented in the [Environment Variables section](@docroot@/command-ref/env-common.md).
386
387 [XDG Base Directory Specification]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
388
389 > **Warning**
390 > This changes the location of some well-known symlinks that Nix creates, which might break tools that rely on the old, non-XDG-conformant locations.
391
392 In particular, the following locations change:
393
394 | Old | New |
395 |-------------------|--------------------------------|
396 | `~/.nix-profile` | `$XDG_STATE_HOME/nix/profile` |
397 | `~/.nix-defexpr` | `$XDG_STATE_HOME/nix/defexpr` |
398 | `~/.nix-channels` | `$XDG_STATE_HOME/nix/channels` |
399
400 If you already have Nix installed and are using [profiles](@docroot@/package-management/profiles.md) or [channels](@docroot@/command-ref/nix-channel.md), you should migrate manually when you enable this option.
401 If `$XDG_STATE_HOME` is not set, use `$HOME/.local/state/nix` instead of `$XDG_STATE_HOME/nix`.
402 This can be achieved with the following shell commands:
403
404 ```sh
405 nix_state_home=${XDG_STATE_HOME-$HOME/.local/state}/nix
406 mkdir -p $nix_state_home
407 mv $HOME/.nix-profile $nix_state_home/profile
408 mv $HOME/.nix-defexpr $nix_state_home/defexpr
409 mv $HOME/.nix-channels $nix_state_home/channels
410 ```
411 )"};
412
413 Setting<uint64_t> warnLargePathThreshold{
414 this,
415 0,
416 "warn-large-path-threshold",
417 R"(
418 Warn when copying a path larger than this number of bytes to the Nix store
419 (as determined by its NAR serialisation).
420 Default is 0, which disables the warning.
421 Set it to 1 to warn on all paths.
422 )"};
423
427 ProfileDirsOptions getProfileDirsOptions() const;
428};
429
430// FIXME: don't use a global variable.
431extern nix::Settings settings;
432
439void loadConfFile(AbstractConfig & config);
440
449extern std::string nixVersion;
450
455void initLibStore(bool loadConfig = true);
456
462void assertLibStoreInitialized();
463
464} // namespace nix
Definition configuration.hh:54
Definition configuration.hh:476
WorkerSettings & getWorkerSettings()
Definition globals.hh:149
LocalSettings & getLocalSettings()
Definition globals.hh:123
std::filesystem::path nixStateDir
Definition globals.hh:177
bool verboseBuild
Definition globals.hh:203
ProfileDirsOptions getProfileDirsOptions() const
Definition globals.cc:292
bool readOnlyMode
Definition globals.hh:209
NarInfoDiskCacheSettings & getNarInfoDiskCacheSettings()
Definition globals.hh:162
LogFileSettings & getLogFileSettings()
Definition globals.hh:136
Definition local-settings.hh:179
Definition globals.hh:21
Definition globals.hh:51
Definition worker-settings.hh:27
std::set< std::string, std::less<> > StringSet
Definition types.hh:45