1 # Tests that you can boot from an external disk image with the qemu-vm module.
2 # "External" here means that the image was not produced within the qemu-vm
3 # module and relies on the fileSystems option also set outside the qemu-vm
4 # module. Most notably, this tests that you can stop the qemu-vm module from
5 # overriding fileSystems with virtualisation.fileSystems so you don't have to
6 # replicate the previously set fileSystems in virtualisation.fileSystems.
11 rootFslabel = "external";
12 rootFsDevice = "/dev/disk/by-label/${rootFslabel}";
14 externalModule = { config, lib, pkgs, ... }: {
15 boot.loader.systemd-boot.enable = true;
18 "/".device = rootFsDevice;
21 system.build.diskImage = import ../lib/make-disk-image.nix {
22 inherit config lib pkgs;
24 partitionTableType = "efi";
27 additionalSpace = "0M";
33 name = "qemu-vm-external-disk-image";
35 meta.maintainers = with lib.maintainers; [ nikstur ];
37 nodes.machine = { config, lib, pkgs, ... }: {
38 virtualisation.directBoot.enable = false;
39 virtualisation.mountHostNixStore = false;
40 virtualisation.useEFIBoot = true;
42 # This stops the qemu-vm module from overriding the fileSystems option
43 # with virtualisation.fileSystems.
44 virtualisation.fileSystems = lib.mkForce { };
46 imports = [ externalModule ];
49 testScript = { nodes, ... }: ''
54 tmp_disk_image = tempfile.NamedTemporaryFile()
57 "${nodes.machine.virtualisation.qemu.package}/bin/qemu-img",
62 "${nodes.machine.system.build.diskImage}/nixos.qcow2",
68 # Set NIX_DISK_IMAGE so that the qemu script finds the right disk image.
69 os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
71 machine.succeed("findmnt --kernel --source ${rootFsDevice} --target /")
73 # Make sure systemd boot didn't clobber this
74 machine.succeed("[ ! -e /homeless-shelter ]")