at master 4.6 kB view raw
1{ 2 system ? builtins.currentSystem, 3 config ? { }, 4 pkgs ? import ../.. { inherit system config; }, 5}: 6 7with import ../lib/testing-python.nix { inherit system pkgs; }; 8with pkgs.lib; 9{ 10 bind = makeTest { 11 name = "non-default-filesystem-bind"; 12 13 nodes.machine = 14 { ... }: 15 { 16 virtualisation.writableStore = false; 17 18 virtualisation.fileSystems."/test-bind-dir/bind" = { 19 device = "/"; 20 neededForBoot = true; 21 options = [ "bind" ]; 22 }; 23 24 virtualisation.fileSystems."/test-bind-file/bind" = { 25 depends = [ "/nix/store" ]; 26 device = builtins.toFile "empty" ""; 27 neededForBoot = true; 28 options = [ "bind" ]; 29 }; 30 }; 31 32 testScript = '' 33 machine.wait_for_unit("multi-user.target") 34 ''; 35 }; 36 37 btrfs = makeTest { 38 name = "non-default-filesystems-btrfs"; 39 40 nodes.machine = 41 { 42 config, 43 pkgs, 44 lib, 45 ... 46 }: 47 let 48 disk = config.virtualisation.rootDevice; 49 in 50 { 51 virtualisation.rootDevice = "/dev/vda"; 52 virtualisation.useDefaultFilesystems = false; 53 54 boot.initrd.availableKernelModules = [ "btrfs" ]; 55 boot.supportedFilesystems = [ "btrfs" ]; 56 57 boot.initrd.postDeviceCommands = '' 58 FSTYPE=$(blkid -o value -s TYPE ${disk} || true) 59 if test -z "$FSTYPE"; then 60 modprobe btrfs 61 ${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk} 62 63 mkdir /nixos 64 mount -t btrfs ${disk} /nixos 65 66 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root 67 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home 68 69 umount /nixos 70 fi 71 ''; 72 73 virtualisation.fileSystems = { 74 "/" = { 75 device = disk; 76 fsType = "btrfs"; 77 options = [ "subvol=/root" ]; 78 }; 79 80 "/home" = { 81 device = disk; 82 fsType = "btrfs"; 83 options = [ "subvol=/home" ]; 84 }; 85 }; 86 }; 87 88 testScript = '' 89 machine.wait_for_unit("multi-user.target") 90 91 with subtest("BTRFS filesystems are mounted correctly"): 92 print("output of \"grep -E '/dev/vda' /proc/mounts\":\n" + machine.execute("grep -E '/dev/vda' /proc/mounts")[1]) 93 machine.succeed("grep -E '/dev/vda / btrfs rw,.*subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts") 94 machine.succeed("grep -E '/dev/vda /home btrfs rw,.*subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts") 95 ''; 96 }; 97 98 erofs = 99 let 100 fsImage = "/tmp/non-default-filesystem.img"; 101 in 102 makeTest { 103 name = "non-default-filesystems-erofs"; 104 105 meta.maintainers = with maintainers; [ nikstur ]; 106 107 nodes.machine = _: { 108 virtualisation.qemu.drives = [ 109 { 110 name = "non-default-filesystem"; 111 file = fsImage; 112 } 113 ]; 114 115 virtualisation.fileSystems."/non-default" = { 116 device = "/dev/vdb"; 117 fsType = "erofs"; 118 neededForBoot = true; 119 }; 120 }; 121 122 testScript = '' 123 import subprocess 124 import tempfile 125 126 with tempfile.TemporaryDirectory() as tmp_dir: 127 with open(f"{tmp_dir}/filesystem", "w") as f: 128 f.write("erofs") 129 130 subprocess.run([ 131 "${pkgs.erofs-utils}/bin/mkfs.erofs", 132 "${fsImage}", 133 tmp_dir, 134 ]) 135 136 machine.start() 137 machine.wait_for_unit("default.target") 138 139 file_contents = machine.succeed("cat /non-default/filesystem") 140 assert "erofs" in file_contents 141 ''; 142 }; 143 144 squashfs = 145 let 146 fsImage = "/tmp/non-default-filesystem.img"; 147 in 148 makeTest { 149 name = "non-default-filesystems-squashfs"; 150 151 meta.maintainers = with maintainers; [ nikstur ]; 152 153 nodes.machine = { 154 virtualisation.qemu.drives = [ 155 { 156 name = "non-default-filesystem"; 157 file = fsImage; 158 deviceExtraOpts.serial = "non-default"; 159 } 160 ]; 161 162 virtualisation.fileSystems."/non-default" = { 163 device = "/dev/disk/by-id/virtio-non-default"; 164 fsType = "squashfs"; 165 neededForBoot = true; 166 }; 167 }; 168 169 testScript = '' 170 import subprocess 171 172 with open("filesystem", "w") as f: 173 f.write("squashfs") 174 175 subprocess.run([ 176 "${pkgs.squashfsTools}/bin/mksquashfs", 177 "filesystem", 178 "${fsImage}", 179 ]) 180 181 assert "squashfs" in machine.succeed("cat /non-default/filesystem") 182 ''; 183 }; 184}