From 5edcb857af5dc231add07d199df64df0d1e464cc Mon Sep 17 00:00:00 2001 From: blahai Date: Sun, 12 Jan 2025 19:18:13 +0200 Subject: [PATCH] Hardware stuffies --- modules/nixos/default.nix | 1 + modules/nixos/hardware/cpu/amd.nix | 17 +++++ modules/nixos/hardware/cpu/default.nix | 17 +++++ modules/nixos/hardware/default.nix | 7 ++ modules/nixos/hardware/firmwares.nix | 1 + modules/nixos/hardware/gpu/amd.nix | 24 +++++++ modules/nixos/hardware/gpu/default.nix | 20 ++++++ modules/nixos/hardware/gpu/novideo.nix | 93 ++++++++++++++++++++++++++ systems/nyx/default.nix | 4 ++ 9 files changed, 184 insertions(+) create mode 100644 modules/nixos/hardware/cpu/amd.nix create mode 100644 modules/nixos/hardware/cpu/default.nix create mode 100644 modules/nixos/hardware/default.nix create mode 100644 modules/nixos/hardware/firmwares.nix create mode 100644 modules/nixos/hardware/gpu/amd.nix create mode 100644 modules/nixos/hardware/gpu/default.nix create mode 100644 modules/nixos/hardware/gpu/novideo.nix diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index 17c625f..fb0898c 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -2,6 +2,7 @@ imports = [ ./boot ./environment + ./hardware ./networking ]; } diff --git a/modules/nixos/hardware/cpu/amd.nix b/modules/nixos/hardware/cpu/amd.nix new file mode 100644 index 0000000..f0c302d --- /dev/null +++ b/modules/nixos/hardware/cpu/amd.nix @@ -0,0 +1,17 @@ +{ + config, + lib, + ... +}: let + inherit (config.olympus) device; + inherit (lib.modules) mkIf; +in { + config = mkIf (device.cpu == "amd") { + hardware.cpu.amd.updateMicrocode = true; + + boot.kernelModules = [ + "kvm-amd" + "amd-pstate" + ]; + }; +} diff --git a/modules/nixos/hardware/cpu/default.nix b/modules/nixos/hardware/cpu/default.nix new file mode 100644 index 0000000..cb46e1e --- /dev/null +++ b/modules/nixos/hardware/cpu/default.nix @@ -0,0 +1,17 @@ +{lib, ...}: let + inherit (lib) mkOption types; +in { + imports = [ + ./amd.nix + ]; + + options.olympus.device.cpu = mkOption { + type = types.nullOr ( + types.enum [ + "amd" + ] + ); + default = null; + description = "CPU brand"; + }; +} diff --git a/modules/nixos/hardware/default.nix b/modules/nixos/hardware/default.nix new file mode 100644 index 0000000..4c3bb6d --- /dev/null +++ b/modules/nixos/hardware/default.nix @@ -0,0 +1,7 @@ +{ + imports = [ + ./cpu + ./gpu + ./firmwares.nix + ]; +} diff --git a/modules/nixos/hardware/firmwares.nix b/modules/nixos/hardware/firmwares.nix new file mode 100644 index 0000000..95fdc15 --- /dev/null +++ b/modules/nixos/hardware/firmwares.nix @@ -0,0 +1 @@ +{hardware.enableRedistributableFirmware = true;} diff --git a/modules/nixos/hardware/gpu/amd.nix b/modules/nixos/hardware/gpu/amd.nix new file mode 100644 index 0000000..b96a894 --- /dev/null +++ b/modules/nixos/hardware/gpu/amd.nix @@ -0,0 +1,24 @@ +{ + lib, + pkgs, + config, + ... +}: let + inherit (lib.modules) mkIf; + inherit (config.olympus) device; +in { + config = mkIf (device.gpu == "amd") { + services.xserver.videoDrivers = ["amdgpu"]; + + boot = { + kernelModules = ["amdgpu"]; + initrd.kernelModules = ["amdgpu"]; + }; + + # enables AMDVLK & OpenCL support + hardware.graphics.extraPackages = [ + pkgs.rocmPackages.clr + pkgs.rocmPackages.clr.icd + ]; + }; +} diff --git a/modules/nixos/hardware/gpu/default.nix b/modules/nixos/hardware/gpu/default.nix new file mode 100644 index 0000000..5f7d317 --- /dev/null +++ b/modules/nixos/hardware/gpu/default.nix @@ -0,0 +1,20 @@ +{lib, ...}: let + inherit (lib) mkOption types; +in { + imports = [ + ./amd.nix + ./novideo.nix + ]; + + options.olympus.device.gpu = mkOption { + type = types.nullOr ( + types.enum [ + "amd" + "nvidia" + "hybrid-nv" + ] + ); + default = null; + description = "GPU brand"; + }; +} diff --git a/modules/nixos/hardware/gpu/novideo.nix b/modules/nixos/hardware/gpu/novideo.nix new file mode 100644 index 0000000..36d9d5a --- /dev/null +++ b/modules/nixos/hardware/gpu/novideo.nix @@ -0,0 +1,93 @@ +{ + lib, + pkgs, + config, + ... +}: let + inherit (config.olympus) device; + inherit + (lib.modules) + mkIf + mkMerge + mkDefault + ; + inherit (lib.validators) isWayland; + + isHybrid = device.gpu == "hybrid-nv"; +in { + config = mkIf (device.gpu == "nvidia" || device.gpu == "hybrid-nv") { + # nvidia drivers kinda are unfree software + nixpkgs.config.allowUnfree = true; + + services.xserver = mkMerge [ + {videoDrivers = ["nvidia"];} + + # xorg settings + ]; + + boot = { + # blacklist nouveau module as otherwise it conflicts with nvidia drm + blacklistedKernelModules = ["nouveau"]; + + # Enables the Nvidia's experimental framebuffer device + # fix for the imaginary monitor that does not exist + kernelParams = ["nvidia_drm.fbdev=1"]; + }; + + environment = { + sessionVariables = mkMerge [ + {LIBVA_DRIVER_NAME = "nvidia";} + + (mkIf (isWayland config) { + # GBM_BACKEND = "nvidia-drm"; # breaks firefox apparently + + WLR_DRM_DEVICES = mkDefault "/dev/dri/card1"; + }) + ]; + + systemPackages = builtins.attrValues { + inherit (pkgs.nvtopPackages) nvidia; + + inherit + (pkgs) + # mesa + mesa + # vulkan + vulkan-tools + vulkan-loader + vulkan-validation-layers + vulkan-extension-layer + # libva + libva + libva-utils + ; + }; + }; + + hardware = { + nvidia = { + package = mkDefault config.boot.kernelPackages.nvidiaPackages.beta; + + prime.offload = { + enable = isHybrid; + enableOffloadCmd = isHybrid; + }; + + powerManagement = { + enable = mkDefault true; + finegrained = mkDefault false; + }; + + open = false; # dont use the open drivers by default + nvidiaSettings = false; # adds nvidia-settings to pkgs, so useless on nixos + nvidiaPersistenced = true; + # forceFullCompositionPipeline = true; + }; + + graphics = { + extraPackages = [pkgs.nvidia-vaapi-driver]; + extraPackages32 = [pkgs.pkgsi686Linux.nvidia-vaapi-driver]; + }; + }; + }; +} diff --git a/systems/nyx/default.nix b/systems/nyx/default.nix index 20d8d98..1c1afbc 100644 --- a/systems/nyx/default.nix +++ b/systems/nyx/default.nix @@ -4,6 +4,10 @@ ]; olympus = { + device = { + cpu = "amd"; + gpu = "amd"; + }; system = { boot = { loader = "systemd-boot";