From 45ab7efecf0f14a8138b062a149a2381a639eda8 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Fri, 20 Mar 2026 20:18:05 +0300 Subject: [PATCH] powersave config --- configuration.nix | 1 + modules/packages.nix | 2 ++ modules/power.nix | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 modules/power.nix diff --git a/configuration.nix b/configuration.nix index 88c1e38..444270b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -15,6 +15,7 @@ ./modules/programs.nix ./modules/wireguard.nix ./modules/security.nix + ./modules/power.nix ]; # This value determines the NixOS release from which the default diff --git a/modules/packages.nix b/modules/packages.nix index 0c4ebe9..e1ad694 100644 --- a/modules/packages.nix +++ b/modules/packages.nix @@ -95,6 +95,8 @@ kubectx # switch between contexts/namespaces stern # multi-pod log tailing hcloud # Hetzner Cloud CLI + packer # image builder + talosctl # Talos OS CLI eksctl # AWS EKS CLI # terragrunt # broken in nixpkgs gh diff --git a/modules/power.nix b/modules/power.nix new file mode 100644 index 0000000..5eea7c4 --- /dev/null +++ b/modules/power.nix @@ -0,0 +1,61 @@ +# Power management — ThinkPad T14 Gen 2 (AMD) +{ config, pkgs, lib, ... }: + +{ + # AMD P-State driver (active mode for full EPP control) + boot.kernelParams = [ "amd_pstate=active" ]; + + # CPU frequency scaling + powerManagement.cpuFreqGovernor = "powersave"; + + # Disable power-profiles-daemon (conflicts with TLP) + services.power-profiles-daemon.enable = false; + + # TLP — main power management daemon + services.tlp = { + enable = true; + settings = { + # CPU + CPU_SCALING_GOVERNOR_ON_AC = "performance"; + CPU_SCALING_GOVERNOR_ON_BAT = "powersave"; + CPU_ENERGY_PERF_POLICY_ON_AC = "balance_performance"; + CPU_ENERGY_PERF_POLICY_ON_BAT = "power"; + CPU_BOOST_ON_AC = 1; + CPU_BOOST_ON_BAT = 0; + PLATFORM_PROFILE_ON_AC = "balanced"; + PLATFORM_PROFILE_ON_BAT = "low-power"; + + # AMD P-State + CPU_DRIVER_OPMODE_ON_AC = "active"; + CPU_DRIVER_OPMODE_ON_BAT = "active"; + + # WiFi + WIFI_PWR_MGT_ON_AC = "off"; + WIFI_PWR_MGT_ON_BAT = "on"; + + # PCIe ASPM + PCIE_ASPM_ON_AC = "default"; + PCIE_ASPM_ON_BAT = "powersupersave"; + + # Runtime PM + RUNTIME_PM_ON_AC = "on"; + RUNTIME_PM_ON_BAT = "auto"; + + # NVMe + NVME_RUNTIME_PM_ON_AC = "on"; + NVME_RUNTIME_PM_ON_BAT = "auto"; + + # USB autosuspend + USB_AUTOSUSPEND = 1; + }; + }; + + # Bluetooth off at boot + hardware.bluetooth.powerOnBoot = false; + + # Battery monitoring + services.upower.enable = true; + + # powertop for diagnostics + environment.systemPackages = [ pkgs.powertop ]; +}