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);
35 (concatStringsSep " " ([
36 "${optionalString (machine.protocol != null) "${machine.protocol}://"}${optionalString (machine.sshUser != null) "${machine.sshUser}@"}${machine.hostName}"
37 (if machine.system != null then machine.system else if machine.systems != [ ] then concatStringsSep "," machine.systems else "-")
38 (if machine.sshKey != null then machine.sshKey else "-")
39 (toString machine.maxJobs)
40 (toString machine.speedFactor)
41 (let res = (machine.supportedFeatures ++ machine.mandatoryFeatures);
42 in if (res == []) then "-" else (concatStringsSep "," res))
43 (let res = machine.mandatoryFeatures;
44 in if (res == []) then "-" else (concatStringsSep "," machine.mandatoryFeatures))
46 ++ optional (isNixAtLeast "2.4pre") (if machine.publicHostKey != null then machine.publicHostKey else "-")))
55 buildMachines = mkOption {
56 type = types.listOf (types.submodule {
60 example = "nixbuilder.example.org";
62 The hostname of the build machine.
66 type = types.enum [ null "ssh" "ssh-ng" ];
70 The protocol used for communicating with the build machine.
71 Use `ssh-ng` if your remote builder and your
72 local Nix version support that improved protocol.
74 Use `null` when trying to change the special localhost builder
75 without a protocol which is for example used by hydra.
79 type = types.nullOr types.str;
81 example = "x86_64-linux";
83 The system type the build machine can execute derivations on.
84 Either this attribute or {var}`systems` must be
85 present, where {var}`system` takes precedence if
90 type = types.listOf types.str;
92 example = [ "x86_64-linux" "aarch64-linux" ];
94 The system types the build machine can execute derivations on.
95 Either this attribute or {var}`system` must be
96 present, where {var}`system` takes precedence if
101 type = types.nullOr types.str;
105 The username to log in as on the remote host. This user must be
106 able to log in and run nix commands non-interactively. It must
107 also be privileged to build derivations, so must be included in
108 {option}`nix.settings.trusted-users`.
112 type = types.nullOr types.str;
114 example = "/root/.ssh/id_buildhost_builduser";
116 The path to the SSH private key with which to authenticate on
117 the build machine. The private key must not have a passphrase.
118 If null, the building user (root on NixOS machines) must have an
119 appropriate ssh configuration to log in non-interactively.
121 Note that for security reasons, this path must point to a file
122 in the local filesystem, *not* to the nix store.
129 The number of concurrent jobs the build machine supports. The
130 build machine will enforce its own limits, but this allows hydra
131 to schedule better since there is no work-stealing between build
135 speedFactor = mkOption {
139 The relative speed of this builder. This is an arbitrary integer
140 that indicates the speed of this builder, relative to other
141 builders. Higher is faster.
144 mandatoryFeatures = mkOption {
145 type = types.listOf types.str;
147 example = [ "big-parallel" ];
149 A list of features mandatory for this builder. The builder will
150 be ignored for derivations that don't require all features in
151 this list. All mandatory features are automatically included in
152 {var}`supportedFeatures`.
155 supportedFeatures = mkOption {
156 type = types.listOf types.str;
158 example = [ "kvm" "big-parallel" ];
160 A list of features supported by this builder. The builder will
161 be ignored for derivations that require features not in this
165 publicHostKey = mkOption {
166 type = types.nullOr types.str;
169 The (base64-encoded) public host key of this builder. The field
170 is calculated via {command}`base64 -w0 /etc/ssh/ssh_host_type_key.pub`.
171 If null, SSH will use its regular known-hosts file when connecting.
178 This option lists the machines to be used if distributed builds are
179 enabled (see {option}`nix.distributedBuilds`).
180 Nix will perform derivations on those machines via SSH by copying the
181 inputs to the Nix store on the remote machine, starting the build,
182 then copying the output back to the local Nix store.
186 distributedBuilds = mkOption {
190 Whether to distribute builds to the machines listed in
191 {option}`nix.buildMachines`.
197 # distributedBuilds does *not* inhibit /etc/machines generation; caller may
198 # override that nix option.
199 config = mkIf cfg.enable {
201 let badMachine = m: m.system == null && m.systems == [ ];
205 assertion = !(any badMachine cfg.buildMachines);
207 At least one system type (via <varname>system</varname> or
208 <varname>systems</varname>) must be set for every build machine.
209 Invalid machine specifications:
211 (concatStringsSep "\n "
213 (filter (badMachine) cfg.buildMachines)));
217 # List of machines for distributed Nix builds
218 environment.etc."nix/machines" =
219 mkIf (cfg.buildMachines != [ ]) {
220 text = buildMachinesText;
223 # Legacy configuration conversion.
224 nix.settings = mkIf (!cfg.distributedBuilds) { builders = null; };