2020-03-05 04:17:23 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hyperv;
|
2024-09-10 01:12:55 +00:00
|
|
|
in
|
|
|
|
{
|
2024-09-10 17:14:43 +00:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
./disk-size-option.nix
|
|
|
|
(lib.mkRenamedOptionModuleWith {
|
|
|
|
sinceRelease = 2411;
|
|
|
|
from = [
|
|
|
|
"hyperv"
|
|
|
|
"baseImageSize"
|
|
|
|
];
|
|
|
|
to = [
|
|
|
|
"virtualisation"
|
|
|
|
"diskSize"
|
|
|
|
];
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2020-03-05 04:17:23 +00:00
|
|
|
options = {
|
|
|
|
hyperv = {
|
|
|
|
vmDerivationName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nixos-hyperv-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
|
|
|
|
description = ''
|
|
|
|
The name of the derivation for the hyper-v appliance.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vmFileName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.vhdx";
|
|
|
|
description = ''
|
|
|
|
The file name of the hyper-v appliance.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-09-10 17:14:43 +00:00
|
|
|
# Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault
|
|
|
|
# to avoid breaking existing configs using that.
|
|
|
|
virtualisation.diskSize = lib.mkOverride 1490 (4 * 1024);
|
|
|
|
|
2020-03-05 04:17:23 +00:00
|
|
|
system.build.hypervImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = cfg.vmDerivationName;
|
|
|
|
postVM = ''
|
|
|
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o subformat=dynamic -O vhdx $diskImage $out/${cfg.vmFileName}
|
2020-05-20 23:34:41 +00:00
|
|
|
rm $diskImage
|
2020-03-05 04:17:23 +00:00
|
|
|
'';
|
|
|
|
format = "raw";
|
2024-09-10 17:14:43 +00:00
|
|
|
inherit (config.virtualisation) diskSize;
|
2020-03-05 04:17:23 +00:00
|
|
|
partitionTableType = "efi";
|
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems."/" = {
|
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
autoResize = true;
|
|
|
|
fsType = "ext4";
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems."/boot" = {
|
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
|
|
|
boot.growPartition = true;
|
|
|
|
|
|
|
|
boot.loader.grub = {
|
|
|
|
device = "nodev";
|
|
|
|
efiSupport = true;
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.hypervGuest.enable = true;
|
|
|
|
};
|
|
|
|
}
|