From 94d534975ab228b27d4713f7dec41bfa3900fdfb Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 Oct 2021 10:46:11 +0530 Subject: rework services --- services/battery.nix | 48 ------------------------------------------------ services/suspend.nix | 8 ++++---- 2 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 services/battery.nix (limited to 'services') 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 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - cfg = config.services.battery-alert; - bat = pkgs.writeScriptBin "bat" - '' - ''; -in -{ - options.services.battery-alert = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - If enabled, NixOS will periodically check battery levels and report - if it is below a threshold value. - ''; - }; - }; - - config = { - systemd.user.timers.battery-alert = mkIf cfg.enable { - description = "Periodically check battery status and alert if required"; - timerConfig.OnBootSec = "1m"; - timerConfig.OnUnitInactiveSec = "1m"; - timerConfig.Unit = "battery-alert.service"; - wantedBy = [ "timers.target" ]; - }; - - systemd.user.services.battery-alert = { - description = "Check battery levels"; - path = [ pkgs.libnotify pkgs.coreutils ]; - serviceConfig = { - PassEnvironment = "DISPLAY XAUTHORITY"; - }; - script = '' - bat_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity ) - charging_status=$( ${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/status ) - - # if [[ $bat_status -ge 10 ]]; then - ${pkgs.libnotify}/bin/notify-send "Battery low: $bat_status%" "$charging_status" - # fi - ''; - }; - - }; -} 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 config = mkIf cfg.enable { systemd.user.timers."lowbatt" = { description = "check battery level"; - timerConfig.OnBootSec = "1m"; - timerConfig.OnUnitInactiveSec = "1m"; + timerConfig.OnBootSec = "5m"; + timerConfig.OnUnitInactiveSec = "5m"; timerConfig.Unit = "lowbatt.service"; wantedBy = [ "timers.target" ]; }; @@ -49,10 +49,10 @@ in export battery_capacity=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/capacity) export battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) if [[ $battery_capacity -le ${builtins.toString cfg.notifyCapacity} && $battery_status = "Discharging" ]]; then - ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low" "You should probably plug-in." + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low: $battery_capacity%" fi if [[ $battery_capacity -le ${builtins.toString cfg.suspendCapacity} && $battery_status = "Discharging" ]]; then - ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low" "Computer will suspend in 60 seconds." + ${pkgs.libnotify}/bin/notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low: $battery_capacity%" sleep 60s battery_status=$(${pkgs.coreutils}/bin/cat /sys/class/power_supply/${cfg.device}/status) if [[ $battery_status = "Discharging" ]]; then -- cgit v1.2.3