Skip to content

Instantly share code, notes, and snippets.

@jchv
Last active May 28, 2025 18:26
Show Gist options
  • Select an option

  • Save jchv/b0e4b39679e450536a17cc6a5d69169a to your computer and use it in GitHub Desktop.

Select an option

Save jchv/b0e4b39679e450536a17cc6a5d69169a to your computer and use it in GitHub Desktop.

Revisions

  1. jchv revised this gist Feb 11, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion configuration.nix
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    { ... }
    { config, pkgs, lib, ... }:

    {
    # IOMMU configuration
  2. jchv revised this gist Feb 11, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion configuration.nix
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    { ... }

    {
    # IOMMU configuration
    boot.kernelParams = [ "amd_iommu=on" "pcie_aspm=off" ];
    boot.kernelModules = [ "kvm-amd" "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" ];
    @@ -28,4 +31,5 @@
    group = "kvm"
    '';
    };
    };
    };
    }
  3. jchv created this gist Feb 11, 2019.
    31 changes: 31 additions & 0 deletions configuration.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # IOMMU configuration
    boot.kernelParams = [ "amd_iommu=on" "pcie_aspm=off" ];
    boot.kernelModules = [ "kvm-amd" "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" ];
    boot.extraModprobeConfig = ''
    options vfio-pci ids=10de:13c2,10de:0fbb
    options kvm ignore_msrs=1
    '';

    boot.postBootCommands = ''
    # Enable VFIO on secondary GPU
    for DEV in "0000:0b:00.0" "0000:0b:00.1"; do
    echo "vfio-pci" > /sys/bus/pci/devices/$DEV/driver_override
    done
    modprobe -i vfio-pci
    # Setup Looking Glass shared memory object
    touch /dev/shm/looking-glass
    chown john:kvm /dev/shm/looking-glass
    chmod 660 /dev/shm/looking-glass
    '';

    virtualisation = {
    libvirtd = {
    qemuOvmf = true;
    qemuVerbatimConfig = ''
    namespaces = []
    nographics_allow_host_audio = 1
    user = "john"
    group = "kvm"
    '';
    };
    };