[Nix-dev] hibernating when battery gets low?

Marc Weber marco-oweber at gmx.de
Sun May 23 18:42:45 CEST 2010


Which is the best way to
a) notify the user if battery gets low
b) hibernate if user doesn't act upon notificaton?

Of course which kind of notification the user prefers and the action
should be customizable which means it should be a shell script.

Does this already exist as NixOS module somewhere?

The implementation could be dead simple:

job battery observer:

  while :; do
    sleep 1m;
    if [ battery_discharging  -a battery_capacity < 5% ]; then
      start warn_low_battery_wait_then_hibernate || true # if job is already running ignore errors
    else
      stop warn_low_battery_wait_then_hibernate || true
    fi
  done


job warn_low_battery_wait_then_hibernate:

  for i in `seq 5 -1 1`; do
    DISLPAY=:0.0 xmessage "battery is low, Plug in the power cable!. I'll hibernate in $i minutes!"
  done
  run custom action such as pm-hibernate


That's simple and does the job. Would this duplicate any existing
efforts?

Marc Weber



More information about the nix-dev mailing list