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

36 lines
921 B
Nix
Raw Permalink 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
if [ `acpi -b | grep "Battery 2" | awk ' { print ($3)}'` == "Discharging," ] ; then
# Discharging
# Monitor for low battery
if [ `acpi -b | grep "Battery 2" | awk ' { print ($4)-0}'` -le "15" ] ; then
notify-send "Battery Low";
fi
else
# Charging
if [ `acpi -b | grep "Battery 2" | awk ' { print ($4)-0}'` -ge "98" ] ; 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" ];
};
}