43 lines
1.3 KiB
Nix
43 lines
1.3 KiB
Nix
{ pkgs, ... }:
|
|
|
|
{
|
|
systemd.services.battery-low = {
|
|
serviceConfig.Type = "simple";
|
|
path = [
|
|
pkgs.acpi
|
|
pkgs.gawk # I was too lazy to find out where awk lives, it's not coreutils, hopefully it works the same
|
|
pkgs.libnotify
|
|
];
|
|
startAt = "*08:00:00";
|
|
script = ''
|
|
#!/usr/bin/env bash
|
|
if [ `acpi -b | grep "Battery 0" | gawk ' { print ($3)}'` == "Discharging," ] ; then
|
|
# Discharging
|
|
# Monitor for low battery
|
|
rm /tmp/battery-full
|
|
if [ `acpi -b | grep "Battery 0" | gawk ' { print ($4)-0}'` -le "15" ] ; then
|
|
notify-send -u critical "Battery Low";
|
|
fi
|
|
else
|
|
# Charging
|
|
if [ `acpi -b | grep "Battery 0" | gawk ' { print ($4)-0}'` -ge "94" ] ; then
|
|
# Fully charged
|
|
if [[ -f /tmp/battery-full ]]; then
|
|
touch /tmp/battery-full;
|
|
notify-send "Battery Full"
|
|
fi
|
|
fi
|
|
fi
|
|
'';
|
|
serviceConfig = {
|
|
User = "anish";
|
|
Environment = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus";
|
|
};
|
|
};
|
|
systemd.timers.battery-low = {
|
|
wantedBy = [ "timers.target" ];
|
|
partOf = [ "battery-low.service" ];
|
|
timerConfig.OnCalendar = [ "*:0/5" ];
|
|
};
|
|
}
|