1 { system ? builtins.currentSystem
3 , pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
10 # A testScript fragment that prepares a disk with some empty, unpartitioned
11 # space. and uses it to boot the test with. Takes a single argument `machine`
12 # from which the diskImage is extracted.
13 useDiskImage = machine: ''
19 tmp_disk_image = tempfile.NamedTemporaryFile()
21 shutil.copyfile("${machine.system.build.diskImage}/nixos.img", tmp_disk_image.name)
24 "${machine.config.virtualisation.qemu.package}/bin/qemu-img",
32 # Set NIX_DISK_IMAGE so that the qemu script finds the right disk image.
33 os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
36 common = { config, pkgs, lib, ... }: {
37 virtualisation.useDefaultFilesystems = false;
38 virtualisation.fileSystems = {
45 # systemd-repart operates on disks with a partition table. The qemu module,
46 # however, creates separate filesystem images without a partition table, so
47 # we have to create a disk image manually.
49 # This creates two partitions, an ESP available as /dev/vda1 and the root
50 # partition available as /dev/vda2.
51 system.build.diskImage = import ../lib/make-disk-image.nix {
52 inherit config pkgs lib;
53 # Use a raw format disk so that it can be resized before starting the
56 # Keep the image as small as possible but leave some room for changes.
58 additionalSpace = "0M";
59 # GPT with an EFI System Partition is the typical use case for
60 # systemd-repart because it does not support MBR.
61 partitionTableType = "efi";
62 # We do not actually care much about the content of the partitions, so we
63 # do not need a bootloader installed.
64 installBootLoader = false;
65 # Improve determinism by not copying a channel.
72 name = "systemd-repart";
73 meta.maintainers = with maintainers; [ nikstur ];
75 nodes.machine = { config, pkgs, ... }: {
78 boot.initrd.systemd.enable = true;
80 boot.initrd.systemd.repart.enable = true;
81 systemd.repart.partitions = {
83 Type = "linux-generic";
88 testScript = { nodes, ... }: ''
89 ${useDiskImage nodes.machine}
92 machine.wait_for_unit("multi-user.target")
94 systemd_repart_logs = machine.succeed("journalctl --boot --unit systemd-repart.service")
95 assert "Growing existing partition 1." in systemd_repart_logs
99 after-initrd = makeTest {
100 name = "systemd-repart-after-initrd";
101 meta.maintainers = with maintainers; [ nikstur ];
103 nodes.machine = { config, pkgs, ... }: {
104 imports = [ common ];
106 systemd.repart.enable = true;
107 systemd.repart.partitions = {
109 Type = "linux-generic";
114 testScript = { nodes, ... }: ''
115 ${useDiskImage nodes.machine}
118 machine.wait_for_unit("multi-user.target")
120 systemd_repart_logs = machine.succeed("journalctl --unit systemd-repart.service")
121 assert "Growing existing partition 1." in systemd_repart_logs
125 create-root = makeTest {
126 name = "systemd-repart-create-root";
127 meta.maintainers = with maintainers; [ nikstur ];
129 nodes.machine = { config, lib, pkgs, ... }: {
130 virtualisation.useDefaultFilesystems = false;
131 virtualisation.fileSystems = {
133 device = "/dev/disk/by-partlabel/created-root";
137 device = "/dev/vda2";
142 # Create an image containing only the Nix store. This enables creating
143 # the root partition with systemd-repart and then successfully booting
144 # into a working system.
146 # This creates two partitions, an ESP available as /dev/vda1 and the Nix
147 # store available as /dev/vda2.
148 system.build.diskImage = import ../lib/make-disk-image.nix {
149 inherit config pkgs lib;
153 additionalSpace = "0M";
154 partitionTableType = "efi";
155 installBootLoader = false;
159 boot.initrd.systemd.enable = true;
161 boot.initrd.systemd.repart.enable = true;
162 boot.initrd.systemd.repart.device = "/dev/vda";
163 systemd.repart.partitions = {
166 Label = "created-root";
172 testScript = { nodes, ... }: ''
173 ${useDiskImage nodes.machine}
176 machine.wait_for_unit("multi-user.target")
178 systemd_repart_logs = machine.succeed("journalctl --boot --unit systemd-repart.service")
179 assert "Adding new partition 2 to partition table." in systemd_repart_logs