-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpci-passthrough.nix
73 lines (63 loc) · 2 KB
/
pci-passthrough.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# put this file in /etc/nixos/
# change the settings tagged with "CHANGE:"
# and add
# ./pci-passthrough.nix
# to /etc/nixos/configuration.nix in `imports`
{config, pkgs, ... }:
{
# CHANGE: intel_iommu enables iommu for intel CPUs with VT-d
# use amd_iommu if you have an AMD CPU with AMD-Vi
boot.kernelParams = [ "intel_iommu=on" "iommu=pt" ];
# These modules are required for PCI passthrough, and must come before early modesetting stuff
boot.kernelModules = [ "kvm-intel" "vfio_pci"];
# CHANGE: Don't forget to put your own PCI IDs here
# boot.extraModprobeConfig ="options vfio-pci ids=10de:1f11,10de:10f9";
environment.systemPackages = with pkgs; [
virtmanager
qemu
OVMF
];
virtualisation.libvirtd = {
enable = true;
onBoot = "ignore";
onShutdown = "shutdown";
qemu = {
ovmf.enable = true;
runAsRoot = true;
};
};
# Add binaries to path so that hooks can use it
systemd.services.libvirtd = {
path = let
env = pkgs.buildEnv {
name = "qemu-hook-env";
paths = with pkgs; [
bash
libvirt
kmod
systemd
ripgrep
sd
];
};
in
[ env ];
preStart =
''
chmod +x /var/lib/libvirt/hooks/qemu
chmod +x /var/lib/libvirt/hooks/kvm.conf
chmod +x /var/lib/libvirt/hooks/qemu.d/win10/prepare/begin/start.sh
chmod +x /var/lib/libvirt/hooks/qemu.d/win10/release/end/stop.sh
'';
};
# CHANGE: add your own user here
users.groups.libvirtd.members = [ "root" "pkngr"];
# CHANGE: use
# ls /nix/store/*OVMF*/FV/OVMF{,_VARS}.fd | tail -n2 | tr '\n' : | sed -e 's/:$//'
# to find your nix store paths
virtualisation.libvirtd.qemu.verbatimConfig = ''
nvram = [
"/nix/store/k42akcjj7yk8srkpilf3ddrykh7clbr9-OVMF-202202-fd/FV/OVMF.fd:/nix/store/k42akcjj7yk8srkpilf3ddrykh7clbr9-OVMF-202202-fd/FV/OVMF_VARS.fd"
]
'';
}