From e40595797825e70b16e01c848692fe09c21eb92b Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Tue, 1 Feb 2022 06:59:17 +0000 Subject: [PATCH] Add vfio on starlight --- system/starlight/default.nix | 1 + system/starlight/vfio.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 system/starlight/vfio.nix diff --git a/system/starlight/default.nix b/system/starlight/default.nix index b8a0a7c..d4976da 100644 --- a/system/starlight/default.nix +++ b/system/starlight/default.nix @@ -5,6 +5,7 @@ ./boot-config.nix ./hardware-configuration.nix ./scripts.nix + ./vfio.nix ../../sets/builder.nix ../../sets/cpu/amd.nix ../../sets/fpga.nix diff --git a/system/starlight/vfio.nix b/system/starlight/vfio.nix new file mode 100644 index 0000000..0f2fb2f --- /dev/null +++ b/system/starlight/vfio.nix @@ -0,0 +1,34 @@ +{ pkgs, pkgs-unstable, ... }: + +# based on https://alexbakker.me/post/nixos-pci-passthrough-qemu-vfio.html +{ + environment.systemPackages = [ + pkgs-unstable.looking-glass-client + pkgs.scream + ]; + + boot.initrd = { + availableKernelModules = [ "amdgpu" "vfio-pci" ]; + preDeviceCommands = '' + echo vfio-pci > /sys/bus/pci/devices/0000:0b:00.0/driver_override + echo vfio-pci > /sys/bus/pci/devices/0000:0b:00.1/driver_override + modprobe -i vfio-pci + ''; + }; + + systemd.tmpfiles.rules = [ + "f /dev/shm/scream 0660 artemis qemu-libvirtd -" + "f /dev/shm/looking-glass 0660 artemis qemu-libvirtd -" + ]; + + systemd.user.services.scream-ivshmem = { + enable = true; + description = "Scream IVSHMEM"; + serviceConfig = { + ExecStart = "${pkgs.scream}/bin/scream -m /dev/shm/scream -o pulse"; + Restart = "always"; + }; + wantedBy = [ "multi-user.target" ]; + requires = [ "pulseaudio.service" ]; + }; +}