at 25.11-pre 2.1 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7 8with lib; 9 10let 11 cfg = config.hyperv; 12in 13{ 14 15 imports = [ 16 ./disk-size-option.nix 17 ../image/file-options.nix 18 (lib.mkRenamedOptionModuleWith { 19 sinceRelease = 2411; 20 from = [ 21 "hyperv" 22 "baseImageSize" 23 ]; 24 to = [ 25 "virtualisation" 26 "diskSize" 27 ]; 28 }) 29 (lib.mkRenamedOptionModuleWith { 30 sinceRelease = 2505; 31 from = [ 32 "virtualisation" 33 "hyperv" 34 "vmFileName" 35 ]; 36 to = [ 37 "image" 38 "fileName" 39 ]; 40 }) 41 ]; 42 43 options = { 44 hyperv = { 45 vmDerivationName = mkOption { 46 type = types.str; 47 default = "nixos-hyperv-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}"; 48 description = '' 49 The name of the derivation for the hyper-v appliance. 50 ''; 51 }; 52 }; 53 }; 54 55 config = { 56 # Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault 57 # to avoid breaking existing configs using that. 58 virtualisation.diskSize = lib.mkOverride 1490 (4 * 1024); 59 60 system.nixos.tags = [ "hyperv" ]; 61 image.extension = "vhdx"; 62 system.build.image = config.system.build.hypervImage; 63 system.build.hypervImage = import ../../lib/make-disk-image.nix { 64 name = cfg.vmDerivationName; 65 baseName = config.image.baseName; 66 postVM = '' 67 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o subformat=dynamic -O vhdx $diskImage $out/${config.image.fileName} 68 rm $diskImage 69 ''; 70 format = "raw"; 71 inherit (config.virtualisation) diskSize; 72 partitionTableType = "efi"; 73 inherit config lib pkgs; 74 }; 75 76 fileSystems."/" = { 77 device = "/dev/disk/by-label/nixos"; 78 autoResize = true; 79 fsType = "ext4"; 80 }; 81 82 fileSystems."/boot" = { 83 device = "/dev/disk/by-label/ESP"; 84 fsType = "vfat"; 85 }; 86 87 boot.growPartition = true; 88 89 boot.loader.grub = { 90 device = "nodev"; 91 efiSupport = true; 92 efiInstallAsRemovable = true; 93 }; 94 95 virtualisation.hypervGuest.enable = true; 96 }; 97}