Skip to content

Darwin linux-builder drop-in solution with Rosetta support - #544193

Merged
arianvp merged 6 commits into
NixOS:masterfrom
tfc:darwin-linux-builder-vzvm-dropin
Aug 4, 2026
Merged

arianvp merged 6 commits into
NixOS:masterfrom
tfc:darwin-linux-builder-vzvm-dropin

Conversation

@tfc

@tfc tfc commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces a Linux builder for macOS that makes x86_64-linux builds ~2.5× faster by running the NixOS guest on Apple's native Virtualization.framework with Rosetta. It also has a smaller closure than the qemu build by offloading a lot to the apple framework.

This is designed as a ~one-line drop-in swap for darwin.linux-builder.

The PR consists of:

  • pkgs.vzvm, an Apple Virtualization.framework based VMM. It is minimized for the projected use case as a linux-builder drop-in replacement with Rosetta support. Forwards ssh TCP connects via vsock to get around the NAT setup from outside.
  • split up the linux-builder NixOS module to a qemu-agnostic part
  • Add the vzvm-specific linux-builder module next to the qemu-specific one
  • made sure that the qemu-vm module split did NOT change the qemu-vm derivation hash that we have right now.

The following nix-darwin configuration snippet can be used to run it:

{ pkgs, ... }:
{
  nix.linux-builder = {
    enable = true;

    package = pkgs.darwin.linux-builder-vz; # new
    systems = [
      "aarch64-linux"
      "x86_64-linux" # new
    ];

    ephemeral = true; # wipe the data disk on every start
    maxJobs = 4;
    supportedFeatures = [
      "kvm" # requires nestedVirtualization below (OPTIONAL)
      "benchmark"
      "big-parallel"
      "nixos-test"
    ];

    config = {
      virtualisation = {
        darwin-builder = {
          diskSize = 40 * 1024; # MiB
          memorySize = 8 * 1024; # MiB
        };
        cores = 8;

        # OPTIONAL:
        # Real /dev/kvm in the guest, for running NixOS VM tests on the
        # builder. Needs macOS 15+ and an M3 or newer chip.
        vz.nestedVirtualization = true; # new
      };
    };
  };
}

Regarding the AI policy: The upstream project has been developed with some LLM help but human-maintained and 110% human-reviewed and tested. All code in this PR is hand-written, but i let an LLM correct my sometimes bad english (not a native speaker).

Things done

@tfc
tfc requested review from Enzime, arianvp and reckenrode July 21, 2026 11:34
@nixpkgs-ci nixpkgs-ci Bot added 8.has: package (new) This PR adds a new package 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: documentation This PR adds or changes documentation labels Jul 21, 2026
@tfc
tfc force-pushed the darwin-linux-builder-vzvm-dropin branch 2 times, most recently from 60c18de to 56e7343 Compare July 21, 2026 13:58
@nixpkgs-ci
nixpkgs-ci Bot requested a review from GetPsyched July 21, 2026 14:04
@tfc
tfc force-pushed the darwin-linux-builder-vzvm-dropin branch from 56e7343 to 7e94757 Compare July 21, 2026 14:10
{
options = {

virtualisation.memorySize = lib.mkOption {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nikstur as you were working on a similar split-up of the vm module at BornHack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we get feedback from @nikstur i would incorporate that. otherwise this could be a followup PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately perpetuates the bad original design choices of the qemu-vm module. However, since the qemu-vm module is mostly untouched (and thus can be changed independently), this is fine for me. On the other hand, it makes it easier to remove the macos specific workarounds (hostPkgs. host certs, etc.) from the qemu abstraction. So it's fine for me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick feedback.

Do you have some material on your thoughts about the design choices and how you intend/plan to fix them?

Comment thread nixos/modules/virtualisation/vz-vm.nix Resolved
Comment thread nixos/modules/virtualisation/vz-vm.nix Resolved

@arianvp arianvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't been able to test this end-to-end yet as I'm on vacation without access to a Mac. Overall approach looks fine. But have a few comments / questions.

@nixpkgs-ci
nixpkgs-ci Bot requested a review from RaitoBezarius July 30, 2026 16:26
@tfc

tfc commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@arianvp i deduplicated the vsock and erofs stuff. for the rest we either block on @nikstur 's feedback or it's a followup PR.

@tfc
tfc force-pushed the darwin-linux-builder-vzvm-dropin branch from f579dd4 to 325e6b2 Compare July 30, 2026 16:53
@ofborg ofborg Bot added the 6.topic: darwin Running or building packages on Darwin label Aug 1, 2026
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/dmv-nix-user-group/78686/5

virtualisation.vz.diskImage = "./${config.networking.hostName}.qcow2";

# authorized keys come via virtiofs. fix uid and mode for sshd's ownership checks.
systemd.services.copy-builder-keys = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: This can be done way cleaner with a systemd credential passed by the hypervisor

e.g. #543333 adds support to configure the root's ssh key.

We can do something similar here. But I'll file that as a follow-up PR once linked PR lands.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds super interesting. I am happy to implement this or collab.

@arianvp arianvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to build both an aarch64 and x86_64 binary with this. Didn't test nested virtualization as I don't have an M3+ device.

I have some ideas how this can be further improved. e.g. I think we can avoid SSH altogether by making nix-daemon.socket listen on vsock directly. I'll have a look contributing those changes to the vz package

@arianvp
arianvp added this pull request to the merge queue Aug 4, 2026
@tfc

tfc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

I have some ideas how this can be further improved. e.g. I think we can avoid SSH altogether by making nix-daemon.socket listen on vsock directly. I'll have a look contributing those changes to the vz package

I have implemented this once but it's difficult for multiple reasons and did not bring the improvements that i hoped for. Let's chat about this if you're interested.

@tfc

tfc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much for your input, testing, and merging in such a short time @arianvp. I really appreciate it!!!

Merged via the queue into NixOS:master with commit a6509f0 Aug 4, 2026
31 of 33 checks passed
@tfc
tfc deleted the darwin-linux-builder-vzvm-dropin branch August 6, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: darwin Running or building packages on Darwin 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants