Skip to content

Instantly share code, notes, and snippets.

@notgne2
Created December 12, 2019 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notgne2/2563301b4b37b18335f20d4b2b026a12 to your computer and use it in GitHub Desktop.
Save notgne2/2563301b4b37b18335f20d4b2b026a12 to your computer and use it in GitHub Desktop.
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.ezpassthru;
in
{
options.services.ezpassthru = {
enable = mkEnableOption "Enable simple VM PCI passthrough config (NOTE: this is only for ppl with a primary AMD/Intel, and a non-primary NVidia)";
PCIs = mkOption {
description = "The ID pairs of your PCI devices to passthrough";
example = {
"10de:1b80" = "0000:41:00.0";
"10de:10f0" = "0000:41:00.1";
"1022:43ba" = "0000:01:00.0";
};
};
};
config = mkIf cfg.enable {
boot.kernelModules = [ "kvm-intel" "kvm-amd" "vfio_virqfd" "vfio_pci" "vfio_iommu_type" "vfio" ];
boot.blacklistedKernelModules = [ "nvidia" "nouveau" ];
boot.extraModprobeConfig = "options vfio-pci ids=${builtins.concatStringsSep "," (builtins.attrNames cfg.PCIs)}";
boot.postBootCommands = ''
DEVS="${builtins.concatStringsSep " " (builtins.attrValues cfg.PCIs)}"
for DEV in $DEVS; do
echo "vfio-pci" > /sys/bus/pci/devices/$DEV/driver_override
done
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment