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