Introduction
In this article, we will discuss how to enable GPU passthrough on a NixOS Linux host running a virtual machine using QEMU and virt-manager. This process is useful for those who want to use a powerful GPU in their NixOS guest VM.
Prerequisites
- NixOS Linux host with two GPUs
- QEMU and virt-manager installed on the NixOS host
- IOMMU groups configured for the GPUs
Configuring IOMMU Groups
Before enabling GPU passthrough, we need to ensure that the IOMMU groups for the GPUs are properly configured. This can be done by editing the /etc/nixos/configuration.nix file.
Add the following lines to the configuration file:
hardware.pci.iommu.groups = [
{ name = "gpu-group-0"; devices = [ "/pci@0000:01:00.0" ]; },
{ name = "gpu-group-1"; devices = [ "/pci@0000:02:00.0" ]; },
];
Replace "/pci@0000:01:00.0" and "/pci@0000:02:00.0" with the PCI addresses of your GPUs.
Enabling GPU Passthrough
Once the IOMMU groups are configured, we can enable GPU passthrough for the virtual machine. This can be done by editing the .vm.xml file of the virtual machine.
Add the following lines to the .vm.xml file:
Replace "0x03" and "0x04" with the PCI addresses of your GPUs.
Starting the Virtual Machine
After configuring the virtual machine, we can start it using virt-manager. Once the virtual machine is running, the GPUs will be passed through to the guest OS.
Verifying GPU Passthrough
To verify that GPU passthrough is working correctly, log into the guest OS and check the output of the lspci command. The GPUs should be listed under the "VGA compatible controller" section.