1 import ./make-test-python.nix ({ lib, pkgs, ... }:
3 name = "swap-partition";
6 { config, pkgs, lib, ... }:
8 virtualisation.useDefaultFilesystems = false;
10 virtualisation.rootDevice = "/dev/vda1";
12 boot.initrd.postDeviceCommands = ''
13 if ! test -b /dev/vda1; then
14 ${pkgs.parted}/bin/parted --script /dev/vda -- mklabel msdos
15 ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary 1MiB -250MiB
16 ${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary -250MiB 100%
20 FSTYPE=$(blkid -o value -s TYPE /dev/vda1 || true)
21 if test -z "$FSTYPE"; then
22 ${pkgs.e2fsprogs}/bin/mke2fs -t ext4 -L root /dev/vda1
23 ${pkgs.util-linux}/bin/mkswap --label swap /dev/vda2
27 virtualisation.fileSystems = {
29 device = "/dev/disk/by-label/root";
36 device = "/dev/disk/by-label/swap";
42 machine.wait_for_unit("multi-user.target")
44 with subtest("Swap is active"):
45 # Doesn't matter if the numbers reported by `free` are slightly off due to unit conversions.
46 machine.succeed("free -h | grep -E 'Swap:\s+2[45][0-9]Mi'")