···11# This module creates a virtual machine from the NixOS configuration.
22# Building the `config.system.build.vm' attribute gives you a command
33# that starts a KVM/QEMU VM running the NixOS configuration defined in
44-# `config'. The Nix store is shared read-only with the host, which
55-# makes (re)building VMs very efficient. However, it also means you
66-# can't reconfigure the guest inside the guest - you need to rebuild
77-# the VM in the host. On the other hand, the root filesystem is a
88-# read/writable disk image persistent across VM reboots.
44+# `config'. By default, the Nix store is shared read-only with the
55+# host, which makes (re)building VMs very efficient.
96107{ config, lib, pkgs, options, ... }:
118···778775 default = false;
779776 description =
780777 lib.mdDoc ''
781781- If enabled, the virtual machine will be booted using the
782782- regular boot loader (i.e., GRUB 1 or 2). This allows
783783- testing of the boot loader. If
784784- disabled (the default), the VM directly boots the NixOS
785785- kernel and initial ramdisk, bypassing the boot loader
786786- altogether.
778778+ Use a boot loader to boot the system.
779779+ This allows, among other things, testing the boot loader.
780780+781781+ If disabled, the kernel and initrd are directly booted,
782782+ forgoing any bootloader.
787783 '';
788784 };
789785···10261022 "-netdev user,id=user.0,${forwardingOptions}${restrictNetworkOption}\"$QEMU_NET_OPTS\""
10271023 ];
1028102410291029- # FIXME: Consolidate this one day.
10301025 virtualisation.qemu.options = mkMerge [
10311026 (mkIf cfg.qemu.virtioKeyboard [
10321027 "-device virtio-keyboard"
···10781073 }) cfg.emptyDiskImages)
10791074 ];
1080107510761076+ # Use mkVMOverride to enable building test VMs (e.g. via `nixos-rebuild
10771077+ # build-vm`) of a system configuration, where the regular value for the
10781078+ # `fileSystems' attribute should be disregarded (since those filesystems
10791079+ # don't necessarily exist in the VM).
10811080 fileSystems = mkVMOverride cfg.fileSystems;
1082108110831083- # Mount the host filesystem via 9P, and bind-mount the Nix store
10841084- # of the host into our own filesystem. We use mkVMOverride to
10851085- # allow this module to be applied to "normal" NixOS system
10861086- # configuration, where the regular value for the `fileSystems'
10871087- # attribute should be disregarded for the purpose of building a VM
10881088- # test image (since those filesystems don't exist in the VM).
10891082 virtualisation.fileSystems = let
10901083 mkSharedDir = tag: share:
10911084 {