at 24.11-pre 2.4 kB view raw
1{ lib, ... }: 2 3let 4 rootFslabel = "external"; 5 rootFsDevice = "/dev/disk/by-label/${rootFslabel}"; 6 7 externalModule = partitionTableType: { config, lib, pkgs, ... }: { 8 virtualisation.directBoot.enable = false; 9 virtualisation.mountHostNixStore = false; 10 virtualisation.useEFIBoot = partitionTableType == "efi"; 11 12 # This stops the qemu-vm module from overriding the fileSystems option 13 # with virtualisation.fileSystems. 14 virtualisation.fileSystems = lib.mkForce { }; 15 16 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"; 21 22 boot.growPartition = true; 23 24 fileSystems = { 25 "/".device = rootFsDevice; 26 }; 27 28 system.build.diskImage = import ../lib/make-disk-image.nix { 29 inherit config lib pkgs; 30 label = rootFslabel; 31 inherit partitionTableType; 32 format = "raw"; 33 bootSize = "128M"; 34 additionalSpace = "0M"; 35 copyChannel = false; 36 }; 37 }; 38in 39{ 40 name = "grow-partition"; 41 42 meta.maintainers = with lib.maintainers; [ arianvp ]; 43 44 nodes = { 45 efi = externalModule "efi"; 46 legacy = externalModule "legacy"; 47 legacyGPT = externalModule "legacy+gpt"; 48 hybrid = externalModule "hybrid"; 49 }; 50 51 52 testScript = { nodes, ... }: 53 lib.concatLines (lib.mapAttrsToList (name: node: '' 54 import os 55 import subprocess 56 import tempfile 57 import shutil 58 59 tmp_disk_image = tempfile.NamedTemporaryFile() 60 61 shutil.copyfile("${node.system.build.diskImage}/nixos.img", tmp_disk_image.name) 62 63 subprocess.run([ 64 "${node.virtualisation.qemu.package}/bin/qemu-img", 65 "resize", 66 "-f", 67 "raw", 68 tmp_disk_image.name, 69 "+32M", 70 ]) 71 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 74 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 81 82 '') nodes); 83}