phaer/nixos-vm-on-macos
{ "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"}NixOS VM on macOS
Section titled “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:
$ nix run .\#nixosConfigurations.minimal-vm.config.system.build.vm -LShare Files
Section titled “Share Files”The local (currently empty) directory persistent gets mounted to /persistent in the guest via `virtio-fs“.
Get the IP
Section titled “Get the IP”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:
$ nix run .\#get-vm-ip -- minimal-vmfe80::f425:e2ff:fe48:581e%bridge100$ nix run .\#get-vm-ip -- minimal-vm -4192.168.64.2Enable the GUI
Section titled “Enable the GUI”Set virtualisation.graphics = true; in configuration.nix.
Builder VM
Section titled “Builder VM”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
nix run .\#nixosConfigurations.builder-vm.config.system.build.macos-builder-installer -LBut 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
What works
Section titled “What works”- 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-linuxandx86_64-linuxin 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(?).
What needs work
Section titled “What needs work”- 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.