forked from
lass.pds.lassul.us/superconfig
This repository has no description
1.2 kB
46 lines
1{ pkgs, ... }:
2
3let
4 # Script that monitors upower D-Bus signals and speaks when battery gets low
5 batteryMonitor = pkgs.writers.writeBash "battery-monitor" ''
6 ${pkgs.upower}/bin/upower --monitor-detail | while read -r line; do
7 if echo "$line" | grep -q "warning-level:.*low"; then
8 ${pkgs.espeak}/bin/espeak -v +whisper -s 110 "power level low"
9 fi
10 done
11 '';
12
13in
14{
15 # UPower handles battery monitoring via kernel events (not polling)
16 services.upower = {
17 enable = true;
18
19 # Use percentage thresholds instead of time-based
20 usePercentageForPolicy = true;
21
22 # Warning levels (triggers D-Bus signals for our monitor)
23 percentageLow = 15;
24 percentageCritical = 10;
25
26 # Suspend when battery drops below this
27 percentageAction = 5;
28
29 # Action to take at critical level
30 criticalPowerAction = "Suspend";
31 allowRiskyCriticalPowerAction = true;
32 };
33
34 # User service to monitor battery and speak warnings
35 systemd.user.services.battery-warning = {
36 description = "Battery low warning speaker";
37 wantedBy = [ "default.target" ];
38 after = [ "upower.service" ];
39
40 serviceConfig = {
41 ExecStart = batteryMonitor;
42 Restart = "always";
43 RestartSec = 5;
44 };
45 };
46}