Skip to content

Commit fd82ba0

Browse files
extract reference documentation on remote builds (#9526)
- move all reference documentation to the `builders` configuration setting - reword documentation on machine specification, add examples - disable showing the default value, as it rendered as `@/dummy/machines`, which is wrong - highlight the examples - link to the configuration docs for distributed builds - builder -> build machine Co-authored-by: Janik H <[email protected]>
1 parent e37d502 commit fd82ba0

File tree

9 files changed

+152
-111
lines changed

9 files changed

+152
-111
lines changed

doc/manual/redirects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const redirects = {
1818
"chap-tuning-cores-and-jobs": "advanced-topics/cores-vs-jobs.html",
1919
"chap-diff-hook": "advanced-topics/diff-hook.html",
2020
"check-dirs-are-unregistered": "advanced-topics/diff-hook.html#check-dirs-are-unregistered",
21-
"chap-distributed-builds": "advanced-topics/distributed-builds.html",
21+
"chap-distributed-builds": "command-ref/conf-file.html#conf-builders",
2222
"chap-post-build-hook": "advanced-topics/post-build-hook.html",
2323
"chap-post-build-hook-caveats": "advanced-topics/post-build-hook.html#implementation-caveats",
2424
"chap-writing-nix-expressions": "language/index.html",

doc/manual/src/advanced-topics/distributed-builds.md

+8-93
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,8 @@ error: cannot connect to 'mac'
3636
then you need to ensure that the `PATH` of non-interactive login shells
3737
contains Nix.
3838

39-
> **Warning**
40-
>
41-
> If you are building via the Nix daemon, it is the Nix daemon user account (that is, `root`) that should have SSH access to a user (not necessarily `root`) on the remote machine.
42-
>
43-
> If you can’t or don’t want to configure `root` to be able to access the remote machine, you can use a private Nix store instead by passing e.g. `--store ~/my-nix` when running a Nix command from the local machine.
44-
45-
The list of remote machines can be specified on the command line or in
46-
the Nix configuration file. The former is convenient for testing. For
47-
example, the following command allows you to build a derivation for
48-
`x86_64-darwin` on a Linux machine:
39+
The [list of remote build machines](@docroot@/command-ref/conf-file.md#conf-builders) can be specified on the command line or in the Nix configuration file.
40+
For example, the following command allows you to build a derivation for `x86_64-darwin` on a Linux machine:
4941

5042
```console
5143
$ uname
@@ -60,97 +52,20 @@ $ cat ./result
6052
Darwin
6153
```
6254

63-
It is possible to specify multiple builders separated by a semicolon or
64-
a newline, e.g.
55+
It is possible to specify multiple build machines separated by a semicolon or a newline, e.g.
6556

6657
```console
6758
--builders 'ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd'
6859
```
6960

70-
Each machine specification consists of the following elements, separated
71-
by spaces. Only the first element is required. To leave a field at its
72-
default, set it to `-`.
73-
74-
1. The URI of the remote store in the format
75-
`ssh://[username@]hostname`, e.g. `ssh://nix@mac` or `ssh://mac`.
76-
For backward compatibility, `ssh://` may be omitted. The hostname
77-
may be an alias defined in your `~/.ssh/config`.
78-
79-
2. A comma-separated list of Nix platform type identifiers, such as
80-
`x86_64-darwin`. It is possible for a machine to support multiple
81-
platform types, e.g., `i686-linux,x86_64-linux`. If omitted, this
82-
defaults to the local platform type.
83-
84-
3. The SSH identity file to be used to log in to the remote machine. If
85-
omitted, SSH will use its regular identities.
86-
87-
4. The maximum number of builds that Nix will execute in parallel on
88-
the machine. Typically this should be equal to the number of CPU
89-
cores. For instance, the machine `itchy` in the example will execute
90-
up to 8 builds in parallel.
91-
92-
5. The “speed factor”, indicating the relative speed of the machine. If
93-
there are multiple machines of the right type, Nix will prefer the
94-
fastest, taking load into account.
95-
96-
6. A comma-separated list of *supported features*. If a derivation has
97-
the `requiredSystemFeatures` attribute, then Nix will only perform
98-
the derivation on a machine that has the specified features. For
99-
instance, the attribute
100-
101-
```nix
102-
requiredSystemFeatures = [ "kvm" ];
103-
```
104-
105-
will cause the build to be performed on a machine that has the `kvm`
106-
feature.
107-
108-
7. A comma-separated list of *mandatory features*. A machine will only
109-
be used to build a derivation if all of the machine’s mandatory
110-
features appear in the derivation’s `requiredSystemFeatures`
111-
attribute.
112-
113-
8. The (base64-encoded) public host key of the remote machine. If omitted, SSH
114-
will use its regular known-hosts file. Specifically, the field is calculated
115-
via `base64 -w0 /etc/ssh/ssh_host_ed25519_key.pub`.
116-
117-
For example, the machine specification
118-
119-
[email protected] i686-linux /home/nix/.ssh/id_scratchy_auto 8 1 kvm
120-
[email protected] i686-linux /home/nix/.ssh/id_scratchy_auto 8 2
121-
[email protected] i686-linux /home/nix/.ssh/id_scratchy_auto 1 2 kvm benchmark
122-
123-
specifies several machines that can perform `i686-linux` builds.
124-
However, `poochie` will only do builds that have the attribute
125-
126-
```nix
127-
requiredSystemFeatures = [ "benchmark" ];
128-
```
129-
130-
or
131-
132-
```nix
133-
requiredSystemFeatures = [ "benchmark" "kvm" ];
134-
```
135-
136-
`itchy` cannot do builds that require `kvm`, but `scratchy` does support
137-
such builds. For regular builds, `itchy` will be preferred over
138-
`scratchy` because it has a higher speed factor.
139-
140-
Remote builders can also be configured in `nix.conf`, e.g.
61+
Remote build machines can also be configured in [`nix.conf`](@docroot@/command-ref/conf-file.md), e.g.
14162

14263
builders = ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd
14364

144-
Finally, remote builders can be configured in a separate configuration
145-
file included in `builders` via the syntax `@file`. For example,
65+
Finally, remote build machines can be configured in a separate configuration
66+
file included in `builders` via the syntax `@/path/to/file`. For example,
14667

14768
builders = @/etc/nix/machines
14869

149-
causes the list of machines in `/etc/nix/machines` to be included. (This
150-
is the default.)
151-
152-
If you want the builders to use caches, you likely want to set the
153-
option `builders-use-substitutes` in your local `nix.conf`.
154-
155-
To build only on remote builders and disable building on the local
156-
machine, you can use the option `--max-jobs 0`.
70+
causes the list of machines in `/etc/nix/machines` to be included.
71+
(This is the default.)

doc/manual/src/contributing/hacking.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ Nix can be built for various platforms, as specified in [`flake.nix`]:
147147

148148
In order to build Nix for a different platform than the one you're currently
149149
on, you need a way for your current Nix installation to build code for that
150-
platform. Common solutions include [remote builders] and [binary format emulation]
150+
platform. Common solutions include [remote build machines] and [binary format emulation]
151151
(only supported on NixOS).
152152

153-
[remote builders]: ../advanced-topics/distributed-builds.md
153+
[remote builders]: @docroot@/language/derivations.md#attr-builder
154154
[binary format emulation]: https://nixos.org/manual/nixos/stable/options.html#opt-boot.binfmt.emulatedSystems
155155

156156
Given such a setup, executing the build only requires selecting the respective attribute.

doc/manual/src/glossary.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
This can be achieved by:
3838
- Fetching a pre-built [store object] from a [substituter]
3939
- Running the [`builder`](@docroot@/language/derivations.md#attr-builder) executable as specified in the corresponding [derivation]
40-
- Delegating to a [remote builder](@docroot@/advanced-topics/distributed-builds.html) and retrieving the outputs
40+
- Delegating to a [remote machine](@docroot@/command-ref/conf-file.md#conf-builders) and retrieving the outputs
4141
<!-- TODO: link [running] to build process page, #8888 -->
4242

4343
See [`nix-store --realise`](@docroot@/command-ref/nix-store/realise.md) for a detailed description of the algorithm.

doc/manual/src/language/advanced-attributes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Derivations can declare some infrequently used optional attributes.
257257
of the environment (typically, a few hundred kilobyte).
258258
259259
- [`preferLocalBuild`]{#adv-attr-preferLocalBuild}\
260-
If this attribute is set to `true` and [distributed building is enabled](../advanced-topics/distributed-builds.md), then, if possible, the derivation will be built locally instead of being forwarded to a remote machine.
260+
If this attribute is set to `true` and [distributed building is enabled](@docroot@/command-ref/conf-file.md#conf-builders), then, if possible, the derivation will be built locally instead of being forwarded to a remote machine.
261261
This is useful for derivations that are cheapest to build locally.
262262
263263
- [`allowSubstitutes`]{#adv-attr-allowSubstitutes}\

doc/manual/src/language/derivations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ It outputs an attribute set, and produces a [store derivation] as a side effect
3636
The system type on which the [`builder`](#attr-builder) executable is meant to be run.
3737
3838
A necessary condition for Nix to build derivations locally is that the `system` attribute matches the current [`system` configuration option].
39-
It can automatically [build on other platforms](../advanced-topics/distributed-builds.md) by forwarding build requests to other machines.
39+
It can automatically [build on other platforms](@docroot@/language/derivations.md#attr-builder) by forwarding build requests to other machines.
4040
4141
[`system` configuration option]: @docroot@/command-ref/conf-file.md#conf-system
4242

src/libstore/build/derivation-goal.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,13 @@ void DerivationGoal::tryToBuild()
780780

781781
void DerivationGoal::tryLocalBuild() {
782782
throw Error(
783-
"unable to build with a primary store that isn't a local store; "
784-
"either pass a different '--store' or enable remote builds."
785-
"\nhttps://nixos.org/manual/nix/stable/advanced-topics/distributed-builds.html");
783+
R"(
784+
Unable to build with a primary store that isn't a local store;
785+
either pass a different '--store' or enable remote builds.
786+
787+
For more information check 'man nix.conf' and search for '/machines'.
788+
)"
789+
);
786790
}
787791

788792

src/libstore/build/worker.cc

+16-6
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,23 @@ void Worker::run(const Goals & _topGoals)
331331
if (awake.empty() && 0U == settings.maxBuildJobs)
332332
{
333333
if (getMachines().empty())
334-
throw Error("unable to start any build; either increase '--max-jobs' "
335-
"or enable remote builds."
336-
"\nhttps://nixos.org/manual/nix/stable/advanced-topics/distributed-builds.html");
334+
throw Error(
335+
R"(
336+
Unable to start any build;
337+
either increase '--max-jobs' or enable remote builds.
338+
339+
For more information run 'man nix.conf' and search for '/machines'.
340+
)"
341+
);
337342
else
338-
throw Error("unable to start any build; remote machines may not have "
339-
"all required system features."
340-
"\nhttps://nixos.org/manual/nix/stable/advanced-topics/distributed-builds.html");
343+
throw Error(
344+
R"(
345+
Unable to start any build;
346+
remote machines may not have all required system features.
347+
348+
For more information run 'man nix.conf' and search for '/machines'.
349+
)"
350+
);
341351

342352
}
343353
assert(!awake.empty());

src/libstore/globals.hh

+115-3
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,121 @@ public:
270270
Setting<std::string> builders{
271271
this, "@" + nixConfDir + "/machines", "builders",
272272
R"(
273-
A semicolon-separated list of build machines.
274-
For the exact format and examples, see [the manual chapter on remote builds](../advanced-topics/distributed-builds.md)
275-
)"};
273+
A semicolon- or newline-separated list of build machines.
274+
275+
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 `@`.
276+
277+
> **Example**
278+
>
279+
> This is the default setting:
280+
>
281+
> ```
282+
> builders = @/etc/nix/machines
283+
> ```
284+
285+
Each machine specification consists of the following elements, separated by spaces.
286+
Only the first element is required.
287+
To leave a field at its default, set it to `-`.
288+
289+
1. The URI of the remote store in the format `ssh://[username@]hostname`.
290+
291+
> **Example**
292+
>
293+
> `ssh://nix@mac`
294+
295+
For backward compatibility, `ssh://` may be omitted.
296+
The hostname may be an alias defined in `~/.ssh/config`.
297+
298+
2. A comma-separated list of [Nix system types](@docroot@/contributing/hacking.md#system-type).
299+
If omitted, this defaults to the local platform type.
300+
301+
> **Example**
302+
>
303+
> `aarch64-darwin`
304+
305+
It is possible for a machine to support multiple platform types.
306+
307+
> **Example**
308+
>
309+
> `i686-linux,x86_64-linux`
310+
311+
3. The SSH identity file to be used to log in to the remote machine.
312+
If omitted, SSH will use its regular identities.
313+
314+
> **Example**
315+
>
316+
> `/home/user/.ssh/id_mac`
317+
318+
4. The maximum number of builds that Nix will execute in parallel on the machine.
319+
Typically this should be equal to the number of CPU cores.
320+
321+
5. The “speed factor”, indicating the relative speed of the machine as a positive integer.
322+
If there are multiple machines of the right type, Nix will prefer the fastest, taking load into account.
323+
324+
6. A comma-separated list of supported [system features](#conf-system-features).
325+
326+
A machine will only be 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.
327+
328+
7. A comma-separated list of required [system features](#conf-system-features).
329+
330+
A machine will only be 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.
331+
332+
8. The (base64-encoded) public host key of the remote machine.
333+
If omitted, SSH will use its regular `known_hosts` file.
334+
335+
The value for this field can be obtained via `base64 -w0`.
336+
337+
> **Example**
338+
>
339+
> Multiple builders specified on the command line:
340+
>
341+
> ```console
342+
> --builders 'ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd'
343+
> ```
344+
345+
> **Example**
346+
>
347+
> This specifies several machines that can perform `i686-linux` builds:
348+
>
349+
> ```
350+
> [email protected] i686-linux /home/nix/.ssh/id_scratchy 8 1 kvm
351+
> [email protected] i686-linux /home/nix/.ssh/id_scratchy 8 2
352+
> [email protected] i686-linux /home/nix/.ssh/id_scratchy 1 2 kvm benchmark
353+
> ```
354+
>
355+
> However, `poochie` will only build derivations that have the attribute
356+
>
357+
> ```nix
358+
> requiredSystemFeatures = [ "benchmark" ];
359+
> ```
360+
>
361+
> or
362+
>
363+
> ```nix
364+
> requiredSystemFeatures = [ "benchmark" "kvm" ];
365+
> ```
366+
>
367+
> `itchy` cannot do builds that require `kvm`, but `scratchy` does support such builds.
368+
> For regular builds, `itchy` will be preferred over `scratchy` because it has a higher speed factor.
369+
370+
For Nix to use substituters, the calling user must be in the [`trusted-users`](#conf-trusted-users) list.
371+
372+
> **Note**
373+
>
374+
> A build machine must be accessible via SSH and have Nix installed.
375+
> `nix` must be available in `$PATH` for the user connecting over SSH.
376+
377+
> **Warning**
378+
>
379+
> 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`).
380+
>
381+
> 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.
382+
383+
To build only on remote machines and disable local builds, set [`max-jobs`](#conf-max-jobs) to 0.
384+
385+
If you want the remote machines to use substituters, set [`builders-use-substitutes`](#conf-builders-use-substituters) to `true`.
386+
)",
387+
{}, false};
276388

277389
Setting<bool> alwaysAllowSubstitutes{
278390
this, false, "always-allow-substitutes",

0 commit comments

Comments
 (0)