diff --git a/hardware/amd/cpu.nix b/hardware/amd/cpu.nix new file mode 100644 index 0000000..507ddea --- /dev/null +++ b/hardware/amd/cpu.nix @@ -0,0 +1,35 @@ +{config, pkgs, lib, ...}: +with lib; +let + generalCfg = config.aviallon.general; + cpuIsZen = ! isNull (builtins.match "znver[0-9]" generalCfg.cpuArch); +in { + config = mkIf (generalCfg.cpuVendor == "amd") { + boot.kernel.sysctl = { + + # Why: https://www.phoronix.com/news/Ryzen-Segv-Response + # Workaround: https://forums.gentoo.org/viewtopic-p-2605135.html#2605135 + "kernel.randomize_va_space" = mkIf (generalCfg.cpuArch == "znver1" ) (warn "Disable Adress Space Layout Randomization on Ryzen 1 CPU" 0); + }; + + aviallon.boot.cmdline = { + "amd_pstate" = "passive"; + } // optionalAttrs (generalCfg.cpuArch == "znver2") { + # Required for Zen 2 + "amd_pstate.shared_memory" = 1; + }; + + boot.extraModulePackages = with config.boot.kernelPackages; [] + ++ optional cpuIsZen (info "enable zenpower for Ryzen CPU" zenpower) + ; + + boot.kernelModules = [] + ++ optional cpuIsZen "zenpower" + ; + + boot.blacklistedKernelModules = [] + ++ optional cpuIsZen "k10-temp" # Superseded by zenpower + ; + }; +} + diff --git a/hardware/amd/default.nix b/hardware/amd/default.nix index e3b8522..b9c81f7 100644 --- a/hardware/amd/default.nix +++ b/hardware/amd/default.nix @@ -16,6 +16,9 @@ in { }; }; + imports = [ + ./cpu.nix + ]; config = mkIf (cfg.enable) { boot.initrd.kernelModules = [ "amdgpu" ];