dotfiles

My PC Dotfiles & Website
commit a6703b65438a67dc15db67b3df7c5a98a58401ad
parent 3e93c02d69336d400ab53ef54b7f059f16d88cc9
Author: maydayv7 <maydayv7@gmail.com>
Date:   Tue, 22 Oct 2024 22:16:30 +0530

feat: Add Looking Glass to VFIO Configuration

Also remove needless `wfvm` Configuration

Diffstat:

MREADME.md | 17+++++++++--------
Mdevices/flake.nix | 8+-------
Ddevices/vm/README.md | 7-------
Ddevices/vm/Windows.nix | 43-------------------------------------------
Mfiles/gnome/menu.json | 9+++++++++
Mfiles/gnome/settings/extensions.nix | 6+++---
Mflake.lock | 21---------------------
Mflake.nix | 6------
Mmodules/README.md | 4++--
Mmodules/hardware/README.md | 17+++++++++++++++++
Mmodules/hardware/virtualisation/vfio.nix | 51+++++++++++++++++++++++++++++++++++++++++++++++++--
11 files changed, 90 insertions(+), 99 deletions(-)

diff --git a/README.md b/README.md @@ -73,7 +73,7 @@ This [repository](https://github.com/maydayv7/dotfiles) contains the configurati - Support for declaratively installing [Flatpak](./modules/apps/flatpak.nix) applications using [`nix-flatpak`](https://github.com/gmodena/nix-flatpak) - Wrapped `wine` [Applications](./packages/wine) using Emmanuel's [Wrapper](https://github.com/emmanuelrosa/erosanix/tree/0dabea58d483e13d2de141517cb4ff1cb230b2aa/pkgs/mkwindowsapp) - Support for Android Virtualisation using [Waydroid](https://waydro.id/) -- Declaratively Configured [Windows VM](./devices/vm/Windows.nix) using the [WFVM](https://git.m-labs.hk/M-Labs/wfvm) module +- Support for VFIO PCI Device Passthrough along with [Looking Glass](https://looking-glass.io/) for high-performance VMs ## Programs @@ -138,10 +138,8 @@ github:maydayv7/dotfiles │ └───x86_64-linux │ ├───install: package 'install' │ └───nixos: package 'nixos' -├───templates -│ └───default: template: My NixOS Configuration -└───vmConfigurations - └───Windows: Virtual Machine +└───templates + └───default: template: My NixOS Configuration ``` </details> @@ -320,7 +318,9 @@ Example `flake.nix`: Download the latest install media image from the [Releases](../../releases/latest) page and burn it to a USB using a flashing utility such as [Etcher](https://www.balena.io/etcher/) > [!IMPORTANT] -> These instructions are mainly intended for personal use. +> These instructions are mainly intended for personal use + +> [!TIP] > In order to directly use the configuration, you must first create a clone of this repository and follow steps 2 to 6 from the first section, and preferably create your own install media <details> @@ -392,7 +392,7 @@ It is not recommended to use NixOS if you are a beginner just starting out, with _May change according to available hardware_ -This configuration works well with an Intel CPU + iGPU, and is currently being improved to support AMD APU + Nvidia GPU. Any other setup is untested +This configuration works well with an Intel CPU + iGPU, and is currently being improved to support AMD APU + Nvidia GPU. Any other setup is untested The `hardware.modules` option can be used to load relevant configuration from [`nixos-hardware`](https://github.com/nixos/nixos-hardware) See [this](./modules/hardware/README.md) for additional information @@ -508,7 +508,8 @@ You can navigate to the `README`s present in the various directories to know mor - GNOME Improvements - Use [PaperWM](https://github.com/paperwm/PaperWM) - Remove unneeded extensions -- Fix VFIO Configuration +- Add Looking Glass to VFIO Configuration +- Remove needless `wfvm` Configuration ### v24 diff --git a/devices/flake.nix b/devices/flake.nix @@ -6,7 +6,6 @@ }: let inherit (inputs) self; inherit (util) build map pack; - inherit (builtins) head readFile; inherit (lib) listToAttrs nameValuePair; in { flake = { @@ -33,15 +32,10 @@ in { description = "Default User"; minimal = true; shells = null; - password = readFile ../users/passwords/default; + password = builtins.readFile ../users/passwords/default; }; })) (import ../modules/gui/desktop/iso.nix)) // {default = self.installMedia.gnome;}; - - ## Virtual Machines ## - vmConfigurations = with self; - map.modules ./vm - (name: import name inputs.wfvm.lib legacyPackages."${head systems}"); }; # Install Media Checks diff --git a/devices/vm/README.md b/devices/vm/README.md @@ -1,7 +0,0 @@ -### Virtual Machines - -The `vm` directory contains the declarative configurations to build multiple Virtual Machines - -Virtualisation is done using `qemu-kvm` and `libvirt`. Preferred GUI is `virt-manager`. For VFI/O, you can use `hardware.passthrough` to specify the devices you want to pass through to the VM (you can use [`scripts/pci.sh`](../../scripts/pci.sh) to find the IDs) - -A [Windows](./Windows.nix) VM is declaratively installed and configured making use of the [WFVM](https://git.m-labs.hk/M-Labs/wfvm) Project. Use `nix build github:maydayv7/dotfiles#vmConfigurations.Windows` to build the image diff --git a/devices/vm/Windows.nix b/devices/vm/Windows.nix @@ -1,43 +0,0 @@ -lib: pkgs: -## Windows Virtual Machine ## -lib.makeWindowsImage { - # Base Image - windowsImage = pkgs.requireFile rec { - name = "Win11_22H2_English_x64.iso"; - sha256 = "08mbppsm1naf73z8fjyqkf975nbls7xj9n4fq0yp802dv1rz3whd"; - message = "Get ${name} from https://www.microsoft.com/en-us/software-download/windows11"; - }; - - # User Accounts - users = { - default = { - password = "1234567"; - description = "Default User"; - displayName = "Windows"; - groups = ["Administrators"]; - }; - }; - - # Auto Login - defaultUser = "default"; - administratorPassword = "admin"; - - # Organisation - fullName = "Microsoft"; - organization = "ms"; - - # Imperative Installation Commands - installCommands = with lib.layers; [ - (collapseLayers [disable-autosleep disable-autolock disable-firewall]) - ]; - - # License - imageSelection = "Windows 11 Pro N"; - productKey = "VK7JG-NPHTM-C97JM-9MPGT-3V66T"; - - # Locales - uiLanguage = "en-US"; - inputLocale = "en-US"; - userLocale = "en-US"; - systemLocale = "en-US"; -} diff --git a/files/gnome/menu.json b/files/gnome/menu.json @@ -32,6 +32,15 @@ "stop": "waydroid session stop", "check": "sh -c 'waydroid status | grep RUNNING'", "interval_s": 10 + }, + { + "type": "switch", + "title": "Windows", + "icon": "application-x-addon-symbolic", + "start": "virsh -c qemu:///system start Windows", + "stop": "virsh -c qemu:///system shutdown Windows", + "check": "sh -c 'virsh -c qemu:///system list | grep Windows'", + "interval_s": 10 } ] }, diff --git a/files/gnome/settings/extensions.nix b/files/gnome/settings/extensions.nix @@ -164,7 +164,7 @@ animation-time = 0.25; disable-topbar-styling = false; gesture-horizontal-fingers = 3; - gesture-workspace-fingers = 3; + gesture-workspace-fingers = 4; horizontal-margin = 10; maximize-within-tiling = true; open-window-position = 0; @@ -358,12 +358,12 @@ workspace-animation-module = true; workspace-module = true; workspace-switcher-animation = 1; - workspace-switcher-popup-module = false; + workspace-switcher-popup-module = true; ws-max-spacing = 350; ws-preview-bg-radius = 30; ws-preview-scale = 100; ws-sw-popup-h-position = 50; - ws-sw-popup-mode = 1; + ws-sw-popup-mode = 0; ws-sw-popup-v-position = 50; ws-switcher-ignore-last = false; ws-switcher-mode = 0; diff --git a/flake.lock b/flake.lock @@ -902,7 +902,6 @@ "utils": "utils_2", "vscode": "vscode", "vsppuccin": "vsppuccin", - "wfvm": "wfvm", "windows": "windows" } }, @@ -1177,26 +1176,6 @@ "type": "github" } }, - "wfvm": { - "inputs": { - "nixpkgs": [ - "stable" - ] - }, - "locked": { - "lastModified": 1718082876, - "narHash": "sha256-u4OgfsO6jnQwHNmxHhSIfCKaa2gYoIYwGKPJFZSpK/A=", - "ref": "refs/heads/master", - "rev": "e811c7c5d87059cb93b6548109fcafb3268a3af1", - "revCount": 70, - "type": "git", - "url": "https://git.m-labs.hk/M-Labs/wfvm" - }, - "original": { - "type": "git", - "url": "https://git.m-labs.hk/M-Labs/wfvm" - } - }, "windows": { "inputs": { "flake-compat": "flake-compat_5", diff --git a/flake.nix b/flake.nix @@ -194,12 +194,6 @@ }; }; - # Windows VM Creator - wfvm = { - url = "git+https://git.m-labs.hk/M-Labs/wfvm"; - inputs.nixpkgs.follows = "stable"; - }; - # Windows Apps Wrapper windows = { url = "github:emmanuelrosa/erosanix"; diff --git a/modules/README.md b/modules/README.md @@ -72,8 +72,8 @@ Configuration [Builder](./configuration.nix) - `support`: List of Additional Supported Hardware - `[ "laptop" "mobile" "printer" "virtualisation" ]` - `vm`: Configure Virtualisation Support - - `android`: Enable Android Virtualisation - `true / false` - - `vfio`: Configure the device for VFIO - `true / false` - - `passthrough`: PCI Device IDs for VFIO (Use [`scripts/pci.sh`](../scripts/pci.sh)) - Ex. `[ "10de:28e0" "10de:22be" ]` + - `vfio`: Configure VFIO PCI passthrough - `true / false` + - `passthrough`: PCI Device IDs for VFIO - Ex. `[ "10de:28e0" "10de:22be" ]` - [`nix`](./nix): Module that configures the Nix Package Manager - diff --git a/modules/hardware/README.md b/modules/hardware/README.md @@ -20,3 +20,20 @@ The system may be set up using either a `simple` or `advanced` filesystem layout #### Data Storage All important, persisted user files are stored at `/data`, while persisted system files are stored at `/nix/state`. Personal files and media are stored at `/data/files` + +### Virtualisation + +Configuration has been provided to run VMs using `qemu-kvm` and `libvirt`, along with support for VFIO PCI Passthrough. This can be used to create high-performance VMs, especially useful for virtualising Windows + +#### PCI Passthrough + +Use [`scripts/pci.sh`](../../scripts/pci.sh) in order to determine the PCI Device IDs which must be added to `hardware.vm.passthrough` + +#### Windows Virtualisation + +In order to create a highly performant Windows VM using the `virt-manager` GUI and [Virtio](https://wiki.libvirt.org/Virtio.html) drivers, follow the instructions given on [this](https://sysguides.com/install-a-windows-11-virtual-machine-on-kvm) page. To configure GPU passthrough, add the relevant GPU and audio IDs to `hardware.vm.passthrough` (See the [Arch Wiki](https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF) for additional information), and enable `hardware.vm.vfio`. Confirm that the GPU is recognized within the Windows VM, and download the relevant drivers. In order to utilize full graphical bandwidth, one of the following must be done: + +1. Connecting an external monitor to the GPU +2. Using a dummy monitor plug or faking a display using [`Virtual Display Driver`](https://github.com/itsmikethetech/Virtual-Display-Driver), then using [Looking Glass](https://looking-glass.io/) to extract video output onto the main monitor. The configuration for Looking Glass on the Linux (client) side is already implemented, and only the Windows (host) needs to be configured by following instructions on [this](https://looking-glass.io/docs/stable/install/) page + +The `vfio` Specialisation can be selected in the boot menu to enable GPU passthrough when required diff --git a/modules/hardware/virtualisation/vfio.nix b/modules/hardware/virtualisation/vfio.nix @@ -1,15 +1,16 @@ { config, lib, + pkgs, ... }: let inherit (builtins) concatStringsSep elem; - inherit (lib) mkEnableOption mkForce mkIf mkMerge mkOption optionals types; + inherit (lib) generators mkEnableOption mkForce mkIf mkMerge mkOption optionals types; enable = elem "virtualisation" config.hardware.support; cfg = config.hardware.vm; in { options.hardware.vm = { - vfio = mkEnableOption "Configure the device for VFIO"; + vfio = mkEnableOption "Configure VFIO PCI passthrough"; passthrough = mkOption { description = "PCI Device IDs for VFIO"; type = types.listOf types.str; @@ -50,6 +51,7 @@ in { "vfio_iommu_type1" "vfio_virqfd" ] + # GPU Passthrough ++ optionals (elem "nvidia" config.services.xserver.videoDrivers) [ "nvidia" "nvidia_modeset" @@ -57,6 +59,51 @@ in { "nvidia_drm" ]; }; + + # Looking Glass + user.groups = ["kvm" "libvirtd" "qemu-libvirtd"]; + systemd.tmpfiles.rules = ["f /dev/shm/looking-glass 0660 root qemu-libvirtd -"]; + environment = { + systemPackages = [pkgs.looking-glass-client]; + etc."looking-glass-client.ini".text = generators.toINI {} { + app.renderer = "egl"; + win = { + title = "Virtual Machine"; + autoResize = "yes"; + borderless = "no"; + dontUpscale = "yes"; + fullScreen = "no"; + keepAspect = "yes"; + maximize = "no"; + noScreensaver = "yes"; + quickSplash = "yes"; + uiSize = 16; + }; + + egl = { + scale = 2; + multisample = "yes"; + vsync = "yes"; + }; + + input = { + autoCapture = "yes"; + grabKeyboardOnFocus = "yes"; + rawMouse = "yes"; + releaseKeysOnFocusLoss = "yes"; + }; + + spice = { + enable = "yes"; + clipboard = "yes"; + }; + + wayland = { + warpSupport = "yes"; + fractionScale = "no"; + }; + }; + }; }) ]; }