59 lines
1.6 KiB
Nix
59 lines
1.6 KiB
Nix
let
|
|
gpuIDs = [
|
|
"1002:744c" # Graphics
|
|
"1002:ab30" # Audio
|
|
];
|
|
in
|
|
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}: {
|
|
options.vfio.enable = with lib;
|
|
mkEnableOption "Configure the machine for VFIO";
|
|
|
|
config = let
|
|
cfg = config.vfio;
|
|
in {
|
|
boot = {
|
|
kernelModules = ["kvm-amd" "vfio_pci" "vfio" "vfio_iommu_type1" "kvmfr"];
|
|
extraModulePackages = with config.boot.kernelPackages; [
|
|
# Until https://github.com/NixOS/nixpkgs/pull/305018 is merged.
|
|
(pkgs.linuxPackages_latest.kvmfr.overrideAttrs({ ... }: {
|
|
patches = [];
|
|
}))
|
|
];
|
|
extraModprobeConfig = ''
|
|
# The memory size is calculates in the same way as VM's shmem.
|
|
options kvmfr static_size_mb=64
|
|
'';
|
|
|
|
kernelParams = [
|
|
"amd_iommu=on"
|
|
"pcie_acs_override=downstream,multifunction"
|
|
"vfio-pci.ids=1002:744c,1002:ab30"
|
|
"pcie_aspm=off"
|
|
];
|
|
};
|
|
services.udev.extraRules = ''
|
|
SUBSYSTEM=="kvmfr", OWNER="gsimmer", GROUP="kvm", MODE="0660"
|
|
'';
|
|
hardware.opengl.enable = true;
|
|
virtualisation.spiceUSBRedirection.enable = true;
|
|
virtualisation.libvirtd = {
|
|
qemu = {
|
|
verbatimConfig = ''
|
|
cgroup_device_acl = [
|
|
"/dev/null", "/dev/full", "/dev/zero",
|
|
"/dev/random", "/dev/urandom",
|
|
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
|
|
"/dev/rtc","/dev/hpet", "/dev/vfio/vfio",
|
|
"/dev/kvmfr0"
|
|
]
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|