From b35c93e8a22eaa5aa755e8faa6c9070731d3b78b Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Fri, 16 Dec 2022 06:58:12 +0800 Subject: [PATCH 1/3] Add mkDefault to services.xserver.videoDrivers = [ "amdgpu" ]; --- common/gpu/amd/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/gpu/amd/default.nix b/common/gpu/amd/default.nix index 762b3c0..9b1d77c 100644 --- a/common/gpu/amd/default.nix +++ b/common/gpu/amd/default.nix @@ -2,7 +2,7 @@ { boot.initrd.kernelModules = [ "amdgpu" ]; - services.xserver.videoDrivers = [ "amdgpu" ]; + services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" ]; hardware.opengl.extraPackages = with pkgs; [ rocm-opencl-icd From b67160bb7f479e5042eeadd4453517e2d27ebca6 Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 16 Dec 2022 17:43:40 +0300 Subject: [PATCH 2/3] cpu/amd/pstate: enable correctly on kernel 6.1+ There is no separate module now, and a clean option to enable it. --- common/cpu/amd/pstate.nix | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/common/cpu/amd/pstate.nix b/common/cpu/amd/pstate.nix index 7d5c2c0..ab07a91 100644 --- a/common/cpu/amd/pstate.nix +++ b/common/cpu/amd/pstate.nix @@ -1,10 +1,22 @@ -{ lib, config, ... }: { +{ lib, config, ... }: +let + kver = config.boot.kernelPackages.kernel.version; +in +{ # Enables the amd cpu scaling https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html # On recent AMD CPUs this can be more energy efficient. imports = [ ./. ]; - boot = lib.mkIf (lib.versionAtLeast config.boot.kernelPackages.kernel.version "5.17") { - kernelParams = [ "initcall_blacklist=acpi_cpufreq_init" ]; - kernelModules = [ "amd-pstate" ]; - }; + boot = lib.mkMerge [ + (lib.mkIf ( + (lib.versionAtLeast kver "5.17") + && (lib.versionOlder kver "6.1") + ) { + kernelParams = [ "initcall_blacklist=acpi_cpufreq_init" ]; + kernelModules = [ "amd-pstate" ]; + }) + (lib.mkIf (lib.versionAtLeast kver "6.1") { + kernelParams = [ "amd_pstate=passive" ]; + }) + ]; } From a1a8723bf9786436f0f784736a5c1e55c7e330b0 Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Fri, 16 Dec 2022 05:01:50 +0800 Subject: [PATCH 3/3] Add a option to add(or disadd) amdgpu to kernelModule Add a option to add(or disadd) amdgpu to boot.initrd.kernelModule --- common/gpu/amd/default.nix | 46 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/common/gpu/amd/default.nix b/common/gpu/amd/default.nix index 762b3c0..91ba0b7 100644 --- a/common/gpu/amd/default.nix +++ b/common/gpu/amd/default.nix @@ -1,23 +1,35 @@ { config, lib, pkgs, ... }: { - boot.initrd.kernelModules = [ "amdgpu" ]; - services.xserver.videoDrivers = [ "amdgpu" ]; - - hardware.opengl.extraPackages = with pkgs; [ - rocm-opencl-icd - rocm-opencl-runtime - amdvlk - ]; - - hardware.opengl.extraPackages32 = with pkgs; [ - driversi686Linux.amdvlk - ]; - - hardware.opengl = { - driSupport = lib.mkDefault true; - driSupport32Bit = lib.mkDefault true; + options.hardware.amdgpu.loadInInitrd = lib.mkEnableOption (lib.mdDoc + "loading `amdgpu` kernelModule at stage 1. (Add `amdgpu` to `boot.initrd.kernelModules`)" + ) // { + default = true; }; - environment.variables.AMD_VULKAN_ICD = lib.mkDefault "RADV"; + config = lib.mkMerge [ + { + services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" ]; + + hardware.opengl.extraPackages = with pkgs; [ + rocm-opencl-icd + rocm-opencl-runtime + amdvlk + ]; + + hardware.opengl.extraPackages32 = with pkgs; [ + driversi686Linux.amdvlk + ]; + + hardware.opengl = { + driSupport = lib.mkDefault true; + driSupport32Bit = lib.mkDefault true; + }; + + environment.variables.AMD_VULKAN_ICD = lib.mkDefault "RADV"; + } + (lib.mkIf config.hardware.amdgpu.loadInInitrd { + boot.initrd.kernelModules = [ "amdgpu" ]; + }) + ]; }