Using Nvidia Prime inside nixos build-vm

Hello,

I’m trying to test hyprland in a VM but when running the vm produced by nixos-rebuild build-vm the gpu does not make it through (unsurprising).

Host:

❯ lspci -k | grep -EA3 'VGA|3D|Display'

00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P GT2 [Iris Xe Graphics] (rev 0c)
        Subsystem: Lenovo Device 22ea
        Kernel driver in use: i915
        Kernel modules: i915
--
03:00.0 3D controller: NVIDIA Corporation TU117GLM [T550 Laptop GPU] (rev a1)
        Subsystem: Lenovo Device 22ea
        Kernel driver in use: nouveau
        Kernel modules: nvidiafb, nouveau

build-vm:

❯ lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Device 1234:1111 (rev 02)
        Subsystem: Red Hat, Inc. Device 1100
        Kernel driver in use: bochs-drm
        Kernel modules: bochs

Does anyone know how I can get an equivalent GPU in the build-vm QEMU or a pass through so I can test?

The two options here are VFIO and virtio-gpu.

With VFIO, you have to configure your host to not use the GPU at all and pass the hardware to the VM directly. That means you can’t use the GPU on the host at all.

virtio-gpu is more like a software passthrough. But the guest drivers for this are rather incomplete and I have no idea how to set it up.

Okay, virtio-gpu sounds like what I need, thanks. Hopefully someone will see this who knows

I will reiterate, virtio-gpu guest drivers are rather incomplete. I would have very low expectations of its capability.