From be2ea6aab3fd9476dd9a037d490f6947c547dcd9 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 10 Dec 2024 09:57:19 -0600 Subject: [PATCH] A few tweaks to try TPM improvement --- home/hosts/jude/default.nix | 15 +++++++--- hosts/jude/virt.nix | 55 +++++++++++++++++++++++++++++++++---- modules/nixos/vmdev.nix | 1 + 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/home/hosts/jude/default.nix b/home/hosts/jude/default.nix index cdde455..7e74fcf 100644 --- a/home/hosts/jude/default.nix +++ b/home/hosts/jude/default.nix @@ -1,10 +1,6 @@ { pkgs, ... }: { - home.packages = with pkgs; [ - (mumble.override { pulseSupport = true; }) - #logseq - ]; greg = { development = true; gui = true; @@ -13,5 +9,16 @@ vscodium = true; }; + home = { + file.".config/libvirt/qemu.conf".text = '' + nvram = [ "/run/libvirt/nix-ovmf/OVMF_CODE.fd:/run/libvirt/nix-ovmf/OVMF_VARS.fd" ] + ''; + + packages = with pkgs; [ + (mumble.override { pulseSupport = true; }) + #logseq + ]; + }; + programs.xonsh.sessionVariables.EFI_DIR = "${pkgs.OVMF.fd}/FV/"; } diff --git a/hosts/jude/virt.nix b/hosts/jude/virt.nix index a9625d8..64fd4b8 100644 --- a/hosts/jude/virt.nix +++ b/hosts/jude/virt.nix @@ -3,11 +3,6 @@ { greg.vmdev.enable = true; - virtualisation = { - waydroid.enable = false; - lxd.enable = false; - }; - systemd.services = { gitlab-runner = { conflicts = [ "libvirtd.service" ]; @@ -35,4 +30,54 @@ }; }; }; + + virtualisation = { + libvirtd.hooks.qemu = { + "win11-prepare-begin-bind_vfio.sh" = pkgs.writeShellApplication { + name = "bind_vfio.sh"; + runtimeInputs = with pkgs; [ + kmod + libvirt + ]; + text = '' + guest="$1" + stage="$2" + state="$3" + + if [ "$guest" == "win11" ] && [ "$stage" == "prepare" ] && [ "$state" == "begin" ]; then + for f in vfio vfio_iommu_type1 vfio_pci; do + modprobe "$f" + done + + virsh nodedev-detach pci_0000_10_00_0 + virsh nodedev-detach pci_0000_10_00_1 + fi + ''; + }; + + "win11-release-end-unbind_vfio.sh" = pkgs.writeShellApplication { + name = "unbind_vfio.sh"; + runtimeInputs = with pkgs; [ + kmod + libvirt + ]; + text = '' + guest="$1" + stage="$2" + state="$3" + + if [ "$guest" == "win11" ] && [ "$stage" == "release" ] && [ "$state" == "end" ]; then + virsh nodedev-reattach pci_0000_10_00_1 + virsh nodedev-reattach pci_0000_10_00_0 + + for f in vfio_pci vfio_iommu_type1 vfio; do + modprobe -r "$f" + done + fi + ''; + }; + }; + lxd.enable = false; + waydroid.enable = false; + }; } diff --git a/modules/nixos/vmdev.nix b/modules/nixos/vmdev.nix index 0e6bffd..f4fcf1c 100644 --- a/modules/nixos/vmdev.nix +++ b/modules/nixos/vmdev.nix @@ -46,6 +46,7 @@ with lib; enable = true; onBoot = "ignore"; # Do not auto-restart VMs on boot, unless they are marked autostart qemu.ovmf.enable = true; + qemu.swtpm.enable = true; }; virtualbox.host = {