feat: working gpu passthrough \o/
This commit is contained in:
parent
964b99b28d
commit
c140a12e66
9 changed files with 391 additions and 2 deletions
|
@ -23,13 +23,21 @@
|
|||
|
||||
./users.nix
|
||||
./user-system-config.nix
|
||||
|
||||
./vm.nix
|
||||
];
|
||||
|
||||
vfio = {
|
||||
enable = true;
|
||||
earlyKMS = true;
|
||||
applyACSpatch = true;
|
||||
};
|
||||
|
||||
# Allows referring to this flake by the shorthand `nixos-config`, which lets you do e.g.
|
||||
# nix repl nixos-config
|
||||
nix.registry.nixos-config.to = {
|
||||
type = "git";
|
||||
url = "file://${config.users.users.evar.home}/dev/nix/config";
|
||||
url = "file://${config.users.users.evar.home}/git/nixos-framework-laptop-config";
|
||||
};
|
||||
|
||||
# In order to catch all logs, we need to mount this early enough in the boot process.
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"/var/lib/fprint"
|
||||
"/var/lib/upower"
|
||||
"/var/lib/tailscale"
|
||||
"/var/lib/libvirt"
|
||||
"/var/lib/systemd/coredump"
|
||||
"/etc/NetworkManager/system-connections"
|
||||
"/var/lib/iwd" # Known networks and keys
|
||||
|
|
72
nixos/vm.nix
Normal file
72
nixos/vm.nix
Normal file
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
gpuIDs = [
|
||||
"1002:7480" # Graphics
|
||||
"1002:ab30" # Audio
|
||||
"1022:15c0" # Top Right physical USB C port
|
||||
];
|
||||
in {
|
||||
options.vfio.enable = with lib;
|
||||
mkEnableOption "Configure the machine for VFIO";
|
||||
|
||||
options.vfio.earlyKMS = with lib;
|
||||
mkEnableOption "Configure the machine to load the GPU driver during initramfs";
|
||||
|
||||
options.vfio.applyACSpatch = with lib;
|
||||
mkEnableOption
|
||||
''If set, the following things will happen:
|
||||
- The ACS override patch is applied
|
||||
- Applies the i915-vga-arbiter patch
|
||||
- Adds pcie_acs_override=downstream to the command line
|
||||
'';
|
||||
|
||||
config = let cfg = config.vfio;
|
||||
in {
|
||||
networking.bridges = {
|
||||
"winvm0" = {
|
||||
interfaces = [ "eth0" ];
|
||||
};
|
||||
};
|
||||
networking.interfaces.eth0.useDHCP = true;
|
||||
networking.interfaces.winvm0.useDHCP = true;
|
||||
|
||||
programs.virt-manager.enable = true;
|
||||
users.groups.libvirtd.members = ["evar"];
|
||||
hardware.graphics.enable = true;
|
||||
virtualisation.libvirtd.enable = true;
|
||||
virtualisation.libvirtd.qemu.swtpm.enable = true; # for TPM 2.0 support
|
||||
virtualisation.spiceUSBRedirection.enable = true;
|
||||
|
||||
boot = {
|
||||
initrd.kernelModules = [
|
||||
"vfio_pci"
|
||||
"vfio"
|
||||
"vfio_iommu_type1"
|
||||
# "vfio_virqfd" # This is apparently a part of the kernel now
|
||||
] ++ lib.optional cfg.earlyKMS "amdgpu";
|
||||
|
||||
# kernelPatches = [] ++ lib.optional cfg.applyACSpatch
|
||||
# {
|
||||
# name = "add-acs-overrides";
|
||||
# patch = pkgs.fetchurl {
|
||||
# name = "add-acs-overrides.patch";
|
||||
# url = "https://aur.archlinux.org/cgit/aur.git/plain/1001-6.8.0-add-acs-overrides.patch?h=linux-vfio";
|
||||
# sha256 = "1qd68s9r0ppynksbffqn2qbp1whqpbfp93dpccp9griwhx5srx6v";
|
||||
# };
|
||||
# };
|
||||
|
||||
kernelParams = [
|
||||
# enable IOMMU
|
||||
"amd_iommu=on"
|
||||
] ++ lib.optional cfg.enable
|
||||
# isolate the GPU
|
||||
("vfio-pci.ids=" + lib.concatStringsSep "," gpuIDs);
|
||||
# ++ lib.optional cfg.applyACSpatch "pcie_acs_override=downstream,multifunction";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue