Home Explore Blog Models CI



nixpkgs

3rd chunk of `doc/packages/darwin-builder.section.md`
82557e5f195651b8fc828f01ec5a261efaf5df13344961ba0000000100000c02
            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";
                serviceConfig = {
                  KeepAlive = true;
                  RunAtLoad = true;
                  StandardOutPath = "/var/log/darwin-builder.log";
                  StandardErrorPath = "/var/log/darwin-builder.log";
                };
              };
            }
          ];
        };
      };

    };
}
```

## Reconfiguring the remote builder {#sec-darwin-builder-reconfiguring}

Initially you should not change the remote builder configuration else you will not be
able to use the binary cache. However, after you have the remote builder running locally
you may use it to build a modified remote builder with additional storage or memory.

To do this, you just need to set the `virtualisation.darwin-builder.*` parameters as
in the example below and rebuild.

```nix
{
  darwin-builder = nixpkgs.lib.nixosSystem {
    system = linuxSystem;
    modules = [
      "${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix"
      {
        virtualisation.host.pkgs = pkgs;
        virtualisation.darwin-builder.diskSize = 5120;
        virtualisation.darwin-builder.memorySize = 1024;
        virtualisation.darwin-builder.hostPort = 33022;
        virtualisation.darwin-builder.workingDirectory = "/var/lib/darwin-builder";
      }
    ];
  };
}
```

You may make any other changes to your VM in this attribute set. For example,
you could enable Docker or X11 forwarding to your Darwin host.

## Troubleshooting the generated configuration {#sec-darwin-builder-troubleshoot}

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:

```
$ nix repl --file ~/src/nixpkgs --argstr system aarch64-darwin

nix-repl> darwin.linux-builder.nixosConfig.nix.package
«derivation /nix/store/...-nix-2.17.0.drv»

nix-repl> :p darwin.linux-builder.nixosOptions.virtualisation.memorySize.definitionsWithLocations
[ { file = "/home/user/src/nixpkgs/nixos/modules/profiles/nix-builder-vm.nix"; value = 3072; } ]

```

Title: Nix Darwin Builder: Advanced Configuration and Troubleshooting
Summary
This chunk concludes a Nix flake example, detailing the `launchd.daemons` configuration for the `darwin-builder` service, ensuring it keeps alive, runs at load, and logs to specified paths. It then transitions to reconfiguring the remote builder, advising against initial changes to preserve binary cache access. Once running, users can modify parameters like `diskSize`, `memorySize`, `hostPort`, and `workingDirectory` within `virtualisation.darwin-builder.*` to customize the VM (e.g., adding Docker or X11 forwarding). Finally, it explains how to troubleshoot the generated configuration by using `nix repl` to inspect `nixosConfig` and `nixosOptions` attributes of the `linux-builder` package, allowing users to examine package paths and option definitions.