Merge pull request #235295 from nikstur/qemu-vm-improve-comments-and-docs

nixos/qemu-vm: improve comments and option descriptions
This commit is contained in:
Ryan Lahfa 2023-06-02 15:34:49 +02:00 committed by GitHub
commit 0902958046
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,8 @@
# This module creates a virtual machine from the NixOS configuration. # This module creates a virtual machine from the NixOS configuration.
# Building the `config.system.build.vm' attribute gives you a command # Building the `config.system.build.vm' attribute gives you a command
# that starts a KVM/QEMU VM running the NixOS configuration defined in # that starts a KVM/QEMU VM running the NixOS configuration defined in
# `config'. The Nix store is shared read-only with the host, which # `config'. By default, the Nix store is shared read-only with the
# makes (re)building VMs very efficient. However, it also means you # host, which makes (re)building VMs very efficient.
# can't reconfigure the guest inside the guest - you need to rebuild
# the VM in the host. On the other hand, the root filesystem is a
# read/writable disk image persistent across VM reboots.
{ config, lib, pkgs, options, ... }: { config, lib, pkgs, options, ... }:
@ -778,12 +775,11 @@ in
default = false; default = false;
description = description =
lib.mdDoc '' lib.mdDoc ''
If enabled, the virtual machine will be booted using the Use a boot loader to boot the system.
regular boot loader (i.e., GRUB 1 or 2). This allows This allows, among other things, testing the boot loader.
testing of the boot loader. If
disabled (the default), the VM directly boots the NixOS If disabled, the kernel and initrd are directly booted,
kernel and initial ramdisk, bypassing the boot loader forgoing any bootloader.
altogether.
''; '';
}; };
@ -1026,7 +1022,6 @@ in
"-netdev user,id=user.0,${forwardingOptions}${restrictNetworkOption}\"$QEMU_NET_OPTS\"" "-netdev user,id=user.0,${forwardingOptions}${restrictNetworkOption}\"$QEMU_NET_OPTS\""
]; ];
# FIXME: Consolidate this one day.
virtualisation.qemu.options = mkMerge [ virtualisation.qemu.options = mkMerge [
(mkIf cfg.qemu.virtioKeyboard [ (mkIf cfg.qemu.virtioKeyboard [
"-device virtio-keyboard" "-device virtio-keyboard"
@ -1078,14 +1073,12 @@ in
}) cfg.emptyDiskImages) }) cfg.emptyDiskImages)
]; ];
# Use mkVMOverride to enable building test VMs (e.g. via `nixos-rebuild
# build-vm`) of a system configuration, where the regular value for the
# `fileSystems' attribute should be disregarded (since those filesystems
# don't necessarily exist in the VM).
fileSystems = mkVMOverride cfg.fileSystems; fileSystems = mkVMOverride cfg.fileSystems;
# Mount the host filesystem via 9P, and bind-mount the Nix store
# of the host into our own filesystem. We use mkVMOverride to
# allow this module to be applied to "normal" NixOS system
# configuration, where the regular value for the `fileSystems'
# attribute should be disregarded for the purpose of building a VM
# test image (since those filesystems don't exist in the VM).
virtualisation.fileSystems = let virtualisation.fileSystems = let
mkSharedDir = tag: share: mkSharedDir = tag: share:
{ {