nixdots/system/roles/laptop/power/power-profiles-daemon/default.nix

44 lines
1.2 KiB
Nix
Raw Normal View History

2024-07-26 23:07:07 +00:00
{
pkgs,
lib,
config,
...
}: let
inherit (lib) mkIf;
inherit (lib.modules) mkForce;
inherit (lib.strings) makeBinPath;
deviceType = config.myOptions.device.roles.type;
acceptedTypes = ["laptop"];
in {
config = mkIf (builtins.elem deviceType acceptedTypes) {
# allows changing system behavior based upon user-selected power profiles
# (with `powerprofilesctl` command)
services.power-profiles-daemon.enable = true;
# 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
2024-04-13 23:12:48 +00:00
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;
serviceConfig = {
Type = "simple";
Restart = "on-failure";
};
wants = ["power-profiles-daemon.service"];
wantedBy = ["default.target"];
};
};
}