From 562ec40d05bd1249db8389180baf86e9675789de Mon Sep 17 00:00:00 2001 From: Syed Daanish Date: Tue, 7 Jul 2026 19:23:46 +0100 Subject: [PATCH] Add battery timer and btop --- home/btop/default.nix | 12 +++++++++++ home/default.nix | 1 + hosts/tardis/default.nix | 2 ++ modules/battery/default.nix | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 home/btop/default.nix create mode 100644 modules/battery/default.nix diff --git a/home/btop/default.nix b/home/btop/default.nix new file mode 100644 index 0000000..5ba2936 --- /dev/null +++ b/home/btop/default.nix @@ -0,0 +1,12 @@ +{ ... }: + +{ + programs.btop = { + enable = true; + + settings = { + color_theme = "Default"; + theme_background = false; + }; + }; +} diff --git a/home/default.nix b/home/default.nix index c6284a8..a016a60 100644 --- a/home/default.nix +++ b/home/default.nix @@ -2,6 +2,7 @@ { imports = [ + ./btop ./dunst ./eza ./fastfetch diff --git a/hosts/tardis/default.nix b/hosts/tardis/default.nix index 75a899d..3ca1a89 100644 --- a/hosts/tardis/default.nix +++ b/hosts/tardis/default.nix @@ -4,6 +4,8 @@ imports = [ ./hardware-configuration.nix + + ../../modules/battery ]; boot.blacklistedKernelModules = [ diff --git a/modules/battery/default.nix b/modules/battery/default.nix new file mode 100644 index 0000000..060ec16 --- /dev/null +++ b/modules/battery/default.nix @@ -0,0 +1,40 @@ +{ config, pkgs, ... }: + +let + batteryNotify = pkgs.writeShellScript "battery-notify" '' + BAT="/sys/class/power_supply/BAT1" + LEVEL=$(cat "$BAT/capacity") + STATUS=$(cat "$BAT/status") + ID=9991 + + if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 20 ]; then + ${pkgs.dunst}/bin/dunstify \ + -r "$ID" -t 0 \ + -u critical \ + "Battery Low" \ + "Battery is at ''${LEVEL}%" + else + ${pkgs.dunst}/bin/dunstify \ + -C "$ID" 2>/dev/null || true + fi + ''; +in +{ + systemd.services.battery-notify = { + description = "Low battery notification"; + serviceConfig = { + Type = "oneshot"; + ExecStart = batteryNotify; + }; + }; + + systemd.timers.battery-notify = { + description = "Check battery level every 20 seconds"; + wantedBy = [ "timers.target" ]; + + timerConfig = { + OnBootSec = "20s"; + OnUnitActiveSec = "20s"; + }; + }; +}