at 25.11-pre 1.5 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.image; 9in 10{ 11 imports = [ 12 ./disk-size-option.nix 13 ../image/file-options.nix 14 ]; 15 16 options.image = { 17 format = lib.mkOption { 18 description = "Format of the disk image to generate: raw or qcow2"; 19 type = lib.types.enum [ 20 "raw" 21 "qcow2" 22 ]; 23 default = "qcow2"; 24 }; 25 efiSupport = lib.mkOption { 26 description = "Whether the disk image should support EFI boot or legacy boot"; 27 type = lib.types.bool; 28 default = true; 29 }; 30 }; 31 32 config = { 33 boot.loader.grub = lib.mkIf (!cfg.efiSupport) { 34 enable = lib.mkOptionDefault true; 35 devices = lib.mkDefault [ "/dev/vda" ]; 36 }; 37 boot.loader.systemd-boot.enable = lib.mkDefault cfg.efiSupport; 38 boot.growPartition = lib.mkDefault true; 39 40 fileSystems = { 41 "/" = { 42 device = "/dev/disk/by-label/nixos"; 43 autoResize = true; 44 fsType = "ext4"; 45 }; 46 "/boot" = lib.mkIf (cfg.efiSupport) { 47 device = "/dev/disk/by-label/ESP"; 48 fsType = "vfat"; 49 }; 50 }; 51 52 system.nixos.tags = [ cfg.format ] ++ lib.optionals cfg.efiSupport [ "efi" ]; 53 image.extension = cfg.format; 54 system.build.image = import ../../lib/make-disk-image.nix { 55 inherit lib config pkgs; 56 inherit (config.virtualisation) diskSize; 57 inherit (cfg) baseName format; 58 partitionTableType = if cfg.efiSupport then "efi" else "legacy"; 59 }; 60 }; 61}