helm/profiles/desktop/battery-low-timer.nix

36 lines
933 B
Nix
Raw Normal View History

2022-08-30 01:53:43 -07:00
{ pkgs, ... }:
{
systemd.services.battery-low = {
serviceConfig.Type = "simple";
path = [
pkgs.acpi
];
startAt = "*08:00:00";
script = ''
#!/usr/bin/env bash
2022-09-02 23:21:06 -07:00
if [ `acpi -b | grep "Battery 0" | awk ' { print ($3)}'` == "Discharging," ] ; then
2022-08-30 01:53:43 -07:00
# Discharging
# Monitor for low battery
2022-09-02 23:21:06 -07:00
if [ `acpi -b | grep "Battery 0" | awk ' { print ($4)-0}'` -le "15" ] ; then
notify-send -u critical "Battery Low";
2022-08-30 01:53:43 -07:00
fi
else
# Charging
2022-09-02 23:21:06 -07:00
if [ `acpi -b | grep "Battery 0" | awk ' { print ($4)-0}'` -ge "94" ] ; then
2022-08-30 01:53:43 -07:00
# Fully charged
notify-send "Battery Full"
fi
fi
'';
serviceConfig = {
User = "anish";
};
};
systemd.timers.battery-low = {
wantedBy = [ "timers.target" ];
partOf = [ "battery-low.service" ];
timerConfig.OnCalendar = [ "*:0/5" ];
};
}