Skip to content
vic

phaer/nixos-vm-on-macos

Run #NixOS on darwin, including Rosetta 2 & virtiofs!

phaer/nixos-vm-on-macos.json
{
"createdAt": "2025-01-11T17:11:19Z",
"defaultBranch": "main",
"description": "Run #NixOS on darwin, including Rosetta 2 & virtiofs!",
"fullName": "phaer/nixos-vm-on-macos",
"homepage": null,
"language": "Nix",
"name": "nixos-vm-on-macos",
"pushedAt": "2025-07-23T13:56:36Z",
"stargazersCount": 24,
"topics": [],
"updatedAt": "2025-10-06T10:14:14Z",
"url": "https://github.com/phaer/nixos-vm-on-macos"
}

This repository contains code to build and run NixOS in virtual machines on macOS. It uses vfkit as qemu doesn’t support apple´s virtualisation framework, and UTM isn’t as easy to configure from nix expressions.

It is currently not much more than a quick weekend hack and therefore experimental, neither stable nor feature-complete - but fun & promising!

To start a graphical, rather minimal VM run:

Terminal window
$ nix run .\#nixosConfigurations.minimal-vm.config.system.build.vm -L

The local (currently empty) directory persistent gets mounted to /persistent in the guest via `virtio-fs“.

minimal-vm has a static mac address defined in virtualisation.macAddress, which can be used to derive its ipv6 link local address. A legacy ipv4 address can be acquired by parsing /var/db/dhcpd_leases. A helper script to do both is included in this repository:

Terminal window
$ nix run .\#get-vm-ip -- minimal-vm
fe80::f425:e2ff:fe48:581e%bridge100
$ nix run .\#get-vm-ip -- minimal-vm -4
192.168.64.2

Set virtualisation.graphics = true; in configuration.nix.

There’s a proof-of-concept implementation of nix-darwins pkgs.linux-builder, based on vfkit and therefore able to use rosetta.

You can start it with

Terminal window
nix run .\#nixosConfigurations.builder-vm.config.system.build.macos-builder-installer -L

But it might interfere with already running linux-builders. It doesn’t listen on a high port, as upstream does. Instead its local IP is fully routed. A patched, not yet upstreamed, nix-darwin fork to allow setting a custom host & port for the builder is available at: https://github.com/nix-darwin/nix-darwin/pull/1459

  • Booting a closure, directly from kernel and initrd.
  • Mounting host file systems via virtio-fs. Used for a writable overlay over the hosts nix store by default (see [hosts/minimal-vm]!(./hosts/minimal-vm)
  • Alternatively, a read-only erofs image with your boot closure and an optional writable overlay in a separate disk image. Those should eventually become a single image. See [hosts/builder-vm]!(./hosts/builder-vm)
  • Rosetta - by leveraging vfkit´s and NixOS´ Rosetta integrations you can build derivations for both aarch64-linux and x86_64-linux in the VM.
  • Bridged networking via virto-net.
  • Graphical mode with virtio-gpu. vfkit´s GUI seems to be still limited though, e.g. no copy & paste support(?).
  • VM Tests with our vfkit VMs would be awesome.
  • CI tests for the builds would be awesome.
  • Same for a release pipeline to pre-build images.
  • This list: There’s much to explore & still a bit to clean-up.