From baa2417bfe4beffb3f79254652e69bbdd0b370f4 Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Sat, 11 Nov 2023 17:11:44 +0000 Subject: [PATCH] vfio fuckery based on https://astrid.tech/2022/09/22/0/nixos-gpu-vfio/ --- nix/london/configuration.nix | 3 +++ nix/london/vfio.nix | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 nix/london/vfio.nix diff --git a/nix/london/configuration.nix b/nix/london/configuration.nix index a9c336a..f8ed971 100644 --- a/nix/london/configuration.nix +++ b/nix/london/configuration.nix @@ -4,8 +4,11 @@ imports = [ ./hardware-configuration.nix + ./vfio.nix ]; + vfio.enable = true; + # Bootloader boot = { loader = { diff --git a/nix/london/vfio.nix b/nix/london/vfio.nix new file mode 100644 index 0000000..1f6025f --- /dev/null +++ b/nix/london/vfio.nix @@ -0,0 +1,37 @@ +let + # RTX 3070 Ti + gpuIDs = [ + "10de:1b81" # Graphics + "10de:10f0" # Audio + ]; +in { pkgs, lib, config, ... }: { + options.vfio.enable = with lib; + mkEnableOption "Configure the machine for VFIO"; + + config = let cfg = config.vfio; + in { + boot = { + initrd.kernelModules = [ + "vfio_pci" + "vfio" + "vfio_iommu_type1" + + "nvidia" + "nvidia_modeset" + "nvidia_uvm" + "nvidia_drm" + ]; + + kernelParams = [ + # enable IOMMU + "amd_iommu=on" + "pcie_acs_override=downstream,multifunction" + ] ++ lib.optional cfg.enable + # isolate the GPU + ("vfio-pci.ids=" + lib.concatStringsSep "," gpuIDs); + }; + + hardware.opengl.enable = true; + virtualisation.spiceUSBRedirection.enable = true; + }; +}