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