Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
worker-settings.hh
Go to the documentation of this file.
1#pragma once
3
7
8namespace nix {
9
10struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
11{
12 MaxBuildJobsSetting(
13 Config * options,
14 unsigned int def,
15 const std::string & name,
16 const std::string & description,
17 const StringSet & aliases = {})
18 : BaseSetting<unsigned int>(def, true, name, description, aliases)
19 {
20 options->addSetting(this);
21 }
22
23 unsigned int parse(const std::string & str) const override;
24};
25
26struct WorkerSettings : public virtual Config
27{
28private:
29 void anchor() override;
30
31protected:
32 WorkerSettings() = default;
33
34public:
35 Setting<bool> keepGoing{
36 this, false, "keep-going", "Whether to keep building derivations when another build fails."};
37
38 Setting<bool> tryFallback{
39 this,
40 false,
41 "fallback",
42 R"(
43 If set to `true`, Nix falls back to building from source if a
44 binary substitute fails. This is equivalent to the `--fallback`
45 flag. The default is `false`.
46 )",
47 {"build-fallback"}};
48
49 Setting<size_t> logLines{
50 this,
51 25,
52 "log-lines",
53 "The number of lines of the tail of "
54 "the log to show if a build fails."};
55
56 MaxBuildJobsSetting maxBuildJobs{
57 this,
58 1,
59 "max-jobs",
60 R"(
61 Maximum number of jobs that Nix tries to build locally in parallel.
62
63 The special value `auto` causes Nix to use the number of CPUs in your system.
64 Use `0` to disable local builds and directly use the remote machines specified in [`builders`](#conf-builders).
65 This doesn't affect derivations that have [`preferLocalBuild = true`](@docroot@/language/advanced-attributes.md#adv-attr-preferLocalBuild), which are always built locally.
66
67 > **Note**
68 >
69 > The number of CPU cores to use for each build job is independently determined by the [`cores`](#conf-cores) setting.
70
71 <!-- TODO(@fricklerhandwerk): would be good to have those shorthands for common options as part of the specification -->
72 The setting can be overridden using the `--max-jobs` (`-j`) command line switch.
73 )",
74 {"build-max-jobs"}};
75
76 Setting<unsigned int> maxSubstitutionJobs{
77 this,
78 16,
79 "max-substitution-jobs",
80 R"(
81 This option defines the maximum number of substitution jobs that Nix
82 tries to run in parallel. The default is `16`. The minimum value
83 one can choose is `1` and lower values are interpreted as `1`.
84 )",
85 {"substitution-max-jobs"}};
86
87 Setting<time_t> maxSilentTime{
88 this,
89 0,
90 "max-silent-time",
91 R"(
92 This option defines the maximum number of seconds that a builder can
93 go without producing any data on standard output or standard error.
94 This is useful (for instance in an automated build system) to catch
95 builds that are stuck in an infinite loop, or to catch remote builds
96 that are hanging due to network problems. It can be overridden using
97 the `--max-silent-time` command line switch.
98
99 The value `0` means that there is no timeout. This is also the
100 default.
101 )",
102 {"build-max-silent-time"}};
103
104 Setting<time_t> buildTimeout{
105 this,
106 0,
107 "timeout",
108 R"(
109 This option defines the maximum number of seconds that a builder can
110 run. This is useful (for instance in an automated build system) to
111 catch builds that are stuck in an infinite loop but keep writing to
112 their standard output or standard error. It can be overridden using
113 the `--timeout` command line switch.
114
115 The value `0` means that there is no timeout. This is also the
116 default.
117 )",
118 {"build-timeout"}};
119
120 Setting<Strings> buildHook{
121 this,
122 {"nix", "__build-remote"},
123 "build-hook",
124 R"(
125 The path to the helper program that executes remote builds.
126
127 Nix communicates with the build hook over `stdio` using a custom protocol to request builds that cannot be performed directly by the Nix daemon.
128 The default value is the internal Nix binary that implements remote building.
129
130 > **Important**
131 >
132 > Change this setting only if you really know what you’re doing.
133 )"};
134
135 Setting<uint32_t> buildHookKillTimeout{
136 this,
137 500,
138 "build-hook-kill-timeout",
139 "How long to wait in milliseconds for build hooks to exit on interrupt before sending SIGKILL."};
140
141 Setting<std::string> builders{
142 this,
143 "@" + (nixConfDir() / "machines").string(),
144 "builders",
145 R"(
146 A semicolon- or newline-separated list of build machines.
147
148 In addition to the [usual ways of setting configuration options](@docroot@/command-ref/conf-file.md), the value can be read from a file by prefixing its absolute path with `@`.
149
150 > **Example**
151 >
152 > This is the default setting:
153 >
154 > ```
155 > builders = @/etc/nix/machines
156 > ```
157
158 Each machine specification consists of the following elements, separated by spaces.
159 Only the first element is required.
160 To leave a field at its default, set it to `-`.
161
162 1. The URI of the remote store in the format `ssh://[username@]hostname[:port]`.
163
164 > **Example**
165 >
166 > `ssh://nix@mac`
167
168 For backward compatibility, `ssh://` may be omitted.
169 The hostname may be an alias defined in `~/.ssh/config`.
170
171 2. A comma-separated list of [Nix system types](@docroot@/development/building.md#system-type).
172 If omitted, this defaults to the local platform type.
173
174 > **Example**
175 >
176 > `aarch64-darwin`
177
178 It is possible for a machine to support multiple platform types.
179
180 > **Example**
181 >
182 > `i686-linux,x86_64-linux`
183
184 3. The SSH identity file to be used to log in to the remote machine.
185 If omitted, SSH uses its regular identities.
186
187 > **Example**
188 >
189 > `/home/user/.ssh/id_mac`
190
191 4. The maximum number of builds that Nix executes in parallel on the machine.
192 Typically this should be equal to the number of CPU cores.
193
194 5. The “speed factor”, indicating the relative speed of the machine as a positive integer or decimal number.
195 If there are multiple machines of the right type, Nix prefers the fastest, taking load into account.
196
197 6. A comma-separated list of supported [system features](#conf-system-features).
198
199 A machine is only used to build a derivation if all the features in the derivation's [`requiredSystemFeatures`](@docroot@/language/advanced-attributes.html#adv-attr-requiredSystemFeatures) attribute are supported by that machine.
200
201 7. A comma-separated list of required [system features](#conf-system-features).
202
203 A machine is only used to build a derivation if all of the machine’s required features appear in the derivation’s [`requiredSystemFeatures`](@docroot@/language/advanced-attributes.html#adv-attr-requiredSystemFeatures) attribute.
204
205 8. The (base64-encoded) public host key of the remote machine.
206 If omitted, SSH uses its regular `known_hosts` file.
207
208 The value for this field can be obtained via `base64 -w0`.
209
210 > **Example**
211 >
212 > Multiple builders specified on the command line:
213 >
214 > ```console
215 > --builders 'ssh://mac aarch64-darwin ; ssh://beastie x86_64-freebsd'
216 > ```
217
218 > **Example**
219 >
220 > This specifies several machines that can perform `i686-linux` builds:
221 >
222 > ```
223 > nix@scratchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy 8 1 kvm
224 > nix@itchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy 8 2
225 > nix@poochie.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy 1 2 kvm benchmark
226 > ```
227 >
228 > However, `poochie` only builds derivations that have the attribute
229 >
230 > ```nix
231 > requiredSystemFeatures = [ "benchmark" ];
232 > ```
233 >
234 > or
235 >
236 > ```nix
237 > requiredSystemFeatures = [ "benchmark" "kvm" ];
238 > ```
239 >
240 > `itchy` cannot do builds that require `kvm`, but `scratchy` does support such builds.
241 > For regular builds, `itchy` is preferred over `scratchy` because it has a higher speed factor.
242
243 For Nix to use substituters, the calling user must be in the [`trusted-users`](#conf-trusted-users) list.
244
245 > **Note**
246 >
247 > A build machine must be accessible via SSH and have Nix installed.
248 > `nix` must be available in `$PATH` for the user connecting over SSH.
249
250 > **Warning**
251 >
252 > If you are building via the Nix daemon (default), the Nix daemon user account on the local machine (that is, `root`) requires access to a user account on the remote machine (not necessarily `root`).
253 >
254 > If you can’t or don’t want to configure `root` to be able to access the remote machine, set [`store`](#conf-store) to any [local store](@docroot@/store/types/local-store.html), e.g. by passing `--store /tmp` to the command on the local machine.
255
256 To build only on remote machines and disable local builds, set [`max-jobs`](#conf-max-jobs) to 0.
257
258 If you want the remote machines to use substituters, set [`builders-use-substitutes`](#conf-builders-use-substitutes) to `true`.
259 )",
260 {},
261 false};
262
263 Setting<bool> alwaysAllowSubstitutes{
264 this,
265 false,
266 "always-allow-substitutes",
267 R"(
268 If set to `true`, Nix ignores the [`allowSubstitutes`](@docroot@/language/advanced-attributes.md) attribute in derivations and always attempt to use [available substituters](#conf-substituters).
269 )"};
270
271 Setting<bool> buildersUseSubstitutes{
272 this,
273 false,
274 "builders-use-substitutes",
275 R"(
276 If set to `true`, Nix instructs [remote build machines](#conf-builders) to use their own [`substituters`](#conf-substituters) if available.
277
278 It means that remote build hosts fetch as many dependencies as possible from their own substituters (e.g, from `cache.nixos.org`) instead of waiting for the local machine to upload them all.
279 This can drastically reduce build times if the network connection between the local machine and the remote build host is slow.
280 )"};
281
282 Setting<bool> useSubstitutes{
283 this,
284 true,
285 "substitute",
286 R"(
287 If set to `true` (default), Nix uses binary substitutes if
288 available. This option can be disabled to force building from
289 source.
290 )",
291 {"build-use-substitutes"}};
292
294 this,
295 std::vector<StoreReference>{StoreReference::parse("https://cache.nixos.org/")},
296 "substituters",
297 R"(
298 A list of [URLs of Nix stores](@docroot@/store/types/index.md#store-url-format) to be used as substituters, separated by whitespace.
299 A substituter is an additional [store](@docroot@/glossary.md#gloss-store) from which Nix can obtain [store objects](@docroot@/store/store-object.md) instead of building them.
300
301 Substituters are tried based on their priority value, which each substituter can set independently.
302 Lower value means higher priority.
303 The default is `https://cache.nixos.org`, which has a priority of 40.
304
305 At least one of the following conditions must be met for Nix to use a substituter:
306
307 - The substituter is in the [`trusted-substituters`](#conf-trusted-substituters) list
308 - The user calling Nix is in the [`trusted-users`](#conf-trusted-users) list
309
310 In addition, each store path should be trusted as described in [`trusted-public-keys`](#conf-trusted-public-keys)
311 )",
312 {"binary-caches"}};
313
314 Setting<unsigned long> maxLogSize{
315 this,
316 0,
317 "max-build-log-size",
318 R"(
319 This option defines the maximum number of bytes that a builder can
320 write to its stdout/stderr. If the builder exceeds this limit, it's
321 killed. A value of `0` (the default) means that there is no limit.
322 )",
323 {"build-max-log-size"}};
324
325 Setting<unsigned int> pollInterval{this, 5, "build-poll-interval", "How often (in seconds) to poll for locks."};
326
327 Setting<std::string> postBuildHook{
328 this,
329 "",
330 "post-build-hook",
331 R"(
332 Optional. The path to a program to execute after each build.
333
334 This option is only settable in the global `nix.conf`, or on the
335 command line by trusted users.
336
337 When using the nix-daemon, the daemon executes the hook as `root`.
338 If the nix-daemon is not involved, the hook runs as the user
339 executing the nix-build.
340
341 - The hook executes after an evaluation-time build.
342
343 - The hook does not execute on substituted paths.
344
345 - The hook's output always goes to the user's terminal.
346
347 - If the hook fails, the build succeeds but no further builds
348 execute.
349
350 - The hook executes synchronously, and blocks other builds from
351 progressing while it runs.
352
353 The program executes with no arguments. The program's environment
354 contains the following environment variables:
355
356 - `DRV_PATH`
357 The derivation for the built paths.
358
359 Example:
360 `/nix/store/5nihn1a7pa8b25l9zafqaqibznlvvp3f-bash-4.4-p23.drv`
361
362 - `OUT_PATHS`
363 Output paths of the built derivation, separated by a space
364 character.
365
366 Example:
367 `/nix/store/l88brggg9hpy96ijds34dlq4n8fan63g-bash-4.4-p23-dev
368 /nix/store/vch71bhyi5akr5zs40k8h2wqxx69j80l-bash-4.4-p23-doc
369 /nix/store/c5cxjywi66iwn9dcx5yvwjkvl559ay6p-bash-4.4-p23-info
370 /nix/store/scz72lskj03ihkcn42ias5mlp4i4gr1k-bash-4.4-p23-man
371 /nix/store/a724znygmd1cac856j3gfsyvih3lw07j-bash-4.4-p23`.
372 )"};
373};
374
375} // namespace nix
Definition configuration.hh:147
Definition configuration.hh:476
Definition worker-settings.hh:11
std::set< std::string, std::less<> > StringSet
Definition types.hh:45