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