forked from stitchy/dotfiles
88 lines
2.4 KiB
Nix
88 lines
2.4 KiB
Nix
{ config, pkgs, ... }:
|
|
let
|
|
passthrough = pkgs.writeShellScript "pasthrough.sh" ''
|
|
GUEST_NAME="$1"
|
|
HOOK_NAME="$2"
|
|
STATE_NAME="$3"
|
|
|
|
set -e
|
|
set -x
|
|
|
|
# For the windows 10 VM
|
|
if [[ "$GUEST_NAME" == "win10" ]]; then
|
|
|
|
# Prepare hook
|
|
if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then
|
|
|
|
# Remove Hyprland
|
|
${pkgs.busybox}/bin/pkill Hyprland
|
|
|
|
# Unbind VTconsoles
|
|
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon0/bind
|
|
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon1/bind
|
|
|
|
# Unbind EFI-Framebuffer
|
|
${pkgs.busybox}/bin/echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
|
|
|
# Unload Modules
|
|
${pkgs.busybox}/bin/modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
|
|
|
|
# Unbind the GPU from display driver
|
|
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_0
|
|
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_1
|
|
|
|
# Load VFIO Kernel Module
|
|
${pkgs.busybox}/bin/modprobe vfio_pci
|
|
|
|
elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then
|
|
|
|
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
|
|
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_0
|
|
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_1
|
|
|
|
${pkgs.busybox}/bin/modprobe -r vfio-pci
|
|
|
|
#bind efi
|
|
${pkgs.busybox}/bin/echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
|
|
|
# Reload nvidia modules
|
|
${pkgs.busybox}/bin/modprobe nvidia_drm
|
|
${pkgs.busybox}/bin/modprobe nvidia_modeset
|
|
${pkgs.busybox}/bin/modprobe nvidia_uvm
|
|
${pkgs.busybox}/bin/modprobe nvidia
|
|
|
|
# Rebind VT consoles
|
|
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon0/bind
|
|
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon1/bind
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
'';
|
|
in {
|
|
imports =
|
|
[
|
|
./hardware-configuration.nix
|
|
../default.nix
|
|
];
|
|
virtualisation.libvirtd.hooks.qemu = {
|
|
passthrough = "${passthrough}";
|
|
};
|
|
|
|
stitchyconf = {
|
|
artPkgs.enable = true;
|
|
};
|
|
|
|
virtualisation.libvirtd.enable = true;
|
|
hardware = {
|
|
steam-hardware.enable = true;
|
|
};
|
|
|
|
networking.hostName = "malachite";
|
|
|
|
time.timeZone = "America/Los_Angeles";
|
|
|
|
# Read the Docs before Changing
|
|
system.stateVersion = "23.05"; # Did you read the comment?
|
|
}
|