1 import ./make-test-python.nix ({ pkgs, ... }: {
3 meta.maintainers = with pkgs.lib.maintainers; [ fpletz ];
13 libvirtd.enable = true;
14 libvirtd.hooks.qemu.is_working = "${pkgs.writeShellScript "testHook.sh" ''
15 touch /tmp/qemu_hook_is_working
17 libvirtd.nss.enable = true;
19 boot.supportedFilesystems = [ "zfs" ];
20 networking.hostId = "deadbeef"; # needed for zfs
21 security.polkit.enable = true;
22 environment.systemPackages = with pkgs; [ virt-manager ];
24 # This adds `resolve` to the `hosts` line of /etc/nsswitch.conf; NSS modules placed after it
25 # will not be consulted. Therefore this tests that the libvirtd NSS modules will be
26 # be placed early enough for name resolution to work.
27 services.resolved.enable = true;
32 nixosInstallISO = (import ../release.nix {}).iso_minimal.${pkgs.stdenv.hostPlatform.system};
33 virshShutdownCmd = if pkgs.stdenv.hostPlatform.isx86_64 then "shutdown" else "destroy";
37 virthost.wait_for_unit("multi-user.target")
39 with subtest("enable default network"):
40 virthost.succeed("virsh net-start default")
41 virthost.succeed("virsh net-autostart default")
42 virthost.succeed("virsh net-info default")
44 with subtest("check if partition disk pools works with parted"):
45 virthost.succeed("fallocate -l100m /tmp/foo; losetup /dev/loop0 /tmp/foo; echo 'label: dos' | sfdisk /dev/loop0")
46 virthost.succeed("virsh pool-create-as foo disk --source-dev /dev/loop0 --target /dev")
47 virthost.succeed("virsh vol-create-as foo loop0p1 25MB")
48 virthost.succeed("virsh vol-create-as foo loop0p2 50MB")
50 with subtest("check if virsh zfs pools work"):
51 virthost.succeed("fallocate -l100m /tmp/zfs; losetup /dev/loop1 /tmp/zfs;")
52 virthost.succeed("zpool create zfs_loop /dev/loop1")
53 virthost.succeed("virsh pool-define-as --name zfs_storagepool --source-name zfs_loop --type zfs")
54 virthost.succeed("virsh pool-start zfs_storagepool")
55 virthost.succeed("virsh vol-create-as zfs_storagepool disk1 25MB")
57 with subtest("check if nixos install iso boots, network and autostart works"):
59 "virt-install -n nixos --osinfo nixos-unstable --memory 1024 --graphics none --disk `find ${nixosInstallISO}/iso -type f | head -n1`,readonly=on --import --noautoconsole --autostart"
61 virthost.succeed("virsh domstate nixos | grep running")
62 virthost.wait_until_succeeds("ping -c 1 nixos")
63 virthost.succeed("virsh ${virshShutdownCmd} nixos")
64 virthost.wait_until_succeeds("virsh domstate nixos | grep 'shut off'")
66 virthost.wait_for_unit("multi-user.target")
67 virthost.wait_until_succeeds("ping -c 1 nixos")
69 with subtest("test if hooks are linked and run"):
70 virthost.succeed("ls /var/lib/libvirt/hooks/qemu.d/is_working")
71 virthost.succeed("ls /tmp/qemu_hook_is_working")