dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
commit 6ac77fc8e16ce247d0a2755de2551f1ec305e5c8 parent ff6f6196e8c02bee763af0873716ced9e3e1a67a Author: maydayv7 <maydayv7@gmail.com> Date: Tue, 30 Dec 2025 16:32:00 +0530 fix: Refactor `hardware.gpu` and add `hardware.cpu.model` Also fix VFIO
Diffstat:
| M | CHANGELOG.md | | | 1 | + |
| M | devices/futura.nix | | | 6 | +++++- |
| M | devices/valkyrie/default.nix | | | 10 | ++++++++-- |
| D | devices/valkyrie/drivers.nix | | | 67 | ------------------------------------------------------------------- |
| A | devices/valkyrie/settings/default.nix | | | 67 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | devices/vortex.nix | | | 6 | +++++- |
| M | files/swaync.css | | | 5 | +++++ |
| M | modules/README.md | | | 5 | ++++- |
| M | modules/apps/git/hosting.nix | | | 3 | ++- |
| A | modules/hardware/cpu.nix | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
| M | modules/hardware/default.nix | | | 23 | ----------------------- |
| M | modules/hardware/gpu.nix | | | 73 | +++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
| M | modules/hardware/virtualisation/default.nix | | | 8 | +++----- |
| M | modules/hardware/virtualisation/vfio.nix | | | 23 | +++++++---------------- |
14 files changed, 201 insertions(+), 143 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -2,6 +2,7 @@ ### December +- Refactor `hardware.gpu` and add `hardware.cpu.model` - Use `swaync` instead of `dunst` - Niri Updates - Update to v25.11 diff --git a/devices/futura.nix b/devices/futura.nix @@ -10,8 +10,12 @@ kernel = "lts"; hardware = { boot = "efi"; - cpu.cores = 4; fs.scheme = "simple"; + cpu = { + model = "intel"; + cores = 4; + }; + support = [ "laptop" ]; modules = [ "common-pc" diff --git a/devices/valkyrie/default.nix b/devices/valkyrie/default.nix @@ -13,7 +13,7 @@ ]; imports = [ - ./drivers.nix + ./settings ./minecraft.nix ]; @@ -21,11 +21,17 @@ boot = "secure"; fs.scheme = "advanced"; modules = [ "asus-zephyrus-ga402x-nvidia" ]; - gpu = "nvidia"; cpu = { + model = "amd"; cores = 8; mode = "performance"; }; + + gpu = { + enable = true; + model = "nvidia"; + }; + support = [ "laptop" "mobile" diff --git a/devices/valkyrie/drivers.nix b/devices/valkyrie/drivers.nix @@ -1,67 +0,0 @@ -{ - config, - lib, - ... -}: -let - inherit (lib) hasPrefix mkIf; -in -{ - # ! # https://gitlab.freedesktop.org/drm/amd/-/issues/3388 - boot.kernelParams = mkIf (config.hardware.cpu.mode == "performance") [ "amdgpu.dcdebugmask=0x10" ]; - - services = { - fwupd.enable = true; - - # Remap Keys - udev.extraHwdb = '' - evdev:name:Asus Keyboard:* - KEYBOARD_KEY_7003f=print # F6 -> PrtSc Key - ''; - }; - - # Development - networking.firewall = { - allowedUDPPorts = [ 7777 ]; - allowedTCPPorts = [ 7777 ]; - }; - - # ASUS Software - services.asusd = { - enable = true; - enableUserService = true; - asusdConfig.text = builtins.readFile ./settings/asusd.ron; - auraConfigs."19b6".text = builtins.readFile ./settings/aura.ron; - }; - - user = { - persist.directories = [ ".config/rog" ]; - homeConfig = { - wayland.windowManager.hyprland.settings.bindl = mkIf (hasPrefix "hyprland" config.gui.desktop) [ - ", XF86Launch3, exec, asusctl led-mode -n" - ", XF86Launch4, exec, asusctl profile -n" - ]; - - dconf.settings = mkIf (hasPrefix "gnome" config.gui.desktop) { - "org/gnome/settings-daemon/plugins/media-keys" = { - custom-keybindings = [ - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/" - ]; - }; - - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3" = { - binding = "Launch3"; - command = "asusctl led-mode -n"; - name = "Keyboard Mode"; - }; - - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4" = { - binding = "Launch4"; - command = "asusctl profile -n"; - name = "Fan Control"; - }; - }; - }; - }; -} diff --git a/devices/valkyrie/settings/default.nix b/devices/valkyrie/settings/default.nix @@ -0,0 +1,67 @@ +{ + config, + lib, + ... +}: +let + inherit (lib) hasPrefix mkIf; +in +{ + # ! # https://gitlab.freedesktop.org/drm/amd/-/issues/3388 + boot.kernelParams = mkIf (config.hardware.cpu.mode == "performance") [ "amdgpu.dcdebugmask=0x10" ]; + + services = { + fwupd.enable = true; + + # Remap Keys + udev.extraHwdb = '' + evdev:name:Asus Keyboard:* + KEYBOARD_KEY_7003f=print # F6 -> PrtSc Key + ''; + }; + + # Development + networking.firewall = { + allowedUDPPorts = [ 7777 ]; + allowedTCPPorts = [ 7777 ]; + }; + + # ASUS Software + services.asusd = { + enable = true; + enableUserService = true; + asusdConfig.text = builtins.readFile ./asusd.ron; + auraConfigs."19b6".text = builtins.readFile ./aura.ron; + }; + + user = { + persist.directories = [ ".config/rog" ]; + homeConfig = { + wayland.windowManager.hyprland.settings.bindl = mkIf (hasPrefix "hyprland" config.gui.desktop) [ + ", XF86Launch3, exec, asusctl led-mode -n" + ", XF86Launch4, exec, asusctl profile -n" + ]; + + dconf.settings = mkIf (hasPrefix "gnome" config.gui.desktop) { + "org/gnome/settings-daemon/plugins/media-keys" = { + custom-keybindings = [ + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/" + ]; + }; + + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3" = { + binding = "Launch3"; + command = "asusctl led-mode -n"; + name = "Keyboard Mode"; + }; + + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4" = { + binding = "Launch4"; + command = "asusctl profile -n"; + name = "Fan Control"; + }; + }; + }; + }; +} diff --git a/devices/vortex.nix b/devices/vortex.nix @@ -17,7 +17,11 @@ boot = "secure"; fs.scheme = "advanced"; modules = [ "dell-inspiron-5509" ]; - cpu.cores = 8; + cpu = { + model = "intel"; + cores = 8; + }; + support = [ "laptop" "mobile" diff --git a/files/swaync.css b/files/swaync.css @@ -45,6 +45,7 @@ trough slider:hover { color: #@base05; margin: 6px 12px; border-radius: 12px; + border: solid 0.5px #@base05; box-shadow: 0 0 8px rgba(0, 0, 0, 0.8), inset 0 0 0 1px #@base03; @@ -195,6 +196,10 @@ trough slider:hover { margin-top: 12px; } +.notification-group-headers { + margin-bottom: 5px; +} + .notification-group-icon { margin-right: 12px; } diff --git a/modules/README.md b/modules/README.md @@ -63,9 +63,12 @@ Configuration [Builder](./configuration.nix) - `scheme`: Disk Filesystem Scheme - `"simple" / "advanced"` - `persist`: System Files to Preserve across Reboots (while using `advanced` File System Layout) - `cpu` - + - `model`: CPU Model - `"amd" / "intel"` - `cores`: Number of CPU Cores - Ex. `4` - `mode`: CPU Frequency Governor Mode - `"ondemand" / "performance" / "powersave"` - - `gpu`: Discrete GPU Support - `null / "nvidia"` + - `gpu` - + - `enable`: Discrete GPU Support - `"true" / "false"` + - `model`: Discrete GPU Model - `null / "nvidia"` - `modules`: List of Hardware Configuration Modules imported from [`inputs.hardware`](https://github.com/nixos/nixos-hardware) - Ex. `[ "common-pc" ]` - `support`: List of Additional Supported Hardware - `[ "laptop" "mobile" "printer" "virtualisation" "blockchain" ]` - `vm`: Configure Virtualisation Support - diff --git a/modules/apps/git/hosting.nix b/modules/apps/git/hosting.nix @@ -1,5 +1,6 @@ { config, + options, lib, ... }: @@ -12,7 +13,7 @@ let ; inherit (config.apps.git.hosting) enable domain secret; - opt = config.apps.git.hosting; + opt = options.apps.git.hosting; in { options.apps.git.hosting = { diff --git a/modules/hardware/cpu.nix b/modules/hardware/cpu.nix @@ -0,0 +1,47 @@ +{ + config, + options, + lib, + ... +}: +let + inherit (lib) mkOption optional types; + cfg = config.hardware.cpu; + opt = options.hardware.cpu; +in +{ + ## CPU Configuration ## + options.hardware.cpu = { + model = mkOption { + description = "CPU Model"; + type = types.enum [ + "" + "amd" + "intel" + ]; + default = ""; + }; + + cores = mkOption { + description = "Number of CPU Cores"; + type = types.int; + default = 4; + }; + + mode = mkOption { + description = "CPU Frequency Governor Mode"; + type = types.enum [ + "ondemand" + "performance" + "powersave" + ]; + default = "performance"; + }; + }; + + config = { + warnings = optional (cfg.model == "") (opt.model.description + " is unset"); + powerManagement.cpuFreqGovernor = cfg.mode; + nix.settings.max-jobs = cfg.cores; + }; +} diff --git a/modules/hardware/default.nix b/modules/hardware/default.nix @@ -1,5 +1,4 @@ { - config, inputs, lib, util, @@ -8,31 +7,12 @@ let inherit (util.map) modules; inherit (lib) mkForce mkOption types; - cfg = config.hardware; in { ## HARDWARE Configuration ## imports = modules.list ./.; options.hardware = with types; { - cpu = { - cores = mkOption { - description = "Number of CPU Cores"; - type = int; - default = 4; - }; - - mode = mkOption { - description = "CPU Frequency Governor Mode"; - type = enum [ - "ondemand" - "performance" - "powersave" - ]; - default = "performance"; - }; - }; - modules = mkOption { description = "List of Modules imported from 'inputs.hardware'"; type = listOf (enum (attrNames inputs.hardware.nixosModules)); @@ -47,9 +27,6 @@ in }; config = { - powerManagement.cpuFreqGovernor = cfg.cpu.mode; - nix.settings.max-jobs = cfg.cpu.cores; - specialisation.powersave.configuration = { system.nixos.label = "special.powersave"; gui.fancy = mkForce false; diff --git a/modules/hardware/gpu.nix b/modules/hardware/gpu.nix @@ -1,5 +1,6 @@ { config, + options, lib, pkgs, ... @@ -8,22 +9,38 @@ let inherit (lib) mkForce mkIf + mkEnableOption mkMerge mkOption types ; - cfg = config.hardware; + cfg = config.hardware.gpu; + opt = options.hardware.gpu; + mode = config.hardware.cpu.mode == "performance"; in { - options.hardware.gpu = mkOption { - description = "Discrete GPU Support"; - type = with types; nullOr (enum [ "nvidia" ]); - default = null; + ## GPU Configuration ## + options.hardware.gpu = { + enable = mkEnableOption "Discrete GPU Support"; + model = mkOption { + description = "Discrete GPU Model"; + type = with types; nullOr (enum [ "nvidia" ]); + default = null; + }; }; config = mkMerge [ - (mkIf (cfg.gpu == "nvidia") { + (mkIf cfg.enable { + assertions = [ + { + assertion = cfg.model != null; + message = opt.model.description + " must be set"; + } + ]; + }) + + (mkIf (cfg.enable && cfg.model == "nvidia") { services.xserver.videoDrivers = mkForce [ "nvidia" ]; environment = { systemPackages = [ pkgs.btop-cuda ]; @@ -45,27 +62,31 @@ in ]; }; - hardware.nvidia = - let - enable = cfg.vm.vfio != "on"; - mode = cfg.cpu.mode == "performance"; - in - { - modesetting.enable = mkForce true; - nvidiaSettings = mkForce true; - dynamicBoost = { inherit enable; }; - powerManagement = { inherit enable; }; - prime = - with cfg.nvidia.prime; - mkIf (amdgpuBusId != "" || intelBusId != "") { - sync.enable = mkForce false; - reverseSync.enable = mkForce mode; - offload = { - enable = mkForce (!mode); - enableOffloadCmd = mkForce (!mode); - }; + hardware.nvidia = { + modesetting.enable = mkForce true; + nvidiaSettings = mkForce true; + dynamicBoost.enable = true; + powerManagement.enable = true; + prime = + with config.hardware.nvidia.prime; + mkIf (amdgpuBusId != "" || intelBusId != "") { + sync.enable = mkForce false; + reverseSync.enable = mkForce mode; + offload = { + enable = mkForce (!mode); + enableOffloadCmd = mkForce (!mode); }; - }; + }; + }; + }) + + (mkIf (!cfg.enable && cfg.model == "nvidia") { + boot.blacklistedKernelModules = [ + "nvidia" + "nvidia_drm" + "nvidia_modeset" + "nvidia_uvm" + ]; }) ]; } diff --git a/modules/hardware/virtualisation/default.nix b/modules/hardware/virtualisation/default.nix @@ -7,6 +7,7 @@ ... }: let + inherit (config.hardware.cpu) model; enable = builtins.elem "virtualisation" config.hardware.support; in { @@ -26,11 +27,8 @@ in environment.persist.directories = [ "/var/lib/libvirt" ]; security.virtualisation.flushL1DataCache = "cond"; boot = { - kernelModules = [ - "kvm-amd" - "kvm-intel" - ]; - extraModprobeConfig = "options kvm_intel nested=1"; + kernelModules = [ "kvm-${model}" ]; + extraModprobeConfig = "options kvm_${model} nested=1"; }; # VM Packages diff --git a/modules/hardware/virtualisation/vfio.nix b/modules/hardware/virtualisation/vfio.nix @@ -15,8 +15,9 @@ let types ; - enable = elem "virtualisation" config.hardware.support; cfg = config.hardware.vm; + inherit (config.hardware.cpu) model; + enable = elem "virtualisation" config.hardware.support; in { options.hardware.vm = { @@ -59,35 +60,25 @@ in hardware.vm.vfio = mkForce "setup"; }; + # Disable GPU + hardware.gpu.enable = mkForce false; + boot = { kernelParams = [ "iommu=pt" - "amd_iommu=pt" - "intel_iommu=pt" - "i915.enable_gvt=1" + "${model}_iommu=on" "kvm.ignore_msrs=1" "kvm.report_ignored_msrs=0" ("vfio-pci.ids=" + concatStringsSep "," cfg.passthrough) ]; - kernelModules = [ + initrd.kernelModules = [ "vfio" "vfio_pci" "vfio_iommu_type1" - "vfio_virqfd" - ]; - - # Disable GPU - blacklistedKernelModules = [ - "nvidia" - "nvidia_drm" - "nvidia_modeset" - "nvidia_uvm" ]; }; - hardware.gpu = mkForce null; - # Looking Glass user.groups = [ "qemu-libvirtd" ]; systemd.tmpfiles.rules = [ "f /dev/shm/looking-glass 0660 root qemu-libvirtd -" ];