better way of doing this

This commit is contained in:
stitchy 2024-04-05 02:21:55 -07:00
parent 16ae890458
commit 8d69eb76d6
Signed by: stitchy
SSH key fingerprint: SHA256:p+xeQgmOvQ2br1d2STl5OnRRMef2LRqCtGA7SO4WYk0

View file

@ -1,65 +1,74 @@
{ config, pkgs, ... }: { config, pkgs, lib, ... }:
let let
passthrough = pkgs.writeShellScript "pasthrough.sh" '' passthrough = pkgs.writeShellApplication {
GUEST_NAME="$1" name = "pasthrough.sh";
HOOK_NAME="$2" runtimeInputs = lib.attrVals [ "coreutils" "kmod" "libvirtd" "procps" ] pkgs;
STATE_NAME="$3" text = ''
GUEST_NAME="$1"
HOOK_NAME="$2"
STATE_NAME="$3"
set -e echo 19>/home/stitchynyan/startlogfile
set -x BASH_XTRACEFD=19
set -x
# For the windows 10 VM # For the windows 10 VM
if [[ "$GUEST_NAME" == "win10" ]]; then if [[ "$GUEST_NAME" == "win10" ]]; then
# Prepare hook # Prepare hook
if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then
# Remove Hyprland # Remove Hyprland
${pkgs.busybox}/bin/pkill Hyprland pkill Hyprland
# Unbind VTconsoles # Unbind VTconsoles
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon0/bind echo 0 > /sys/class/vtconsole/vtcon0/bind
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon1/bind echo 0 > /sys/class/vtconsole/vtcon1/bind
# Unbind EFI-Framebuffer # Unbind EFI-Framebuffer
${pkgs.busybox}/bin/echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
# Unload Modules # We love race conditions
${pkgs.busybox}/bin/modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia sleep 2
# Unbind the GPU from display driver # Unload Modules
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_0 modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_1
# Load VFIO Kernel Module # Unbind the GPU from display driver
${pkgs.busybox}/bin/modprobe vfio_pci virsh nodedev-detach pci_0000_01_00_0
virsh nodedev-detach pci_0000_01_00_1
elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then # Load VFIO Kernel Module
modprobe vfio_pci
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours) sleep 2
${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 elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then
#bind efi # Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
${pkgs.busybox}/bin/echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind virsh nodedev-reattach pci_0000_01_00_0
virsh nodedev-reattach pci_0000_01_00_1
# Reload nvidia modules modprobe -r vfio-pci
${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 #bind efi
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon0/bind echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon1/bind
# Reload nvidia modules
modprobe nvidia_drm
modprobe nvidia_modeset
modprobe nvidia_uvm
modprobe nvidia
# Rebind VT consoles
echo 1 > /sys/class/vtconsole/vtcon0/bind
bin/echo 1 > /sys/class/vtconsole/vtcon1/bind
fi
fi fi
fi '';
'';
in { in {
imports = imports =
[ [