about summary refs log tree commit diff
path: root/nixos/tests/swap-file-btrfs.nix
diff options
context:
space:
mode:
authoroxalica <oxalicc@pm.me>2022-10-04 11:08:46 +0800
committeroxalica <oxalicc@pm.me>2023-01-17 06:56:55 +0800
commiteecb6c2bd82e7b2db3cc91c2cd0fbeddaa78eced (patch)
tree065713850bd794f62b7372c9088012906103f511 /nixos/tests/swap-file-btrfs.nix
parent87a0c9490d0c97f1dd40454b47a416d7477320ff (diff)
nixos/tests/swap-file-btrfs: init
Diffstat (limited to 'nixos/tests/swap-file-btrfs.nix')
-rw-r--r--nixos/tests/swap-file-btrfs.nix46
1 files changed, 46 insertions, 0 deletions
diff --git a/nixos/tests/swap-file-btrfs.nix b/nixos/tests/swap-file-btrfs.nix
new file mode 100644
index 0000000000000..4f73942b5f32b
--- /dev/null
+++ b/nixos/tests/swap-file-btrfs.nix
@@ -0,0 +1,46 @@
+import ./make-test-python.nix ({ lib, ... }:
+{
+  name = "swap-file-btrfs";
+
+  meta.maintainers = with lib.maintainers; [ oxalica ];
+
+  nodes.machine =
+    { pkgs, ... }:
+    {
+      virtualisation.useDefaultFilesystems = false;
+
+      virtualisation.bootDevice = "/dev/vda";
+
+      boot.initrd.postDeviceCommands = ''
+        ${pkgs.btrfs-progs}/bin/mkfs.btrfs --label root /dev/vda
+      '';
+
+      virtualisation.fileSystems = {
+        "/" = {
+          device = "/dev/disk/by-label/root";
+          fsType = "btrfs";
+        };
+      };
+
+      swapDevices = [
+        {
+          device = "/var/swapfile";
+          size = 1; # 1MiB.
+        }
+      ];
+    };
+
+  testScript = ''
+    machine.wait_for_unit('var-swapfile.swap')
+    machine.succeed("stat --file-system --format=%T /var/swapfile | grep btrfs")
+    # First run. Auto creation.
+    machine.succeed("swapon --show | grep /var/swapfile")
+
+    machine.shutdown()
+    machine.start()
+
+    # Second run. Use it as-is.
+    machine.wait_for_unit('var-swapfile.swap')
+    machine.succeed("swapon --show | grep /var/swapfile")
+  '';
+})