2024-08-08 04:49:22 -07:00
|
|
|
{ config, nixpkgs-xr, pkgs, lib, ... }:
|
2024-03-13 23:13:52 -07:00
|
|
|
let
|
2024-04-05 02:21:55 -07:00
|
|
|
passthrough = pkgs.writeShellApplication {
|
2024-06-05 05:46:08 -07:00
|
|
|
name = "passthrough.sh";
|
2024-04-05 02:23:27 -07:00
|
|
|
runtimeInputs = lib.attrVals [ "coreutils" "kmod" "libvirt" "procps" ] pkgs;
|
2024-04-05 02:21:55 -07:00
|
|
|
text = ''
|
|
|
|
GUEST_NAME="$1"
|
|
|
|
HOOK_NAME="$2"
|
|
|
|
STATE_NAME="$3"
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
set -x
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# For the windows 10 VM
|
|
|
|
if [[ "$GUEST_NAME" == "win10" ]]; then
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Prepare hook
|
|
|
|
if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Remove Hyprland
|
2024-06-05 05:46:08 -07:00
|
|
|
#pkill Hyprland
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Unbind VTconsoles
|
|
|
|
echo 0 > /sys/class/vtconsole/vtcon0/bind
|
|
|
|
echo 0 > /sys/class/vtconsole/vtcon1/bind
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Unbind EFI-Framebuffer
|
2024-08-08 04:49:22 -07:00
|
|
|
#echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-08-08 04:49:22 -07:00
|
|
|
# Unbind the GPU from display driver
|
|
|
|
virsh nodedev-detach pci_0000_03_00_0
|
|
|
|
virsh nodedev-detach pci_0000_03_00_1
|
|
|
|
virsh nodedev-detach pci_0000_03_00_2
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Unload Modules
|
2024-08-08 04:49:22 -07:00
|
|
|
modprobe -r amdgpu
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-08-08 04:49:22 -07:00
|
|
|
# We love race conditions
|
|
|
|
sleep 2
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
# Load VFIO Kernel Module
|
2024-08-08 04:49:22 -07:00
|
|
|
modprobe vfio vfio_pci vfio_iommu_type1
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-08-08 04:49:22 -07:00
|
|
|
modprobe -r vfio_iommu_type1 vfio_pci vfio
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-08-08 04:49:22 -07:00
|
|
|
# Re-Bind GPU to Host
|
|
|
|
virsh nodedev-reattach pci_0000_03_00_0
|
|
|
|
virsh nodedev-reattach pci_0000_03_00_1
|
|
|
|
virsh nodedev-reattach pci_0000_03_00_2
|
2024-04-05 02:21:55 -07:00
|
|
|
|
|
|
|
# Rebind VT consoles
|
|
|
|
echo 1 > /sys/class/vtconsole/vtcon0/bind
|
2024-08-08 04:49:22 -07:00
|
|
|
echo 1 > /sys/class/vtconsole/vtcon1/bind
|
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# Bind Framebuffer
|
|
|
|
#echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
|
|
|
|
|
|
|
# Reload Modules
|
|
|
|
modprobe amdgpu
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2024-03-13 23:13:52 -07:00
|
|
|
|
2024-04-05 02:21:55 -07:00
|
|
|
'';
|
2024-04-05 02:23:27 -07:00
|
|
|
};
|
2024-03-13 23:13:52 -07:00
|
|
|
in {
|
|
|
|
imports =
|
|
|
|
[
|
|
|
|
./hardware-configuration.nix
|
2024-03-26 20:47:54 -07:00
|
|
|
../default.nix
|
2024-03-13 23:13:52 -07:00
|
|
|
];
|
2024-03-14 00:29:36 -07:00
|
|
|
virtualisation.libvirtd.hooks.qemu = {
|
2024-06-05 05:46:08 -07:00
|
|
|
passthrough = "${passthrough}/bin/passthrough.sh";
|
2024-03-13 23:01:33 -07:00
|
|
|
};
|
2024-03-13 23:13:52 -07:00
|
|
|
|
2024-03-26 21:34:28 -07:00
|
|
|
stitchyconf = {
|
|
|
|
artPkgs.enable = true;
|
|
|
|
};
|
|
|
|
|
2024-06-05 05:46:08 -07:00
|
|
|
virtualisation.libvirtd = {
|
|
|
|
enable = true;
|
|
|
|
onBoot = "ignore";
|
|
|
|
};
|
2024-03-26 20:47:54 -07:00
|
|
|
hardware = {
|
2024-06-05 05:46:08 -07:00
|
|
|
opentabletdriver.enable = true;
|
2024-03-26 20:47:54 -07:00
|
|
|
steam-hardware.enable = true;
|
|
|
|
};
|
2024-03-13 23:13:52 -07:00
|
|
|
|
2024-04-05 02:23:27 -07:00
|
|
|
networking.networkmanager.enable = true;
|
|
|
|
services.syncthing = {
|
|
|
|
enable = true;
|
|
|
|
user = "stitchynyan";
|
|
|
|
openDefaultPorts = true;
|
|
|
|
databaseDir = "/home/stitchynyan/.local/share/syncthing";
|
|
|
|
dataDir = "/home/stitchynyan";
|
|
|
|
};
|
2024-08-08 04:49:22 -07:00
|
|
|
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.wlx-overlay-s ];
|
2024-04-05 02:23:27 -07:00
|
|
|
|
2024-03-13 23:13:52 -07:00
|
|
|
networking.hostName = "malachite";
|
|
|
|
|
|
|
|
time.timeZone = "America/Los_Angeles";
|
2024-03-13 23:01:33 -07:00
|
|
|
|
2024-02-25 19:49:15 -08:00
|
|
|
# Read the Docs before Changing
|
|
|
|
system.stateVersion = "23.05"; # Did you read the comment?
|
2024-03-14 00:29:36 -07:00
|
|
|
}
|