aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-02 06:16:11 +0100
committerAkshay <[email protected]>2021-10-02 06:16:11 +0100
commit94d534975ab228b27d4713f7dec41bfa3900fdfb (patch)
treeb63c5ef86b83935a27b287c842a1b7fa64368049 /services
parent804ad2b07645b4cb2e44449720d54ed94106a116 (diff)
rework services
Diffstat (limited to 'services')
-rw-r--r--services/battery.nix48
-rw-r--r--services/suspend.nix8
2 files changed, 4 insertions, 52 deletions
diff --git a/services/battery.nix b/services/battery.nix
deleted file mode 100644
index a871e8f..0000000
--- a/services/battery.nix
+++ /dev/null
@@ -1,48 +0,0 @@
1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.services.battery-alert;
6 bat = pkgs.writeScriptBin "bat"
7 ''
8 '';
9in
10{
11 options.services.battery-alert = {
12 enable = mkOption {
13 type = types.bool;
14 default = false;
15 description = ''
16 If enabled, NixOS will periodically check battery levels and report
17 if it is below a threshold value.
18 '';
19 };
20 };
21
22 config = {
23 systemd.user.timers.battery-alert = mkIf cfg.enable {
24 description = "Periodically check battery status and alert if required";
25 timerConfig.OnBootSec = "1m";
26 timerConfig.OnUnitInactiveSec = "1m";
27 timerConfig.Unit = "battery-alert.service";
28 wantedBy = [ "timers.target" ];
29 };
30
31 systemd.user.services.battery-alert = {
32 description = "Check battery levels";
33 path = [ pkgs.libnotify pkgs.coreutils ];
34 serviceConfig = {
35 PassEnvironment = "DISPLAY XAUTHORITY";
36 };
37 script = ''
38 bat_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity )
39 charging_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/status )
40
41 # if [[ $bat_status -ge 10 ]]; then
42 ${pkgs.libnotify}/bin/notify-send "Battery low: $bat_status%" "$charging_status"
43 # fi
44 '';
45 };
46
47 };
48}
diff --git a/services/suspend.nix b/services/suspend.nix
index 445446b..35e213a 100644
--- a/services/suspend.nix
+++ b/services/suspend.nix
@@ -37,8 +37,8 @@ in
37 config = mkIf cfg.enable { 37 config = mkIf cfg.enable {
38 systemd.user.timers."lowbatt" = { 38 systemd.user.timers."lowbatt" = {
39 description = "check battery level"; 39 description = "check battery level";
40 timerConfig.OnBootSec = "1m"; 40 timerConfig.OnBootSec = "5m";
41 timerConfig.OnUnitInactiveSec = "1m"; 41 timerConfig.OnUnitInactiveSec = "5m";
42 timerConfig.Unit = "lowbatt.service"; 42 timerConfig.Unit = "lowbatt.service";
43 wantedBy = [ "timers.target" ]; 43 wantedBy = [ "timers.target" ];
44 }; 44 };
@@ -49,10 +49,10 @@ in
49 export battery_capacity=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/capacity) 49 export battery_capacity=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/capacity)
50 export battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) 50 export battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status)
51 if [[ $battery_capacity -le ${builtins.toString cfg.notifyCapacity} && $battery_status = "Discharging" ]]; then 51 if [[ $battery_capacity -le ${builtins.toString cfg.notifyCapacity} && $battery_status = "Discharging" ]]; then
52 ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low" "You should probably plug-in." 52 ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low: $battery_capacity%"
53 fi 53 fi
54 if [[ $battery_capacity -le ${builtins.toString cfg.suspendCapacity} && $battery_status = "Discharging" ]]; then 54 if [[ $battery_capacity -le ${builtins.toString cfg.suspendCapacity} && $battery_status = "Discharging" ]]; then
55 ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low" "Computer will suspend in 60 seconds." 55 ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low: $battery_capacity%"
56 sleep 60s 56 sleep 60s
57 battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) 57 battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status)
58 if [[ $battery_status = "Discharging" ]]; then 58 if [[ $battery_status = "Discharging" ]]; then