Elgato 4K60 Capture Card on NixOS

This guide will allow you to use your Elgato 4K60 Capture Card on NixOS through a virtualised copy of Windows.

Prerequisites

Installation

Install the following packages. I use home-manager for this.

spice
spice-gtk
spice-protocol
virt-manager
virt-viewer
win-spice
win-virtio

Set the following settings in your NixOS configuration.

users.users.YourUsernameHere.extraGroups = [ "libvirtd" ];

virtualisation = {
    libvirtd = {
        enable = true;
        qemu = {
            swtpm.enable = true;
            ovmf.enable = true;
            ovmf.packages = with pkgs; [ OVMFFull.fd ];
            vhostUserPackages = with pkgs; [ virtiofsd ];
        };
    };
    spiceUSBRedirection.enable = true;
};

services.spice-vdagentd.enable = true;

Finding your Device ID

Obtain the device ID of your capture card using lspci -nn. It will show up as YUAN High-Tech Development Co., Ltd. Device. Make a note of the value at the end, usually something similar to 1234:5678. The output of lspci -nn showing my device ID as being 12ab:0710.

Add the following to your NixOS settings then reboot.

boot.kernelModules = [ "vfio_pci" "vfio" "vfio_iommu_type1" ];

# Replace `12ab:0710` here with the value you got earlier.
boot.kernelParams = [ "intel_iommu=on" "iommu=pt" "vfio-pci.ids=12ab:0710"];

Running the Windows VM

  1. Make a new Windows VM using virt-manager.
  2. Add your PCI device by clicking into Add Hardware > PCI Host Device and finding YUAN High-Tech Development Co., Ltd..
  3. Set up Windows as usual.
  4. Install Elgato’s 4K Capture Utility software.

From here you should see the input from your capture card. If it doesn’t show up, try unplugging/replugging the HDMI cables on the capture card.