2024-10-11 23:27:07 +03:00
|
|
|
{
|
2024-12-18 09:40:11 +03:00
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.module.powersave;
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
script = pkgs.writeShellScriptBin "powersave" ''
|
|
|
|
function toggle() {
|
|
|
|
if status; then
|
|
|
|
echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile}
|
|
|
|
else
|
|
|
|
echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile}
|
|
|
|
fi
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
pkill -RTMIN+5 waybar
|
|
|
|
true
|
|
|
|
}
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
function widget() {
|
|
|
|
status && printf '' || printf ''
|
|
|
|
}
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
function status() {
|
|
|
|
local current=$(cat ${cfg.cpu.boost.controlFile})
|
|
|
|
local enabled="${cfg.cpu.boost.enableCmd}"
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
[[ "''${current}" = "''${enabled}" ]]
|
|
|
|
}
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
''${@}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ script ];
|
|
|
|
systemd = {
|
|
|
|
services.powersave-cpu = {
|
|
|
|
enable = true;
|
|
|
|
description = "disable CPU Boost";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = "${lib.getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile}'";
|
|
|
|
ExecStop = "${lib.getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile}'";
|
|
|
|
};
|
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
|
2024-12-18 09:40:11 +03:00
|
|
|
# HACK: Allow user access.
|
|
|
|
tmpfiles.rules = [ "z ${cfg.cpu.boost.controlFile} 0777 - - - -" ];
|
|
|
|
};
|
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
}
|