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