diff --git a/configurations/host/materusPC/hardware/boot.nix b/configurations/host/materusPC/hardware/boot.nix index f8b6d37..037c9b2 100644 --- a/configurations/host/materusPC/hardware/boot.nix +++ b/configurations/host/materusPC/hardware/boot.nix @@ -3,10 +3,9 @@ #Kernel boot.kernelPackages = pkgs.linuxPackages_zen; boot.kernelParams = [ "nvme_core.default_ps_max_latency_us=0" "nvme_core.io_timeout=255" "nvme_core.max_retries=10" "nvme_core.shutdown_timeout=10" "amd_iommu=on" "iommu=pt" "pcie_acs_override=downstream,multifunction" ]; - boot.kernelModules = [ "nbd" "i2c_dev" "kvm_amd" "vfio-pci" "v4l2loopback" "kvmfr" ]; + boot.kernelModules = [ "i2c_dev" "kvm_amd" "vfio-pci" "v4l2loopback" "kvmfr" ]; boot.extraModprobeConfig = '' options kvm_amd nested=1 - options nbd max_part=16 ''; boot.kernel.sysctl = {"vm.max_map_count" = 1000000;}; diff --git a/configurations/host/materusPC/hardware/default.nix b/configurations/host/materusPC/hardware/default.nix index 0ae0b64..0d157e4 100644 --- a/configurations/host/materusPC/hardware/default.nix +++ b/configurations/host/materusPC/hardware/default.nix @@ -1,4 +1,11 @@ { config, pkgs, lib, inputs, materusFlake, materusPkgs, ... }: +let +pkg = import (builtins.fetchTarball { + name = "nixos-23.05"; + url = "https://github.com/nixos/nixpkgs/archive/4ecab3273592f27479a583fb6d975d4aba3486fe.tar.gz"; + sha256 = "sha256:10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf"; +}) {system = pkgs.system;}; +in { imports = [ @@ -9,7 +16,7 @@ hardware.firmware = with pkgs; [ materusPkgs.amdgpu-pro-libs.firmware.vcn materusPkgs.amdgpu-pro-libs.firmware - linux-firmware + pkg.linux-firmware alsa-firmware sof-firmware ]; diff --git a/configurations/host/materusPC/tmp.nix b/configurations/host/materusPC/tmp.nix index bfd00ae..4b99b93 100644 --- a/configurations/host/materusPC/tmp.nix +++ b/configurations/host/materusPC/tmp.nix @@ -101,20 +101,12 @@ in }; - virtualisation.libvirtd = { - enable = true; - onBoot = "ignore"; - onShutdown = "shutdown"; - qemu.ovmf.enable = true; - qemu.ovmf.packages = [ pkgs.OVMFFull.fd ]; - qemu.runAsRoot = true; - qemu.swtpm.enable = true; - }; + users.users.materus = { isNormalUser = true; - extraGroups = [ "pipewire" "wheel" "networkmanager" "input" "kvm" "libvirt-qemu" "libvirt" "libvirtd" "podman" "lxd" ]; # Enable ‘sudo’ for the user. + extraGroups = [ "audio" "video" "render" "pipewire" "wheel" "networkmanager" "input" "kvm" "libvirt-qemu" "libvirt" "libvirtd" "podman" "lxd" ]; # Enable ‘sudo’ for the user. shell = pkgs.bashInteractive; description = "Mateusz Słodkowicz"; # packages = with pkgs; [ @@ -290,7 +282,7 @@ in - + bubblewrap bindfs @@ -318,200 +310,154 @@ in ]; - /* - system.activationScripts.libvirt-hooks.text = + + system.activationScripts.libvirt-hooks.text = '' - ln -Tfs /etc/libvirt/hooks /var/lib/libvirt/hooks + ln -Tfs /etc/libvirt/hooks /var/lib/libvirt/hooks ''; - environment.etc = { - "libvirt/hooks/qemu" = { - text = - '' - #!/usr/bin/env bash - # - # Author: Sebastiaan Meijer (sebastiaan@passthroughpo.st) - # - # Copy this file to /etc/libvirt/hooks, make sure it's called "qemu". - # After this file is installed, restart libvirt. - # From now on, you can easily add per-guest qemu hooks. - # Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name. - # For a list of available hooks, please refer to https://www.libvirt.org/hooks.html - # + environment.etc = { - GUEST_NAME="$1" - HOOK_NAME="$2" - STATE_NAME="$3" - MISC="''${@:4}" - - BASEDIR="$(dirname $0)" - - HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME" - - set -e # If a script exits with an error, we should as well. - - # check if it's a non-empty executable file - if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH"] && [ -x "$HOOKPATH" ]; then - eval \"$HOOKPATH\" "$@" - elif [ -d "$HOOKPATH" ]; then - while read file; do - # check for null string - if [ ! -z "$file" ]; then - eval \"$file\" "$@" - fi - done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)" - fi - ''; - mode = "0755"; - }; - - "libvirt/hooks/kvm.conf" = { - text = - '' - VIRSH_GPU_VIDEO=pci_0000_01_00_0 - VIRSH_GPU_AUDIO=pci_0000_01_00_1 - VIRSH_GPU_USB=pci_0000_01_00_2 - VIRSH_GPU_SERIAL_BUS=pci_0000_01_00_3 - ''; - mode = "0755"; - }; + "libvirt/hooks/qemu.d/win11/prepare/begin/start.sh" = { - text = - '' - #!/usr/bin/env bash - # Debugging - exec 19>/home/materus/startlogfile - BASH_XTRACEFD=19 - set -x + text = + '' + #!/usr/bin/env bash + # Debugging + exec 19>/home/materus/startlogfile + BASH_XTRACEFD=19 + set -x - exec 3>&1 4>&2 - trap 'exec 2>&4 1>&3' 0 1 2 3 - exec 1>/home/materus/startlogfile.out 2>&1 + exec 3>&1 4>&2 + trap 'exec 2>&4 1>&3' 0 1 2 3 + exec 1>/home/materus/startlogfile.out 2>&1 - # Stop display manager - killall -u materus - systemctl stop display-manager.service - killall gdm-x-session - #systemctl isolate multi-user.target - sleep 1 + # Stop display manager + killall -u materus + systemctl stop display-manager.service + killall gdm-x-session + #systemctl isolate multi-user.target + sleep 1 - # Load variables we defined - source "/etc/libvirt/hooks/kvm.conf" + # Load variables we defined + source "/etc/libvirt/hooks/kvm.conf" - # Isolate host to core 0 - systemctl set-property --runtime -- user.slice AllowedCPUs=0 - systemctl set-property --runtime -- system.slice AllowedCPUs=0 - systemctl set-property --runtime -- init.scope AllowedCPUs=0 + # Isolate host to core 0 + systemctl set-property --runtime -- user.slice AllowedCPUs=0 + systemctl set-property --runtime -- system.slice AllowedCPUs=0 + systemctl set-property --runtime -- init.scope AllowedCPUs=0 - # Unbind VTconsoles - for (( i = 0; i < 16; i++)) - do - if test -x /sys/class/vtconsole/vtcon"''${i}"; then - if [ "$(grep -c "frame buffer" /sys/class/vtconsole/vtcon"''${i}"/name)" = 1 ]; then - echo 0 > /sys/class/vtconsole/vtcon"''${i}"/bind - echo "$DATE Unbinding Console ''${i}" - fi - fi - done + # Unbind VTconsoles + for (( i = 0; i < 16; i++)) + do + if test -x /sys/class/vtconsole/vtcon"''${i}"; then + if [ "$(grep -c "frame buffer" /sys/class/vtconsole/vtcon"''${i}"/name)" = 1 ]; then + echo 0 > /sys/class/vtconsole/vtcon"''${i}"/bind + echo "$DATE Unbinding Console ''${i}" + fi + fi + done - # Unbind EFI Framebuffer - echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/unbind + # Unbind EFI Framebuffer + echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/unbind - # Avoid race condition - sleep 1 + # Avoid race condition + sleep 1 - # Unload NVIDIA kernel modules - modprobe -r nvidia_uvm - modprobe -r nvidia_drm - modprobe -r nvidia_modeset - modprobe -r nvidia - modprobe -r i2c_nvidia_gpu - modprobe -r drm_kms_helper - modprobe -r drm + # Unload NVIDIA kernel modules + modprobe -r nvidia_uvm + modprobe -r nvidia_drm + modprobe -r nvidia_modeset + modprobe -r nvidia + modprobe -r i2c_nvidia_gpu + modprobe -r drm_kms_helper + modprobe -r drm - # Detach GPU devices from host - #virsh nodedev-detach $VIRSH_GPU_VIDEO - #virsh nodedev-detach $VIRSH_GPU_AUDIO - #virsh nodedev-detach $VIRSH_GPU_USB - #virsh nodedev-detach $VIRSH_GPU_SERIAL_BUS + # Detach GPU devices from host + #virsh nodedev-detach $VIRSH_GPU_VIDEO + #virsh nodedev-detach $VIRSH_GPU_AUDIO + #virsh nodedev-detach $VIRSH_GPU_USB + #virsh nodedev-detach $VIRSH_GPU_SERIAL_BUS - # Load vfio module - modprobe vfio - modprobe vfio_pci - modprobe vfio_iommu_type1 - ''; - mode = "0755"; + # Load vfio module + modprobe vfio + modprobe vfio_pci + modprobe vfio_iommu_type1 + ''; + mode = "0755"; }; "libvirt/hooks/qemu.d/win11/release/end/stop.sh" = { - text = - '' - #!/usr/bin/env bash - # Debugging - exec 19>/home/materus/stoplogfile - BASH_XTRACEFD=19 - set -x + text = + '' + #!/usr/bin/env bash + # Debugging + exec 19>/home/materus/stoplogfile + BASH_XTRACEFD=19 + set -x - exec 3>&1 4>&2 - trap 'exec 2>&4 1>&3' 0 1 2 3 - exec 1>/home/materus/stoplogfile.out 2>&1 + exec 3>&1 4>&2 + trap 'exec 2>&4 1>&3' 0 1 2 3 + exec 1>/home/materus/stoplogfile.out 2>&1 - # Load variables we defined - source "/etc/libvirt/hooks/kvm.conf" + # Load variables we defined + source "/etc/libvirt/hooks/kvm.conf" - # Unload vfio module - modprobe -r vfio-pci - modprobe -r vfio_iommu_type1 - modprobe -r vfio + # Unload vfio module + modprobe -r vfio-pci + modprobe -r vfio_iommu_type1 + modprobe -r vfio - modprobe drm - modprobe drm_kms_helper - modprobe i2c_nvidia_gpu - modprobe nvidia - modprobe nvidia_modeset - modprobe nvidia_drm - modprobe nvidia_uvm + modprobe drm + modprobe drm_kms_helper + modprobe i2c_nvidia_gpu + modprobe nvidia + modprobe nvidia_modeset + modprobe nvidia_drm + modprobe nvidia_uvm - # Attach GPU devices from host - #virsh nodedev-reattach $VIRSH_GPU_VIDEO - #virsh nodedev-reattach $VIRSH_GPU_AUDIO - #virsh nodedev-reattach $VIRSH_GPU_USB - #virsh nodedev-reattach $VIRSH_GPU_SERIAL_BUS + # Attach GPU devices from host + #virsh nodedev-reattach $VIRSH_GPU_VIDEO + #virsh nodedev-reattach $VIRSH_GPU_AUDIO + #virsh nodedev-reattach $VIRSH_GPU_USB + #virsh nodedev-reattach $VIRSH_GPU_SERIAL_BUS - #echo "0000:01:00.0" > /sys/bus/pci/drivers/nvidia/bind - # Bind EFI Framebuffer - echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind + #echo "0000:01:00.0" > /sys/bus/pci/drivers/nvidia/bind + # Bind EFI Framebuffer + echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind - # Bind VTconsoles - echo 1 > /sys/class/vtconsole/vtcon0/bind - #echo 1 > /sys/class/vtconsole/vtcon1/bind + # Bind VTconsoles + echo 1 > /sys/class/vtconsole/vtcon0/bind + #echo 1 > /sys/class/vtconsole/vtcon1/bind - # Start display manager - sleep 1 - systemctl start display-manager.service + # Start display manager + sleep 1 + systemctl start display-manager.service - # Return host to all cores - systemctl set-property --runtime -- user.slice AllowedCPUs=0-3 - systemctl set-property --runtime -- system.slice AllowedCPUs=0-3 - systemctl set-property --runtime -- init.scope AllowedCPUs=0-3 - ''; - /*text = '' - #!/usr/bin/env bash - reboot - '';*-/ - mode = "0755"; + # Return host to all cores + systemctl set-property --runtime -- user.slice AllowedCPUs=0-3 + systemctl set-property --runtime -- system.slice AllowedCPUs=0-3 + systemctl set-property --runtime -- init.scope AllowedCPUs=0-3 + ''; + /*text = '' + #!/usr/bin/env bash + reboot + '';*-/ + mode = "0755"; + }; + "libvirt/vgabios/patched.rom".source = ./vbios.rom; + }; */ }; - "libvirt/vgabios/patched.rom".source = ./vbios.rom; - }; */ + }; }