1 # darwin.linux-builder {#sec-darwin-builder}
4 By default, `darwin.linux-builder` uses a publicly-known private SSH **host key** (this is different from the SSH key used by the user that connects to the builder).
6 Given the intended use case for it (a Linux builder that runs **on the same machine**), this shouldn't be an issue.
7 However, if you plan to deviate from this use case in any way (e.g. by exposing this builder to remote machines), you should understand the security implications of doing so and take any appropriate measures.
10 `darwin.linux-builder` provides a way to bootstrap a Linux remote builder on a macOS machine.
12 This requires macOS version 12.4 or later.
14 The remote builder runs on host port 31022 by default.
15 You can change it by overriding `virtualisation.darwin-builder.hostPort`.
16 See the [example](#sec-darwin-builder-example-flake).
18 You will also need to be a trusted user for your Nix installation. In other
19 words, your `/etc/nix/nix.conf` should have something like:
22 extra-trusted-users = <your username goes here>
25 To launch the remote builder, run the following flake:
28 $ nix run nixpkgs#darwin.linux-builder
31 That will prompt you to enter your `sudo` password:
34 + sudo --reset-timestamp /nix/store/…-install-credentials.sh ./keys
38 … so that it can install a private key used to `ssh` into the build server.
39 After that the script will launch the virtual machine and automatically log you
40 in as the `builder` user:
43 <<< Welcome to NixOS 22.11.20220901.1bd8d11 (aarch64) - ttyAMA0 >>>
45 Run 'nixos-help' for the NixOS manual.
47 nixos login: builder (automatic login)
53 > Note: When you need to stop the VM, run `shutdown now` as the `builder` user.
55 To delegate builds to the remote builder, add the following options to your
59 # - Replace ${ARCH} with either aarch64 or x86_64 to match your host machine
60 # - Replace ${MAX_JOBS} with the maximum number of builds (pick 4 if you're not sure)
61 builders = ssh-ng://builder@linux-builder ${ARCH}-linux /etc/nix/builder_ed25519 ${MAX_JOBS} - - - c3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSUpCV2N4Yi9CbGFxdDFhdU90RStGOFFVV3JVb3RpQzVxQkorVXVFV2RWQ2Igcm9vdEBuaXhvcwo=
63 # Not strictly necessary, but this will reduce your disk utilization
64 builders-use-substitutes = true
67 To allow Nix to connect to a remote builder not running on port 22, you will also need to create a new file at `/etc/ssh/ssh_config.d/100-linux-builder.conf`:
72 HostKeyAlias linux-builder
76 … and then restart your Nix daemon to apply the change:
79 $ sudo launchctl kickstart -k system/org.nixos.nix-daemon
82 ## Example flake usage {#sec-darwin-builder-example-flake}
87 nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-22.11-darwin";
88 darwin.url = "github:lnl7/nix-darwin/master";
89 darwin.inputs.nixpkgs.follows = "nixpkgs";
92 outputs = { self, darwin, nixpkgs, ... }@inputs:
95 inherit (darwin.lib) darwinSystem;
96 system = "aarch64-darwin";
97 pkgs = nixpkgs.legacyPackages."${system}";
98 linuxSystem = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;
100 darwin-builder = nixpkgs.lib.nixosSystem {
101 system = linuxSystem;
103 "${nixpkgs}/nixos/modules/profiles/macos-builder.nix"
106 darwin-builder.workingDirectory = "/var/lib/darwin-builder";
107 darwin-builder.hostPort = 22;
114 darwinConfigurations = {
115 machine1 = darwinSystem {
119 nix.distributedBuilds = true;
120 nix.buildMachines = [{
121 hostName = "localhost";
123 sshKey = "/etc/nix/builder_ed25519";
124 system = linuxSystem;
126 supportedFeatures = [ "kvm" "benchmark" "big-parallel" ];
129 launchd.daemons.darwin-builder = {
130 command = "${darwin-builder.config.system.build.macos-builder-installer}/bin/create-builder";
134 StandardOutPath = "/var/log/darwin-builder.log";
135 StandardErrorPath = "/var/log/darwin-builder.log";
147 ## Reconfiguring the remote builder {#sec-darwin-builder-reconfiguring}
149 Initially you should not change the remote builder configuration else you will not be
150 able to use the binary cache. However, after you have the remote builder running locally
151 you may use it to build a modified remote builder with additional storage or memory.
153 To do this, you just need to set the `virtualisation.darwin-builder.*` parameters as
154 in the example below and rebuild.
158 darwin-builder = nixpkgs.lib.nixosSystem {
159 system = linuxSystem;
161 "${nixpkgs}/nixos/modules/profiles/macos-builder.nix"
163 virtualisation.host.pkgs = pkgs;
164 virtualisation.darwin-builder.diskSize = 5120;
165 virtualisation.darwin-builder.memorySize = 1024;
166 virtualisation.darwin-builder.hostPort = 33022;
167 virtualisation.darwin-builder.workingDirectory = "/var/lib/darwin-builder";
174 You may make any other changes to your VM in this attribute set. For example,
175 you could enable Docker or X11 forwarding to your Darwin host.
177 ## Troubleshooting the generated configuration {#sec-darwin-builder-troubleshoot}
179 The `linux-builder` package exposes the attributes `nixosConfig` and `nixosOptions` that allow you to inspect the generated NixOS configuration in the `nix repl`. For example:
182 $ nix repl --file ~/src/nixpkgs --argstr system aarch64-darwin
184 nix-repl> darwin.linux-builder.nixosConfig.nix.package
185 «derivation /nix/store/...-nix-2.17.0.drv»
187 nix-repl> :p darwin.linux-builder.nixosOptions.virtualisation.memorySize.definitionsWithLocations
188 [ { file = "/home/user/src/nixpkgs/nixos/modules/profiles/macos-builder.nix"; value = 3072; } ]