2 Manages the remote build configuration, /etc/nix/machines
6 - nixos/modules/services/system/nix-daemon.nix
28 nixPackage = cfg.package.out;
30 isNixAtLeast = versionAtLeast (getVersion nixPackage);
32 buildMachinesText = concatMapStrings (
34 (concatStringsSep " " (
36 "${optionalString (machine.protocol != null) "${machine.protocol}://"}${
37 optionalString (machine.sshUser != null) "${machine.sshUser}@"
40 if machine.system != null then
42 else if machine.systems != [ ] then
43 concatStringsSep "," machine.systems
47 (if machine.sshKey != null then machine.sshKey else "-")
48 (toString machine.maxJobs)
49 (toString machine.speedFactor)
52 res = (machine.supportedFeatures ++ machine.mandatoryFeatures);
54 if (res == [ ]) then "-" else (concatStringsSep "," res)
58 res = machine.mandatoryFeatures;
60 if (res == [ ]) then "-" else (concatStringsSep "," machine.mandatoryFeatures)
63 ++ optional (isNixAtLeast "2.4pre") (
64 if machine.publicHostKey != null then machine.publicHostKey else "-"
74 buildMachines = mkOption {
80 example = "nixbuilder.example.org";
82 The hostname of the build machine.
94 The protocol used for communicating with the build machine.
95 Use `ssh-ng` if your remote builder and your
96 local Nix version support that improved protocol.
98 Use `null` when trying to change the special localhost builder
99 without a protocol which is for example used by hydra.
103 type = types.nullOr types.str;
105 example = "x86_64-linux";
107 The system type the build machine can execute derivations on.
108 Either this attribute or {var}`systems` must be
109 present, where {var}`system` takes precedence if
114 type = types.listOf types.str;
121 The system types the build machine can execute derivations on.
122 Either this attribute or {var}`system` must be
123 present, where {var}`system` takes precedence if
128 type = types.nullOr types.str;
132 The username to log in as on the remote host. This user must be
133 able to log in and run nix commands non-interactively. It must
134 also be privileged to build derivations, so must be included in
135 {option}`nix.settings.trusted-users`.
139 type = types.nullOr types.str;
141 example = "/root/.ssh/id_buildhost_builduser";
143 The path to the SSH private key with which to authenticate on
144 the build machine. The private key must not have a passphrase.
145 If null, the building user (root on NixOS machines) must have an
146 appropriate ssh configuration to log in non-interactively.
148 Note that for security reasons, this path must point to a file
149 in the local filesystem, *not* to the nix store.
156 The number of concurrent jobs the build machine supports. The
157 build machine will enforce its own limits, but this allows hydra
158 to schedule better since there is no work-stealing between build
162 speedFactor = mkOption {
166 The relative speed of this builder. This is an arbitrary integer
167 that indicates the speed of this builder, relative to other
168 builders. Higher is faster.
171 mandatoryFeatures = mkOption {
172 type = types.listOf types.str;
174 example = [ "big-parallel" ];
176 A list of features mandatory for this builder. The builder will
177 be ignored for derivations that don't require all features in
178 this list. All mandatory features are automatically included in
179 {var}`supportedFeatures`.
182 supportedFeatures = mkOption {
183 type = types.listOf types.str;
190 A list of features supported by this builder. The builder will
191 be ignored for derivations that require features not in this
195 publicHostKey = mkOption {
196 type = types.nullOr types.str;
199 The (base64-encoded) public host key of this builder. The field
200 is calculated via {command}`base64 -w0 /etc/ssh/ssh_host_type_key.pub`.
201 If null, SSH will use its regular known-hosts file when connecting.
209 This option lists the machines to be used if distributed builds are
210 enabled (see {option}`nix.distributedBuilds`).
211 Nix will perform derivations on those machines via SSH by copying the
212 inputs to the Nix store on the remote machine, starting the build,
213 then copying the output back to the local Nix store.
217 distributedBuilds = mkOption {
221 Whether to distribute builds to the machines listed in
222 {option}`nix.buildMachines`.
228 # distributedBuilds does *not* inhibit /etc/nix/machines generation; caller may
229 # override that nix option.
230 config = mkIf cfg.enable {
233 badMachine = m: m.system == null && m.systems == [ ];
237 assertion = !(any badMachine cfg.buildMachines);
240 At least one system type (via <varname>system</varname> or
241 <varname>systems</varname>) must be set for every build machine.
242 Invalid machine specifications:
245 + (concatStringsSep "\n " (map (m: m.hostName) (filter (badMachine) cfg.buildMachines)));
249 # List of machines for distributed Nix builds
250 environment.etc."nix/machines" = mkIf (cfg.buildMachines != [ ]) {
251 text = buildMachinesText;
254 # Legacy configuration conversion.
255 nix.settings = mkIf (!cfg.distributedBuilds) { builders = null; };