4 rootFslabel = "external";
5 rootFsDevice = "/dev/disk/by-label/${rootFslabel}";
7 externalModule = partitionTableType: { config, lib, pkgs, ... }: {
8 virtualisation.directBoot.enable = false;
9 virtualisation.mountHostNixStore = false;
10 virtualisation.useEFIBoot = partitionTableType == "efi";
12 # This stops the qemu-vm module from overriding the fileSystems option
13 # with virtualisation.fileSystems.
14 virtualisation.fileSystems = lib.mkForce { };
17 boot.loader.grub.enable = true;
18 boot.loader.grub.efiSupport = partitionTableType == "efi";
19 boot.loader.grub.efiInstallAsRemovable = partitionTableType == "efi";
20 boot.loader.grub.device = if partitionTableType == "efi" then "nodev" else "/dev/vda";
22 boot.growPartition = true;
25 "/".device = rootFsDevice;
28 system.build.diskImage = import ../lib/make-disk-image.nix {
29 inherit config lib pkgs;
31 inherit partitionTableType;
34 additionalSpace = "0M";
40 name = "grow-partition";
42 meta.maintainers = with lib.maintainers; [ arianvp ];
45 efi = externalModule "efi";
46 legacy = externalModule "legacy";
47 legacyGPT = externalModule "legacy+gpt";
48 hybrid = externalModule "hybrid";
52 testScript = { nodes, ... }:
53 lib.concatLines (lib.mapAttrsToList (name: node: ''
59 tmp_disk_image = tempfile.NamedTemporaryFile()
61 shutil.copyfile("${node.system.build.diskImage}/nixos.img", tmp_disk_image.name)
64 "${node.virtualisation.qemu.package}/bin/qemu-img",
72 # Set NIX_DISK_IMAGE so that the qemu script finds the right disk image.
73 os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
75 ${name}.wait_for_unit("growpart.service")
76 systemd_growpart_logs = ${name}.succeed("journalctl --boot --unit growpart.service")
77 assert "CHANGED" in systemd_growpart_logs
78 ${name}.succeed("systemctl restart growpart.service")
79 systemd_growpart_logs = ${name}.succeed("journalctl --boot --unit growpart.service")
80 assert "NOCHANGE" in systemd_growpart_logs