-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add existing modules by @CRTified and remove staticfiles
- Loading branch information
Showing
8 changed files
with
145 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
{ | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
cfg = config.virtualisation.libvirtd; | ||
|
||
boolToZeroOne = x: if x then "1" else "0"; | ||
|
||
aclString = with lib.strings; | ||
concatMapStringsSep '' | ||
, | ||
'' escapeNixString cfg.deviceACL; | ||
in { | ||
imports = [ | ||
./hooks.nix | ||
./scopedHooks.nix | ||
./qemuGuests.nix | ||
]; | ||
|
||
options.virtualisation.libvirtd = { | ||
deviceACL = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
}; | ||
clearEmulationCapabilities = mkOption { | ||
type = types.bool; | ||
default = true; | ||
}; | ||
}; | ||
|
||
# Add qemu-libvirtd to the input group if required | ||
config.users.users."qemu-libvirtd" = { | ||
extraGroups = optionals (!cfg.qemu.runAsRoot) [ "kvm" "input" ]; | ||
isSystemUser = true; | ||
}; | ||
|
||
config.virtualisation.libvirtd.qemu.verbatimConfig = '' | ||
clear_emulation_capabilities = ${ | ||
boolToZeroOne cfg.clearEmulationCapabilities | ||
} | ||
cgroup_device_acl = [ | ||
${aclString} | ||
] | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
cfg = config.virtualisation.vfio; | ||
in { | ||
options.virtualisation.vfio = { | ||
enable = mkEnableOption "VFIO Configuration"; | ||
IOMMUType = mkOption { | ||
type = types.enum [ "intel" "amd" ]; | ||
example = "intel"; | ||
description = "Type of the IOMMU used"; | ||
}; | ||
devices = mkOption { | ||
type = types.listOf (types.strMatching "[0-9a-f]{4}:[0-9a-f]{4}"); | ||
default = [ ]; | ||
example = [ "10de:1b80" "10de:10f0" ]; | ||
description = "PCI IDs of devices to bind to vfio-pci"; | ||
}; | ||
disableEFIfb = mkOption { | ||
type = types.bool; | ||
default = false; | ||
example = true; | ||
description = "Disables the usage of the EFI framebuffer on boot."; | ||
}; | ||
blacklistNvidia = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Add Nvidia GPU modules to blacklist"; | ||
}; | ||
ignoreMSRs = mkOption { | ||
type = types.bool; | ||
default = false; | ||
example = true; | ||
description = | ||
"Enables or disables kvm guest access to model-specific registers"; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
services.udev.extraRules = '' | ||
SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm" | ||
''; | ||
|
||
boot.kernelParams = (if cfg.IOMMUType == "intel" then [ | ||
"intel_iommu=on" | ||
"intel_iommu=igfx_off" | ||
] else | ||
[ "amd_iommu=on" ]) ++ (optional (builtins.length cfg.devices > 0) | ||
("vfio-pci.ids=" + builtins.concatStringsSep "," cfg.devices)) | ||
++ (optional cfg.disableEFIfb "video=efifb:off") | ||
++ (optionals cfg.ignoreMSRs [ | ||
"kvm.ignore_msrs=1" | ||
"kvm.report_ignored_msrs=0" | ||
]); | ||
|
||
boot.kernelModules = [ "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" ]; | ||
|
||
boot.initrd.kernelModules = | ||
[ "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" ]; | ||
boot.blacklistedKernelModules = | ||
optionals cfg.blacklistNvidia [ "nvidia" "nouveau" ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
cfg = config.virtualisation; | ||
in { | ||
options.virtualisation = { | ||
hugepages = { | ||
enable = mkEnableOption "Hugepages"; | ||
|
||
defaultPageSize = mkOption { | ||
type = types.strMatching "[0-9]*[kKmMgG]"; | ||
default = "1M"; | ||
description = | ||
"Default size of huge pages. You can use suffixes K, M, and G to specify KB, MB, and GB."; | ||
}; | ||
pageSize = mkOption { | ||
type = types.strMatching "[0-9]*[kKmMgG]"; | ||
default = "1M"; | ||
description = | ||
"Size of huge pages that are allocated at boot. You can use suffixes K, M, and G to specify KB, MB, and GB."; | ||
}; | ||
numPages = mkOption { | ||
type = types.ints.positive; | ||
default = 1; | ||
description = "Number of huge pages to allocate at boot."; | ||
}; | ||
}; | ||
}; | ||
|
||
config.boot.kernelParams = optionals cfg.hugepages.enable [ | ||
"default_hugepagesz=${cfg.hugepages.defaultPageSize}" | ||
"hugepagesz=${cfg.hugepages.pageSize}" | ||
"hugepages=${toString cfg.hugepages.numPages}" | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters