there’s also the
nixos-rebuild build-vm and
nixos-rebuild build-vm-with-bootloader if you want to sanity check a configuration.
Build a script that starts a NixOS virtual machine with the desired configuration. It
leaves a symlink result in the current directory that points (under result/bin/
run-hostname-vm) at the script that starts the VM. Thus, to test a NixOS configuration in
a virtual machine, you should do the following:
$ nixos-rebuild build-vm
The VM is implemented using the qemu package. For best performance, you should load the
kvm-intel or kvm-amd kernel modules to get hardware virtualisation.
The VM mounts the Nix store of the host through the 9P file system. The host Nix store is
read-only, so Nix commands that modify the Nix store will not work in the VM. This
includes commands such as nixos-rebuild; to change the VM’s configuration, you must halt
the VM and re-run the commands above.
The VM has its own ext3 root file system, which is automatically created when the VM is
first started, and is persistent across reboots of the VM. It is stored in
Like build-vm, but boots using the regular boot loader of your configuration (e.g., GRUB
1 or 2), rather than booting directly into the kernel and initial ramdisk of the system.
This allows you to test whether the boot loader works correctly. However, it does not
guarantee that your NixOS configuration will boot successfully on the host hardware
(i.e., after running nixos-rebuild switch), because the hardware and boot loader
configuration in the VM are different. The boot loader is installed on an automatically
generated virtual disk containing a /boot partition, which is mounted read-only in the
obviously some limitations compared to bare metal, but I would still say low risk.