Home Explore Blog Models CI



nixpkgs

2nd chunk of `doc/packages/darwin-builder.section.md`
07aa02d26a2df7d3b232c3fdf5a9002a7899e2920a6f3a4400000001000008bc
# Not strictly necessary, but this will reduce your disk utilization
builders-use-substitutes = true
```

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`:

```
Host linux-builder
  Hostname localhost
  HostKeyAlias linux-builder
  Port 31022
```

… and then restart your Nix daemon to apply the change:

```ShellSession
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon
```

## Example flake usage {#sec-darwin-builder-example-flake}

```nix
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-22.11-darwin";
    darwin.url = "github:lnl7/nix-darwin/master";
    darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs =
    {
      self,
      darwin,
      nixpkgs,
      ...
    }@inputs:
    let

      inherit (darwin.lib) darwinSystem;
      system = "aarch64-darwin";
      pkgs = nixpkgs.legacyPackages."${system}";
      linuxSystem = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;

      darwin-builder = nixpkgs.lib.nixosSystem {
        system = linuxSystem;
        modules = [
          "${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix"
          {
            virtualisation = {
              host.pkgs = pkgs;
              darwin-builder.workingDirectory = "/var/lib/darwin-builder";
              darwin-builder.hostPort = 22;
            };
          }
        ];
      };
    in
    {

      darwinConfigurations = {
        machine1 = darwinSystem {
          inherit system;
          modules = [
            {
              nix.distributedBuilds = true;
              nix.buildMachines = [
                {
                  hostName = "localhost";
                  sshUser = "builder";
                  sshKey = "/etc/nix/builder_ed25519";
                  system = linuxSystem;
                  maxJobs = 4;
                  supportedFeatures = [
                    "kvm"
                    "benchmark"
                    "big-parallel"
                  ];
                }
              ];

              launchd.daemons.darwin-builder = {
                command = "${darwin-builder.config.system.build.macos-builder-installer}/bin/create-builder";

Title: Darwin Linux Builder Configuration and Flake Example
Summary
This text provides final configuration steps for `darwin.linux-builder`, including setting `builders-use-substitutes = true` to reduce disk usage and creating an SSH configuration file (`/etc/ssh/ssh_config.d/100-linux-builder.conf`) to allow Nix to connect to the remote builder on port 31022. It instructs users to restart the Nix daemon to apply changes. The document then presents a detailed Nix flake example, demonstrating how to define inputs, set up the `darwin-builder` as a `nixosSystem` with specific modules and host port, and configure a macOS system (`darwinConfigurations.machine1`) to use distributed builds, pointing to the `localhost` builder with specified SSH user, key, system type, max jobs, and supported features, and launching it via `launchd.daemons`.