at 24.11-pre 1.7 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.hyperv; 7 8in { 9 options = { 10 hyperv = { 11 baseImageSize = mkOption { 12 type = with types; either (enum [ "auto" ]) int; 13 default = "auto"; 14 example = 2048; 15 description = '' 16 The size of the hyper-v base image in MiB. 17 ''; 18 }; 19 vmDerivationName = mkOption { 20 type = types.str; 21 default = "nixos-hyperv-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}"; 22 description = '' 23 The name of the derivation for the hyper-v appliance. 24 ''; 25 }; 26 vmFileName = mkOption { 27 type = types.str; 28 default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.vhdx"; 29 description = '' 30 The file name of the hyper-v appliance. 31 ''; 32 }; 33 }; 34 }; 35 36 config = { 37 system.build.hypervImage = import ../../lib/make-disk-image.nix { 38 name = cfg.vmDerivationName; 39 postVM = '' 40 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o subformat=dynamic -O vhdx $diskImage $out/${cfg.vmFileName} 41 rm $diskImage 42 ''; 43 format = "raw"; 44 diskSize = cfg.baseImageSize; 45 partitionTableType = "efi"; 46 inherit config lib pkgs; 47 }; 48 49 fileSystems."/" = { 50 device = "/dev/disk/by-label/nixos"; 51 autoResize = true; 52 fsType = "ext4"; 53 }; 54 55 fileSystems."/boot" = { 56 device = "/dev/disk/by-label/ESP"; 57 fsType = "vfat"; 58 }; 59 60 boot.growPartition = true; 61 62 boot.loader.grub = { 63 device = "nodev"; 64 efiSupport = true; 65 efiInstallAsRemovable = true; 66 }; 67 68 virtualisation.hypervGuest.enable = true; 69 }; 70}