diff --git a/nixos/modules/virtualisation/incus-virtual-machine.nix b/nixos/modules/virtualisation/incus-virtual-machine.nix index d714b7fdc36c..2cf4cff8bce3 100644 --- a/nixos/modules/virtualisation/incus-virtual-machine.nix +++ b/nixos/modules/virtualisation/incus-virtual-machine.nix @@ -14,6 +14,7 @@ in }; imports = [ + ../image/repart.nix ./lxc-instance-common.nix ../profiles/qemu-guest.nix @@ -28,6 +29,50 @@ in copyChannel = config.system.installer.channel.enable; }; + system.build.repartImage = config.image.repart.image.overrideAttrs (previousAttrs: { + nativeBuildInputs = previousAttrs.nativeBuildInputs ++ [ pkgs.qemu-utils ]; + postBuild = '' + qemu-img convert -f raw -O qcow2 -c ${config.image.baseName}.raw ${config.image.baseName}.qcow2 + rm ${config.image.baseName}.raw + ''; + }); + + image.repart = { + name = "nixos"; + version = null; + sectorSize = 512; + compression.enable = false; + partitions = { + esp = { + contents = + let + efiArch = pkgs.stdenv.hostPlatform.efiArch; + in + { + "/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source = + "${config.systemd.package}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi"; + "/EFI/Linux/${config.system.boot.loader.ukiFile}".source = + "${config.system.build.uki}/${config.system.boot.loader.ukiFile}"; + }; + repartConfig = { + Type = "esp"; + Format = "vfat"; + Label = "ESP"; + SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M"; + }; + }; + root = { + storePaths = [ config.system.build.toplevel ]; + repartConfig = { + Type = "root"; + Format = "ext4"; + Label = "nixos"; + Minimize = "guess"; + }; + }; + }; + }; + fileSystems = { "/" = { device = "/dev/disk/by-label/nixos";