2024-05-07 23:31:41 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
system,
|
|
|
|
...
|
|
|
|
}:
|
2024-04-30 22:04:17 +02:00
|
|
|
let
|
|
|
|
cfg = config.grimmShared;
|
2024-05-07 23:31:41 +02:00
|
|
|
inherit (lib)
|
|
|
|
optionals
|
|
|
|
optional
|
|
|
|
optionalString
|
|
|
|
concatLines
|
|
|
|
getExe
|
|
|
|
;
|
2024-05-02 14:02:35 +02:00
|
|
|
inherit (config.boot.kernelPackages) x86_energy_perf_policy cpupower;
|
2024-05-07 20:47:08 +02:00
|
|
|
enable_perf_policy = (lib.elem system x86_energy_perf_policy.meta.platforms);
|
2024-05-02 14:02:35 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
powersave =
|
|
|
|
with pkgs;
|
|
|
|
writeShellScriptBin "powersave-mode" (
|
|
|
|
concatLines (
|
|
|
|
[
|
|
|
|
"${getExe cpupower} frequency-set -g powersave -u 2000000" # clock speed
|
|
|
|
"${getExe pkgs.brightnessctl} s 20%" # display brightness
|
|
|
|
]
|
|
|
|
++ optionals enable_perf_policy [
|
|
|
|
"${getExe x86_energy_perf_policy} 15" # power save preference
|
|
|
|
"${getExe x86_energy_perf_policy} --turbo-enable 0" # disable turbo
|
|
|
|
]
|
|
|
|
++ optional cfg.sway.enable "init-screens-min"
|
|
|
|
)
|
|
|
|
);
|
2024-05-02 14:02:35 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
performance = pkgs.writeShellScriptBin "performance-mode" (
|
|
|
|
concatLines (
|
|
|
|
[
|
|
|
|
"${getExe cpupower} frequency-set frequency-set -g performance -u 5000000" # clock speed
|
|
|
|
"${getExe pkgs.brightnessctl} s 100%" # display brightness
|
|
|
|
]
|
|
|
|
++ optionals enable_perf_policy [
|
|
|
|
"${getExe x86_energy_perf_policy} 0" # performance preference
|
|
|
|
"${getExe x86_energy_perf_policy} --turbo-enable 1" # enable turbo
|
|
|
|
]
|
|
|
|
++ optional cfg.sway.enable "init-screens-max"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
auto =
|
|
|
|
let
|
|
|
|
inherit (pkgs) tlp;
|
|
|
|
in
|
|
|
|
pkgs.writeShellScriptBin "auto-mode" ''
|
|
|
|
${tlp}/bin/run-on-ac ${getExe performance}
|
|
|
|
${tlp}/bin/run-on-bat ${getExe powersave}
|
|
|
|
'';
|
2024-04-30 22:04:17 +02:00
|
|
|
in
|
|
|
|
{
|
2024-05-07 23:31:41 +02:00
|
|
|
config =
|
|
|
|
with cfg;
|
|
|
|
lib.mkIf (enable && laptop_hardware.enable) {
|
|
|
|
environment.systemPackages =
|
|
|
|
with pkgs;
|
|
|
|
[
|
|
|
|
acpi
|
|
|
|
powertop
|
|
|
|
brightnessctl
|
|
|
|
cpupower
|
|
|
|
powersave
|
|
|
|
performance
|
|
|
|
auto
|
|
|
|
]
|
|
|
|
++ optionals graphical [ tlpui ]
|
|
|
|
++ optional enable_perf_policy x86_energy_perf_policy;
|
2024-04-30 22:04:17 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
services.acpid = {
|
|
|
|
enable = true;
|
|
|
|
acEventCommands = getExe auto;
|
|
|
|
};
|
2024-05-02 15:04:38 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
powerManagement.scsiLinkPolicy = lib.mkIf (!config.services.tlp.enable) "min_power";
|
|
|
|
powerManagement.cpuFreqGovernor = lib.mkDefault "normal";
|
2024-04-30 22:04:17 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
services.power-profiles-daemon.enable = false;
|
|
|
|
services.upower.enable = true;
|
2024-05-08 12:47:03 +02:00
|
|
|
boot.extraModulePackages = [
|
|
|
|
cpupower
|
|
|
|
] ++ optional enable_perf_policy x86_energy_perf_policy;
|
2024-04-30 22:04:17 +02:00
|
|
|
|
2024-05-07 23:31:41 +02:00
|
|
|
services.tlp = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
USB_AUTOSUSPEND = 1;
|
|
|
|
USB_EXCLUDE_BTUSB = 1;
|
|
|
|
USB_EXCLUDE_PHONE = 1;
|
|
|
|
SOUND_POWER_SAVE_ON_AC = 0;
|
|
|
|
SOUND_POWER_SAVE_ON_BAT = 1;
|
|
|
|
SATA_LINKPWR_ON_AC = "max_performance";
|
|
|
|
SATA_LINKPWR_ON_BAT = "min_power";
|
|
|
|
MAX_LOST_WORK_SECS_ON_BAT = 15;
|
|
|
|
CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
|
|
|
|
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
|
|
|
|
CPU_BOOST_ON_AC = 1;
|
|
|
|
CPU_BOOST_ON_BAT = 0;
|
|
|
|
RUNTIME_PM_ON_AC = "on";
|
|
|
|
RUNTIME_PM_ON_BAT = "auto";
|
|
|
|
};
|
2024-04-30 22:04:17 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|