2024-07-26 23:07:07 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2024-04-13 20:18:21 +00:00
|
|
|
inherit (lib.modules) mkForce;
|
|
|
|
inherit (lib.strings) makeBinPath;
|
|
|
|
in {
|
2024-09-24 09:40:42 +00:00
|
|
|
# allows changing system behavior based upon user-selected power profiles
|
|
|
|
# (with `powerprofilesctl` command)
|
|
|
|
services.power-profiles-daemon.enable = true;
|
2024-04-13 20:18:21 +00:00
|
|
|
|
2024-09-24 09:40:42 +00:00
|
|
|
# Power state monitor. Switches power profiles based on charging state.
|
|
|
|
# Plugged in - performance (if available, falls back to balance)
|
|
|
|
# Unplugged - balanced, until below 50%, then power-saver
|
|
|
|
systemd.services."power-monitor" = let
|
|
|
|
dependencies = with pkgs; [
|
|
|
|
coreutils
|
|
|
|
gnugrep
|
|
|
|
power-profiles-daemon
|
|
|
|
inotify-tools
|
|
|
|
jaq
|
|
|
|
];
|
|
|
|
in {
|
|
|
|
description = "Power Monitoring Service";
|
|
|
|
environment.PATH = mkForce "/run/wrappers/bin:${makeBinPath dependencies}";
|
|
|
|
script = builtins.readFile ./power_monitor.sh;
|
2024-04-13 20:18:21 +00:00
|
|
|
|
2024-09-24 09:40:42 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "on-failure";
|
2024-04-13 20:18:21 +00:00
|
|
|
};
|
2024-09-24 09:40:42 +00:00
|
|
|
|
|
|
|
wants = ["power-profiles-daemon.service"];
|
|
|
|
wantedBy = ["default.target"];
|
2024-04-13 20:18:21 +00:00
|
|
|
};
|
|
|
|
}
|