at 25.11-pre 1.5 kB view raw
1import ./make-test-python.nix ( 2 { lib, ... }: 3 { 4 name = "swap-file-btrfs"; 5 6 meta.maintainers = with lib.maintainers; [ oxalica ]; 7 8 nodes.machine = 9 { pkgs, ... }: 10 { 11 virtualisation.useDefaultFilesystems = false; 12 13 virtualisation.rootDevice = "/dev/vda"; 14 15 boot.initrd.postDeviceCommands = '' 16 ${pkgs.btrfs-progs}/bin/mkfs.btrfs --label root /dev/vda 17 ''; 18 19 virtualisation.fileSystems = { 20 "/" = { 21 device = "/dev/disk/by-label/root"; 22 fsType = "btrfs"; 23 }; 24 }; 25 26 swapDevices = [ 27 { 28 device = "/var/swapfile"; 29 size = 1; # 1MiB. 30 } 31 ]; 32 }; 33 34 testScript = '' 35 machine.wait_for_unit('var-swapfile.swap') 36 # Ensure the swap file creation script ran to completion without failing when creating the swap file 37 machine.fail("systemctl is-failed --quiet mkswap-var-swapfile.service") 38 machine.succeed("stat --file-system --format=%T /var/swapfile | grep btrfs") 39 # First run. Auto creation. 40 machine.succeed("swapon --show | grep /var/swapfile") 41 42 machine.shutdown() 43 machine.start() 44 45 # Second run. Use it as-is. 46 machine.wait_for_unit('var-swapfile.swap') 47 # Ensure the swap file creation script ran to completion without failing when the swap file already exists 48 machine.fail("systemctl is-failed --quiet mkswap-var-swapfile.service") 49 machine.succeed("swapon --show | grep /var/swapfile") 50 ''; 51 } 52)