From 7c1e567f48da549fc624fc9838f26e79f92ffaac Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Sat, 1 Jul 2023 17:41:02 -0400 Subject: [PATCH] vifo config --- machines/levitation/configuration.nix | 3 +-- machines/levitation/passthrough.nix | 35 +++++++++++++++++++++++++++ modules/linux/virtualization.nix | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 machines/levitation/passthrough.nix diff --git a/machines/levitation/configuration.nix b/machines/levitation/configuration.nix index 49d9e10..9343176 100644 --- a/machines/levitation/configuration.nix +++ b/machines/levitation/configuration.nix @@ -6,6 +6,7 @@ let inherit system; }; in { + imports = [ ./passthrough.nix ]; # Sops setup for this machine sops.secrets = { "borg-ssh-key" = { @@ -79,8 +80,6 @@ in { allowedUDPPorts = [ 61377 1701 9001 ]; }; }; - # GPU passthrough - boot.kernelParams = [ "amd_iommu=on" ]; # Setup home manager home-manager.users.nathan = import ./home.nix; diff --git a/machines/levitation/passthrough.nix b/machines/levitation/passthrough.nix new file mode 100644 index 0000000..d4aca51 --- /dev/null +++ b/machines/levitation/passthrough.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, ... }: +let + gpuIDs = [ + # 2080 super + "10de:1e81" # Graphics + "10de:10f8" # Audio + "10de:1ad8" # Usb ???? + "10de:1ad9" # Usb ???? + ]; +in { + boot = { + kernelParams = [ + # enable iommu + "amd_iommu=on" + # Isolate the nvidia gpu + ("vfio-pci.ids=" + lib.concatStringsSep "," gpuIDs) + ]; + # Modules needed + initrd.kernelModules = [ "vfio_pci" "vfio" "vfio_iommu_type1" ]; + }; + + environment.systemPackages = with pkgs; [ looking-glass-client ]; + virtualisation.spiceUSBRedirection.enable = true; + virtualisation.libvirtd = { + qemu = { + swtpm.enable = true; + ovmf = { + enable = true; + packages = [ pkgs.OVMFFull.fd ]; + }; + }; + }; + systemd.tmpfiles.rules = + [ "f /dev/shm/looking-glass 0660 nathan qemu-libvirtd -" ]; +} diff --git a/modules/linux/virtualization.nix b/modules/linux/virtualization.nix index 19e2143..6023597 100644 --- a/modules/linux/virtualization.nix +++ b/modules/linux/virtualization.nix @@ -6,6 +6,7 @@ in with lib; { # Enable the kernel modules boot.kernelModules = [ "kvm-amd" "kvm-intel" ]; # Enable libvirt + programs.dconf.enable = true; virtualisation.libvirtd.enable = true; # Install virt-manager environment.systemPackages = with pkgs; [ virtmanager virt-viewer ];