at 25.11-pre 2.5 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 boolToStr = value: if value then "on" else "off"; 9 cfg = config.vmware; 10 11 subformats = [ 12 "monolithicSparse" 13 "monolithicFlat" 14 "twoGbMaxExtentSparse" 15 "twoGbMaxExtentFlat" 16 "streamOptimized" 17 ]; 18 19in 20{ 21 imports = [ 22 ../image/file-options.nix 23 (lib.mkRenamedOptionModuleWith { 24 sinceRelease = 2505; 25 from = [ 26 "virtualisation" 27 "vmware" 28 "vmFileName" 29 ]; 30 to = [ 31 "image" 32 "fileName" 33 ]; 34 }) 35 36 ]; 37 38 options = { 39 vmware = { 40 baseImageSize = lib.mkOption { 41 type = with lib.types; either (enum [ "auto" ]) int; 42 default = "auto"; 43 example = 2048; 44 description = '' 45 The size of the VMWare base image in MiB. 46 ''; 47 }; 48 vmDerivationName = lib.mkOption { 49 type = lib.types.str; 50 default = "nixos-vmware-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}"; 51 description = '' 52 The name of the derivation for the VMWare appliance. 53 ''; 54 }; 55 vmSubformat = lib.mkOption { 56 type = lib.types.enum subformats; 57 default = "monolithicSparse"; 58 description = "Specifies which VMDK subformat to use."; 59 }; 60 vmCompat6 = lib.mkOption { 61 type = lib.types.bool; 62 default = false; 63 example = true; 64 description = "Create a VMDK version 6 image (instead of version 4)."; 65 }; 66 }; 67 }; 68 69 config = { 70 system.nixos.tags = [ "vmware" ]; 71 image.extension = "vmdk"; 72 system.build.image = config.system.build.vmwareImage; 73 system.build.vmwareImage = import ../../lib/make-disk-image.nix { 74 name = cfg.vmDerivationName; 75 baseName = config.image.baseName; 76 postVM = '' 77 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o compat6=${boolToStr cfg.vmCompat6},subformat=${cfg.vmSubformat} -O vmdk $diskImage $out/${config.image.fileName} 78 rm $diskImage 79 ''; 80 format = "raw"; 81 diskSize = cfg.baseImageSize; 82 partitionTableType = "efi"; 83 inherit config lib pkgs; 84 }; 85 86 fileSystems."/" = { 87 device = "/dev/disk/by-label/nixos"; 88 autoResize = true; 89 fsType = "ext4"; 90 }; 91 92 fileSystems."/boot" = { 93 device = "/dev/disk/by-label/ESP"; 94 fsType = "vfat"; 95 }; 96 97 boot.growPartition = true; 98 99 boot.loader.grub = { 100 device = "nodev"; 101 efiSupport = true; 102 efiInstallAsRemovable = true; 103 }; 104 105 virtualisation.vmware.guest.enable = true; 106 }; 107}