2024-12-20 13:11:42 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
enableIOMMU = true;
|
2024-11-22 19:51:14 +00:00
|
|
|
in {
|
|
|
|
boot = lib.mkIf enableIOMMU {
|
2024-12-20 13:11:42 +00:00
|
|
|
initrd.kernelModules = lib.mkBefore [
|
|
|
|
"kvm-amd"
|
|
|
|
"vfio_pci"
|
|
|
|
"vfio_iommu_type1"
|
|
|
|
"vfio"
|
2024-10-28 15:18:56 +00:00
|
|
|
];
|
2024-11-16 22:07:01 +00:00
|
|
|
kernelParams = [
|
2024-10-28 15:18:56 +00:00
|
|
|
"amd_iommu=on"
|
|
|
|
"amd_iommu=pt"
|
|
|
|
"kvm.ignore_msrs=1"
|
|
|
|
"vfio-pci.ids=1002:67df,1002:aaf0"
|
|
|
|
];
|
|
|
|
extraModprobeConfig = ''
|
|
|
|
softdep drm pre: vfio-pci
|
2024-11-16 22:07:01 +00:00
|
|
|
options kvm_amd nested=1
|
|
|
|
options kvm ignore_msrs=1 report_ignored_msrs=0
|
2024-10-28 15:18:56 +00:00
|
|
|
'';
|
2024-10-28 11:19:32 +00:00
|
|
|
};
|
|
|
|
|
2024-11-16 22:07:01 +00:00
|
|
|
hardware.ksm.enable = true;
|
|
|
|
|
2024-10-28 11:19:32 +00:00
|
|
|
virtualisation = {
|
|
|
|
libvirtd = {
|
|
|
|
enable = true;
|
|
|
|
onBoot = "ignore";
|
|
|
|
onShutdown = "shutdown";
|
|
|
|
|
2024-10-28 15:18:56 +00:00
|
|
|
qemu = {
|
|
|
|
package = pkgs.qemu_kvm;
|
|
|
|
ovmf.enable = true;
|
|
|
|
};
|
2024-10-28 11:19:32 +00:00
|
|
|
};
|
|
|
|
|
2024-12-20 13:11:42 +00:00
|
|
|
docker = {enable = true;};
|
2024-10-28 11:19:32 +00:00
|
|
|
};
|
|
|
|
|
2024-12-20 13:11:42 +00:00
|
|
|
programs = {virt-manager = {enable = true;};};
|
2024-10-28 15:59:07 +00:00
|
|
|
|
2024-12-20 13:11:42 +00:00
|
|
|
users.users.pingu.extraGroups = ["qemu-libvirtd" "libvirtd" "disk" "kvm" "docker"];
|
2024-10-28 15:18:56 +00:00
|
|
|
|
2024-10-28 11:19:32 +00:00
|
|
|
environment.systemPackages = with pkgs; [
|
2024-11-16 22:07:01 +00:00
|
|
|
python3 # scripts, cba to use nix shell all the time
|
|
|
|
usbutils
|
|
|
|
pciutils
|
2024-10-28 11:19:32 +00:00
|
|
|
virt-manager
|
2024-11-16 22:07:01 +00:00
|
|
|
moonlight-qt # for linux vms
|
2025-01-01 13:55:38 +00:00
|
|
|
# looking-glass-client # for windows vms :husk:
|
2024-10-28 11:19:32 +00:00
|
|
|
];
|
|
|
|
}
|