|
41 | 41 | }; |
42 | 42 | }; |
43 | 43 |
|
44 | | - config = { |
45 | | - # Host kernel configuration |
46 | | - boot = optionalAttrs fullVirtualization { |
47 | | - initrd = { |
48 | | - inherit (config.ghaf.hardware.definition.host.kernelConfig.stage1) kernelModules; |
| 44 | + options.ghaf.host.kernel.memory-wipe = { |
| 45 | + enable = lib.mkEnableOption "Memory wipe on boot and free using kernel configuration (host only)"; |
| 46 | + }; |
| 47 | + |
| 48 | + config = lib.mkMerge [ |
| 49 | + # Memory wipe kernel patches (applies to host only) |
| 50 | + { |
| 51 | + boot.kernelPatches = lib.optionals config.ghaf.host.kernel.memory-wipe.enable [ |
| 52 | + { |
| 53 | + name = "memory-wipe-config"; |
| 54 | + patch = null; |
| 55 | + structuredExtraConfig = with lib.kernel; { |
| 56 | + # Enable page poisoning for additional security |
| 57 | + PAGE_POISONING = yes; |
| 58 | + |
| 59 | + # Enable init-on-alloc and init-on-free support |
| 60 | + INIT_ON_ALLOC_DEFAULT_ON = option yes; |
| 61 | + INIT_ON_FREE_DEFAULT_ON = option yes; |
| 62 | + }; |
| 63 | + } |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
| 67 | + # Host kernel configuration (only for full virtualization) |
| 68 | + { |
| 69 | + boot = optionalAttrs fullVirtualization { |
| 70 | + initrd = { |
| 71 | + inherit (config.ghaf.hardware.definition.host.kernelConfig.stage1) kernelModules; |
| 72 | + }; |
| 73 | + inherit (config.ghaf.hardware.definition.host.kernelConfig.stage2) kernelModules; |
| 74 | + kernelParams = |
| 75 | + let |
| 76 | + # PCI device passthroughs for vfio |
| 77 | + filterDevices = builtins.filter (d: d.vendorId != null && d.productId != null); |
| 78 | + mapPciIdsToString = map (d: "${d.vendorId}:${d.productId}"); |
| 79 | + vfioPciIds = mapPciIdsToString ( |
| 80 | + filterDevices ( |
| 81 | + config.ghaf.hardware.definition.network.pciDevices |
| 82 | + ++ config.ghaf.hardware.definition.gpu.pciDevices |
| 83 | + ++ config.ghaf.hardware.definition.audio.pciDevices |
| 84 | + ) |
| 85 | + ); |
| 86 | + in |
| 87 | + config.ghaf.hardware.definition.host.kernelConfig.kernelParams |
| 88 | + ++ [ "vfio-pci.ids=${builtins.concatStringsSep "," vfioPciIds}" ]; |
49 | 89 | }; |
50 | | - inherit (config.ghaf.hardware.definition.host.kernelConfig.stage2) kernelModules; |
51 | | - kernelParams = |
52 | | - let |
53 | | - # PCI device passthroughs for vfio |
54 | | - filterDevices = builtins.filter (d: d.vendorId != null && d.productId != null); |
55 | | - mapPciIdsToString = map (d: "${d.vendorId}:${d.productId}"); |
56 | | - vfioPciIds = mapPciIdsToString ( |
57 | | - filterDevices ( |
58 | | - config.ghaf.hardware.definition.network.pciDevices |
59 | | - ++ config.ghaf.hardware.definition.gpu.pciDevices |
60 | | - ++ config.ghaf.hardware.definition.audio.pciDevices |
61 | | - ) |
62 | | - ); |
63 | | - in |
64 | | - config.ghaf.hardware.definition.host.kernelConfig.kernelParams |
65 | | - ++ [ "vfio-pci.ids=${builtins.concatStringsSep "," vfioPciIds}" ]; |
66 | | - }; |
| 90 | + } |
67 | 91 |
|
68 | 92 | # Guest kernel configurations |
69 | | - ghaf.kernel = optionalAttrs fullVirtualization { |
70 | | - guivm = { |
71 | | - boot = { |
72 | | - initrd = { |
73 | | - inherit (config.ghaf.hardware.definition.gpu.kernelConfig.stage1) kernelModules; |
| 93 | + { |
| 94 | + ghaf.kernel = optionalAttrs fullVirtualization { |
| 95 | + guivm = { |
| 96 | + boot = { |
| 97 | + initrd = { |
| 98 | + inherit (config.ghaf.hardware.definition.gpu.kernelConfig.stage1) kernelModules; |
| 99 | + }; |
| 100 | + inherit (config.ghaf.hardware.definition.gpu.kernelConfig.stage2) kernelModules; |
| 101 | + inherit (config.ghaf.hardware.definition.gpu.kernelConfig) kernelParams; |
74 | 102 | }; |
75 | | - inherit (config.ghaf.hardware.definition.gpu.kernelConfig.stage2) kernelModules; |
76 | | - inherit (config.ghaf.hardware.definition.gpu.kernelConfig) kernelParams; |
77 | 103 | }; |
78 | | - }; |
79 | | - audiovm = { |
80 | | - boot = { |
81 | | - initrd = { |
82 | | - inherit (config.ghaf.hardware.definition.audio.kernelConfig.stage1) kernelModules; |
| 104 | + audiovm = { |
| 105 | + boot = { |
| 106 | + initrd = { |
| 107 | + inherit (config.ghaf.hardware.definition.audio.kernelConfig.stage1) kernelModules; |
| 108 | + }; |
| 109 | + inherit (config.ghaf.hardware.definition.audio.kernelConfig.stage2) kernelModules; |
| 110 | + inherit (config.ghaf.hardware.definition.audio.kernelConfig) kernelParams; |
83 | 111 | }; |
84 | | - inherit (config.ghaf.hardware.definition.audio.kernelConfig.stage2) kernelModules; |
85 | | - inherit (config.ghaf.hardware.definition.audio.kernelConfig) kernelParams; |
86 | 112 | }; |
87 | | - }; |
88 | | - netvm = { |
89 | | - boot = { |
90 | | - initrd = { |
91 | | - inherit (config.ghaf.hardware.definition.network.kernelConfig.stage1) kernelModules; |
| 113 | + netvm = { |
| 114 | + boot = { |
| 115 | + initrd = { |
| 116 | + inherit (config.ghaf.hardware.definition.network.kernelConfig.stage1) kernelModules; |
| 117 | + }; |
| 118 | + inherit (config.ghaf.hardware.definition.network.kernelConfig.stage2) kernelModules; |
| 119 | + inherit (config.ghaf.hardware.definition.network.kernelConfig) kernelParams; |
92 | 120 | }; |
93 | | - inherit (config.ghaf.hardware.definition.network.kernelConfig.stage2) kernelModules; |
94 | | - inherit (config.ghaf.hardware.definition.network.kernelConfig) kernelParams; |
95 | 121 | }; |
96 | 122 | }; |
97 | | - }; |
98 | | - }; |
| 123 | + } |
| 124 | + ]; |
99 | 125 | } |
0 commit comments