summaryrefslogtreecommitdiffstats
path: root/nixos/tests/swap-partition.nix
blob: fa370be079c84afd3867af8bb4549a1e0d2418e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{ ... }:
{
  name = "swap-partition";

  nodes.machine =
    { config, ... }:
    {
      virtualisation.useDefaultFilesystems = false;

      virtualisation.rootDevice = "/dev/vda1";

      boot.initrd.systemd = {
        enable = true;
        repart = {
          enable = true;
          device = "/dev/vda";
          empty = "allow";
        };
      };
      systemd.repart.partitions = {
        "00-root" = {
          Type = "linux-generic";
          Format = "ext4";
          Label = "root";
        };
        "10-swap" = {
          Type = "linux-generic";
          Label = "swap";
          SizeMinBytes = "250M";
          SizeMaxBytes = "250M";
        };
      };

      virtualisation.fileSystems = {
        "/" = {
          device = "/dev/disk/by-label/root";
          fsType = "ext4";
        };
      };

      swapDevices = [
        {
          device = "/dev/disk/by-partlabel/swap";
          options = [ "x-systemd.makefs" ];
        }
      ];
    };

  testScript = ''
    machine.wait_for_unit("multi-user.target")

    with subtest("Swap is active"):
      # Doesn't matter if the numbers reported by `free` are slightly off due to unit conversions.
      machine.succeed("free -h | grep -E 'Swap:\s+2[45][0-9]Mi'")
  '';
}