From f982861233725293fbfa2c3da1084df67c16b090 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 9 Jan 2025 22:00:00 +0000 Subject: [PATCH] Remove notify-battery script with i3-battery-popup https://github.com/rjekker/i3-battery-popup --- nix/home/opdavies/default.nix | 1 - nix/hosts/lemp11/configuration.nix | 6 ---- nix/hosts/t490/services/default.nix | 6 ---- nix/modules/nixos/i3.nix | 9 +----- nix/pkgs/default.nix | 2 +- nix/pkgs/i3-battery-popup.nix | 21 +++++++++++++ nix/pkgs/notify-battery.nix | 46 ----------------------------- 7 files changed, 23 insertions(+), 68 deletions(-) create mode 100644 nix/pkgs/i3-battery-popup.nix delete mode 100644 nix/pkgs/notify-battery.nix diff --git a/nix/home/opdavies/default.nix b/nix/home/opdavies/default.nix index f4b099f..1056634 100644 --- a/nix/home/opdavies/default.nix +++ b/nix/home/opdavies/default.nix @@ -54,7 +54,6 @@ in build-glove80 gscan2pdf meslo-lg - notify-battery obs-studio okular pamixer diff --git a/nix/hosts/lemp11/configuration.nix b/nix/hosts/lemp11/configuration.nix index 469f702..7fb172d 100644 --- a/nix/hosts/lemp11/configuration.nix +++ b/nix/hosts/lemp11/configuration.nix @@ -148,12 +148,6 @@ services.blueman.enable = true; - services.cron = { - enable = true; - - systemCronJobs = [ "* * * * * opdavies /home/${username}/.local/bin/notify-battery" ]; - }; - services.auto-cpufreq.enable = true; services.udev = { diff --git a/nix/hosts/t490/services/default.nix b/nix/hosts/t490/services/default.nix index 4b00029..c73817e 100644 --- a/nix/hosts/t490/services/default.nix +++ b/nix/hosts/t490/services/default.nix @@ -19,12 +19,6 @@ blueman.enable = true; - cron = { - enable = true; - - systemCronJobs = [ "* * * * * opdavies /home/${username}/.local/bin/notify-battery" ]; - }; - gvfs.enable = true; openssh.enable = true; power-profiles-daemon.enable = false; diff --git a/nix/modules/nixos/i3.nix b/nix/modules/nixos/i3.nix index eb8c0c4..94e9373 100644 --- a/nix/modules/nixos/i3.nix +++ b/nix/modules/nixos/i3.nix @@ -20,14 +20,6 @@ in config = mkIf config.features.desktop.i3.enable { services = { - cron = { - enable = true; - - systemCronJobs = [ - "* * * * * opdavies ${pkgs.notify-battery}/bin/notify-battery" - ]; - }; - displayManager.defaultSession = "none+i3"; xserver = { @@ -108,6 +100,7 @@ in exec_always --no-startup-id caffeine exec_always --no-startup-id ${pkgs.autorandr}/bin/autorandr --change + exec_always --no-startup-id ${pkgs.i3-battery-popup}/bin/i3-battery-popup -n smart_borders on smart_gaps on diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index b42201e..a91c709 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -8,7 +8,7 @@ in { build-glove80 = callPackage ./build-glove80.nix { }; notes = callPackage ./notes.nix { }; - notify-battery = callPackage ./notify-battery.nix { }; + i3-battery-popup = callPackage ./i3-battery-popup.nix { }; tmux-sessionizer = callPackage ./tmux-sessionizer.nix { }; vimPlugins = prev.vimPlugins // vimPlugins; diff --git a/nix/pkgs/i3-battery-popup.nix b/nix/pkgs/i3-battery-popup.nix new file mode 100644 index 0000000..9cd1505 --- /dev/null +++ b/nix/pkgs/i3-battery-popup.nix @@ -0,0 +1,21 @@ +{ pkgs, ... }: + +pkgs.stdenv.mkDerivation rec { + pname = "i3-battery-popop"; + version = "1.1.1"; + + src = pkgs.fetchFromGitHub { + owner = "rjekker"; + repo = "i3-battery-popup"; + rev = "v${version}"; + sha256 = "s6jZCkB0Z8dtnBG2p1NJIUY1fV4urEp4w6wFzxFNlqg="; + }; + + buildInputs = with pkgs; [ bash ]; + + installPhase = '' + mkdir -p $out/bin + cp $src/i3-battery-popup $out/bin/i3-battery-popup + chmod +x $out/bin/i3-battery-popup + ''; +} diff --git a/nix/pkgs/notify-battery.nix b/nix/pkgs/notify-battery.nix deleted file mode 100644 index 7355f4f..0000000 --- a/nix/pkgs/notify-battery.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ pkgs, ... }: - -pkgs.writeShellApplication { - name = "notify-battery"; - - runtimeInputs = with pkgs; [ - acpi - bash - coreutils - dbus - ]; - - text = '' - set +o nounset - set +o pipefail - - export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" - export DISPLAY=:0 - - # Battery percentage at which to notify. - BATTERY_DISCHARGING=$(acpi -b | grep "Battery 0" | grep -c "Discharging") - BATTERY_LEVEL=$(acpi -b | grep "Battery 0" | grep -P -o '[0-9]+(?=%)') - WARNING_LEVEL=20 - - # Use two files to store whether we've shown a notification or not (to prevent multiple notifications). - EMPTY_FILE=/tmp/battery-empty - FULL_FILE=/tmp/battery-full - - # Reset notifications if the computer is charging/discharging. - if [ "$BATTERY_DISCHARGING" -eq 1 ] && [ -f $FULL_FILE ]; then - rm $FULL_FILE - elif [ "$BATTERY_DISCHARGING" -eq 0 ] && [ -f $EMPTY_FILE ]; then - rm $EMPTY_FILE - fi - - # If the battery is charging and is full (and has not shown notification yet). - if [ "$BATTERY_LEVEL" -gt 95 ] && [ "$BATTERY_DISCHARGING" -eq 0 ] && [ ! -f $FULL_FILE ]; then - notify-send "Battery Charged" "Battery is fully charged." -r 9991 - touch $FULL_FILE - # If the battery is low and is not charging (and has not shown notification yet). - elif [ "$BATTERY_LEVEL" -le $WARNING_LEVEL ] && [ "$BATTERY_DISCHARGING" -eq 1 ] && [ ! -f $EMPTY_FILE ]; then - notify-send "Low Battery" "''${BATTERY_LEVEL}% of battery remaining." -u critical -r 9991 -t 0 - touch $EMPTY_FILE - fi - ''; -}