2017-04-07 09:40:17 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.hypervGuest;
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
virtualisation.hypervGuest = {
|
|
|
|
enable = mkEnableOption "Hyper-V Guest Support";
|
2018-09-28 14:10:03 +00:00
|
|
|
|
|
|
|
videoMode = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "1152x864";
|
|
|
|
example = "1024x768";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-09-28 14:10:03 +00:00
|
|
|
Resolution at which to initialize the video adapter.
|
|
|
|
|
|
|
|
Supports screen resolution up to Full HD 1920x1080 with 32 bit color
|
|
|
|
on Windows Server 2012, and 1600x1200 with 16 bit color on Windows
|
|
|
|
Server 2008 R2 or earlier.
|
|
|
|
'';
|
|
|
|
};
|
2017-04-07 09:40:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-09-28 14:10:03 +00:00
|
|
|
boot = {
|
|
|
|
initrd.kernelModules = [
|
|
|
|
"hv_balloon" "hv_netvsc" "hv_storvsc" "hv_utils" "hv_vmbus"
|
|
|
|
];
|
|
|
|
|
2021-02-08 12:05:15 +00:00
|
|
|
initrd.availableKernelModules = [ "hyperv_keyboard" ];
|
|
|
|
|
2018-09-28 14:10:03 +00:00
|
|
|
kernelParams = [
|
2021-10-18 18:22:53 +00:00
|
|
|
"video=hyperv_fb:${cfg.videoMode}" "elevator=noop"
|
2018-09-28 14:10:03 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-04-07 09:40:17 +00:00
|
|
|
environment.systemPackages = [ config.boot.kernelPackages.hyperv-daemons.bin ];
|
|
|
|
|
2018-09-28 14:27:52 +00:00
|
|
|
# enable hotadding cpu/memory
|
2017-04-07 09:40:17 +00:00
|
|
|
services.udev.packages = lib.singleton (pkgs.writeTextFile {
|
2018-09-28 14:27:52 +00:00
|
|
|
name = "hyperv-cpu-and-memory-hotadd-udev-rules";
|
|
|
|
destination = "/etc/udev/rules.d/99-hyperv-cpu-and-memory-hotadd.rules";
|
2017-04-07 09:40:17 +00:00
|
|
|
text = ''
|
2018-09-28 14:27:52 +00:00
|
|
|
# Memory hotadd
|
|
|
|
SUBSYSTEM=="memory", ACTION=="add", DEVPATH=="/devices/system/memory/memory[0-9]*", TEST=="state", ATTR{state}="online"
|
|
|
|
|
|
|
|
# CPU hotadd
|
|
|
|
SUBSYSTEM=="cpu", ACTION=="add", DEVPATH=="/devices/system/cpu/cpu[0-9]*", TEST=="online", ATTR{online}="1"
|
2017-04-07 09:40:17 +00:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
packages = [ config.boot.kernelPackages.hyperv-daemons.lib ];
|
|
|
|
|
2021-04-27 09:10:27 +00:00
|
|
|
services.hv-vss.unitConfig.ConditionPathExists = [ "/dev/vmbus/hv_vss" ];
|
|
|
|
|
2017-04-07 09:40:17 +00:00
|
|
|
targets.hyperv-daemons = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|