1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.virtualisation.hypervGuest;
12
13in
14{
15 imports = [
16 (mkRemovedOptionModule [
17 "virtualisation"
18 "hypervGuest"
19 "videoMode"
20 ] "The video mode can now be configured via standard tools, or in Hyper-V VM settings.")
21 ];
22
23 options = {
24 virtualisation.hypervGuest = {
25 enable = mkEnableOption "Hyper-V Guest Support";
26 };
27 };
28
29 config = mkIf cfg.enable {
30 boot = {
31 initrd.kernelModules = [
32 "hv_balloon"
33 "hv_netvsc"
34 "hv_storvsc"
35 "hv_utils"
36 "hv_vmbus"
37 ];
38
39 initrd.availableKernelModules = [ "hyperv_keyboard" ];
40
41 kernelParams = [
42 "elevator=noop"
43 ];
44 };
45
46 environment.systemPackages = [ config.boot.kernelPackages.hyperv-daemons.bin ];
47
48 # enable hotadding cpu/memory
49 services.udev.packages = lib.singleton (
50 pkgs.writeTextFile {
51 name = "hyperv-cpu-and-memory-hotadd-udev-rules";
52 destination = "/etc/udev/rules.d/99-hyperv-cpu-and-memory-hotadd.rules";
53 text = ''
54 # Memory hotadd
55 SUBSYSTEM=="memory", ACTION=="add", DEVPATH=="/devices/system/memory/memory[0-9]*", TEST=="state", ATTR{state}="online"
56
57 # CPU hotadd
58 SUBSYSTEM=="cpu", ACTION=="add", DEVPATH=="/devices/system/cpu/cpu[0-9]*", TEST=="online", ATTR{online}="1"
59 '';
60 }
61 );
62
63 systemd = {
64 packages = [ config.boot.kernelPackages.hyperv-daemons.lib ];
65
66 targets.hyperv-daemons = {
67 wantedBy = [ "multi-user.target" ];
68 };
69 };
70 };
71}