mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
treewide: remove battery-notify script
This commit is contained in:
parent
32b6fbccf0
commit
ae8273ee9d
5 changed files with 0 additions and 84 deletions
|
|
@ -1,70 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
cfg = config.services."battery-notify";
|
||||
in {
|
||||
options = {
|
||||
services."battery-notify" = {
|
||||
enable = lib.mkEnableOption "battery-notify";
|
||||
triggerLevel = lib.mkOption {
|
||||
type = with lib.types; ints.between 0 100;
|
||||
description = "Below which percentage should the script send a notification";
|
||||
default = 20;
|
||||
};
|
||||
checkAt = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
description = "At which frequency should the service check for the battery status";
|
||||
default = ["*:0/5"]; # every five minutes
|
||||
};
|
||||
device_full = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "The device to read for full energy status";
|
||||
};
|
||||
device_now = lib.mkOption {
|
||||
type = with lib.types; str;
|
||||
description = "The device to read for current energy status";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.user.services."battery-notify" = {
|
||||
Unit.Description = "Notify when battery is low";
|
||||
Install = {
|
||||
WantedBy = ["multi-user.target"];
|
||||
};
|
||||
Service = {
|
||||
ExecStart = let
|
||||
script = pkgs.writeShellApplication {
|
||||
name = "battery-notify";
|
||||
runtimeInputs = [
|
||||
pkgs.libnotify
|
||||
pkgs.bc
|
||||
pkgs.uutils-coreutils-noprefix
|
||||
];
|
||||
text = ''
|
||||
now="$(cat ${cfg.device_now})"
|
||||
full="$(cat ${cfg.device_full})"
|
||||
|
||||
if (( $(bc -l <<< "($now / $full) * 100 < ${builtins.toString cfg.triggerLevel}") )); then
|
||||
notify-send -u critical "Battery Low" "Please charge your battery"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in "${lib.getExe script}";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.user.timers."battery-notify" = {
|
||||
Unit.Description = "Notify when battery is low";
|
||||
Timer = {
|
||||
OnCalendar = cfg.checkAt;
|
||||
Persistent = true;
|
||||
};
|
||||
Install.WantedBy = ["timers.target"];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue