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 -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:
$ 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
.
- 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* - Rosetta - by leveraging vfkit´s and NixOS´ Rosetta integrations you can build derivations for both
aarch64-linux
andx86_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(?).
- Persistence:
virtio-blk
is quite easy to use, just needs a nice interface on the module side. I didn't bother so far, asvirtio-fs
works well enough atm.
There's a branchdisk
in which I played around with formatting avirtio-blk
device wich systemd-repart on first boot, but didn't finish that yet. - VM Tests with our vfkit VMs would be awesome.
- Might be worth a try to (optionally) replace qemu in nix-darwins linux-builder vm for rosetta.
- This list: There's much to explore & still a bit to clean-up.