chore(aspen/system): Drop custom battery service in favor of upower

Change-Id: Ie3e5aeba7026724dacbe4d0dc15a1112a22c3670
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11304
Autosubmit: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: aspen <root@gws.fyi>
This commit is contained in:
Aspen Smith 2024-03-31 14:16:05 -04:00 committed by clbot
parent 1dd378b0b8
commit d959358e1f
2 changed files with 14 additions and 39 deletions

View file

@ -1,15 +1,22 @@
{ config, lib, pkgs, ... }:
{
imports = [
./reusable/battery.nix
];
services.logind = {
powerKey = "hibernate";
powerKeyLongPress = "poweroff";
lidSwitch = "hybrid-sleep";
lidSwitchExternalPower = "ignore";
};
laptop.onLowBattery.enable = true;
services.logind.extraConfig = ''
HandlePowerKey=hibernate
systemd.sleep.extraConfig = ''
HibernateDelaySec=30m
SuspendState=mem
'';
services.tlp.enable = true;
services.upower = {
enable = true;
criticalPowerAction = "Hibernate";
};
}

View file

@ -1,32 +0,0 @@
{ config, lib, pkgs, ... }:
with lib;
{
options = {
laptop.onLowBattery = {
enable = mkEnableOption "Perform action on low battery";
thresholdPercentage = mkOption {
description = "Threshold battery percentage on which to perform the action";
default = 8;
type = types.int;
};
action = mkOption {
description = "Action to perform on low battery";
default = "hibernate";
type = types.enum [ "hibernate" "suspend" "suspend-then-hibernate" ];
};
};
};
config =
let cfg = config.laptop.onLowBattery;
in mkIf cfg.enable {
services.udev.extraRules = concatStrings [
''SUBSYSTEM=="power_supply", ''
''ATTR{status}=="Discharging", ''
''ATTR{capacity}=="[0-${toString cfg.thresholdPercentage}]", ''
''RUN+="${pkgs.systemd}/bin/systemctl ${cfg.action}"''
];
};
}