helm/profiles/desktop/battery-low-timer.nix
2022-09-03 16:21:06 +10:00

36 lines
933 B
Nix

{ pkgs, ... }:
{
systemd.services.battery-low = {
serviceConfig.Type = "simple";
path = [
pkgs.acpi
];
startAt = "*08:00:00";
script = ''
#!/usr/bin/env bash
if [ `acpi -b | grep "Battery 0" | awk ' { print ($3)}'` == "Discharging," ] ; then
# Discharging
# Monitor for low battery
if [ `acpi -b | grep "Battery 0" | awk ' { print ($4)-0}'` -le "15" ] ; then
notify-send -u critical "Battery Low";
fi
else
# Charging
if [ `acpi -b | grep "Battery 0" | awk ' { print ($4)-0}'` -ge "94" ] ; then
# 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" ];
};
}