summary refs log tree commit diff
path: root/nixos/tests/systemd-repart.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/tests/systemd-repart.nix')
-rw-r--r--nixos/tests/systemd-repart.nix62
1 files changed, 60 insertions, 2 deletions
diff --git a/nixos/tests/systemd-repart.nix b/nixos/tests/systemd-repart.nix
index 5d579ae3371d1..22ea8fbd22711 100644
--- a/nixos/tests/systemd-repart.nix
+++ b/nixos/tests/systemd-repart.nix
@@ -56,8 +56,8 @@ let
     # however, creates separate filesystem images without a partition table, so
     # we have to create a disk image manually.
     #
-    # This creates two partitions, an ESP mounted on /dev/vda1 and the root
-    # partition mounted on /dev/vda2
+    # This creates two partitions, an ESP available as /dev/vda1 and the root
+    # partition available as /dev/vda2.
     system.build.diskImage = import ../lib/make-disk-image.nix {
       inherit config pkgs lib;
       # Use a raw format disk so that it can be resized before starting the
@@ -131,4 +131,62 @@ in
       assert "Growing existing partition 1." in systemd_repart_logs
     '';
   };
+
+  create-root = makeTest {
+    name = "systemd-repart-create-root";
+    meta.maintainers = with maintainers; [ nikstur ];
+
+    nodes.machine = { config, lib, pkgs, ... }: {
+      virtualisation.useDefaultFilesystems = false;
+      virtualisation.fileSystems = {
+        "/" = {
+          device = "/dev/disk/by-partlabel/created-root";
+          fsType = "ext4";
+        };
+        "/nix/store" = {
+          device = "/dev/vda2";
+          fsType = "ext4";
+        };
+      };
+
+      # Create an image containing only the Nix store. This enables creating
+      # the root partition with systemd-repart and then successfully booting
+      # into a working system.
+      #
+      # This creates two partitions, an ESP available as /dev/vda1 and the Nix
+      # store available as /dev/vda2.
+      system.build.diskImage = import ../lib/make-disk-image.nix {
+        inherit config pkgs lib;
+        onlyNixStore = true;
+        format = "raw";
+        bootSize = "32M";
+        additionalSpace = "0M";
+        partitionTableType = "efi";
+        installBootLoader = false;
+        copyChannel = false;
+      };
+
+      boot.initrd.systemd.enable = true;
+
+      boot.initrd.systemd.repart.enable = true;
+      boot.initrd.systemd.repart.device = "/dev/vda";
+      systemd.repart.partitions = {
+        "10-root" = {
+          Type = "root";
+          Label = "created-root";
+          Format = "ext4";
+        };
+      };
+    };
+
+    testScript = { nodes, ... }: ''
+      ${useDiskImage nodes.machine}
+
+      machine.start()
+      machine.wait_for_unit("multi-user.target")
+
+      systemd_repart_logs = machine.succeed("journalctl --boot --unit systemd-repart.service")
+      assert "Adding new partition 2 to partition table." in systemd_repart_logs
+    '';
+  };
 }