diff --git a/home/battery/default.nix b/home/battery/default.nix new file mode 100644 index 0000000..b896fc4 --- /dev/null +++ b/home/battery/default.nix @@ -0,0 +1,50 @@ +{ config, pkgs, ... }: + +let + batteryNotify = pkgs.writeShellScript "battery-notify" '' + BAT="/sys/class/power_supply/BAT1" + LEVEL=$(cat "$BAT/capacity") + STATUS=$(cat "$BAT/status") + + if [ "$STATUS" = "Discharging" ] && [ "$LEVEL" -lt 90 ]; then + ${pkgs.dunst}/bin/dunstify \ + -r 9991 \ + -t 0 \ + -u critical \ + "Battery Low" \ + "Battery is at ''${LEVEL}%" + else + ${pkgs.dunst}/bin/dunstify \ + -C 9991 2>/dev/null || true + fi + ''; +in +{ + systemd.user.services.battery-notify = { + Unit = { + Description = "Low battery notification"; + After = [ "dunst.service" ]; + Requires = [ "dunst.service" ]; + }; + + Service = { + Type = "oneshot"; + ExecStart = batteryNotify; + }; + }; + + systemd.user.timers.battery-notify = { + Unit = { + Description = "Check battery level every 20 seconds"; + }; + + Timer = { + OnBootSec = "20s"; + OnUnitActiveSec = "20s"; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; +} diff --git a/home/default.nix b/home/default.nix index 1b566e5..c486f86 100644 --- a/home/default.nix +++ b/home/default.nix @@ -2,6 +2,7 @@ { imports = [ + ./battery ./btop ./dunst ./eza diff --git a/hosts/common.nix b/hosts/common.nix index 50a9ef4..b847804 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -54,10 +54,8 @@ environment.systemPackages = with pkgs; [ libinput - nodejs gnupg age - eza yazi gitui bind diff --git a/hosts/tardis/default.nix b/hosts/tardis/default.nix index b186449..d2dc11c 100644 --- a/hosts/tardis/default.nix +++ b/hosts/tardis/default.nix @@ -4,8 +4,6 @@ imports = [ ./hardware-configuration.nix - - ../../modules/battery ]; boot.blacklistedKernelModules = [ diff --git a/modules/battery/default.nix b/modules/battery/default.nix deleted file mode 100644 index 060ec16..0000000 --- a/modules/battery/default.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ 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"; - }; - }; -}