Auto: cleanup-2026-05-24T10-18-36Z

This commit is contained in:
2026-05-24 12:18:49 +02:00
parent 4dc460dc0c
commit 16c01a5e67
71 changed files with 1770 additions and 1731 deletions
+151 -150
View File
@@ -1,4 +1,4 @@
{ ... }: {
_: {
flake.nixosModules.battery-laptop = {
lib,
config,
@@ -20,7 +20,7 @@
# type = lib.types.bool;
# };
# };
# config = lib.mkIf cfg.battery.enable {
powerManagement.powertop.enable = true; # enable powertop auto tuning on startup.
# Acording to https://community.frame.work/t/solved-keys-stick-and-repeat-after-being-released/51153/12
@@ -53,7 +53,7 @@
};
# };
};
perSystem = { pkgs, ... }: let
perSystem = {pkgs, ...}: let
NotifySound = ../../assets/battery_notify.mp3;
in {
packages.custom-batterynotify = pkgs.writeShellApplication {
@@ -65,33 +65,33 @@
brightnessctl
];
text = ''
# Delay for startup
sleep 5
# Change your sound path here
playsound() {
mplayer ${NotifySound}
}
adjustBrightness() {
local adjustment="$1"
brightnessctl set "$adjustment"
}
sendNotification() {
local title="$1"
local message="$2"
notify-send -h string:x-canonical-private-synchronous:sys-notify -e -u low "$title" "$message"
}
# Runs full time in background
x=0
while true; do
Battery_Status="$(\cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity=$(\cat /sys/class/power_supply/BAT*/capacity)
case "$Battery_Status" in
"Discharging")
if [ $x -eq 1 ]; then
@@ -117,7 +117,7 @@
fi
;;
esac
sleep 1
done
'';
@@ -130,27 +130,27 @@
brightnessctl
];
text = ''
# Delay for startup
sleep 5
playsound() {
mplayer ${NotifySound}
}
while true; do
Battery_Status="$(cat /sys/class/power_supply/BAT*/status)"
Battery_Capacity="$(cat /sys/class/power_supply/BAT*/capacity)"
if [ "$Battery_Status" == "Discharging" ]; then
if [ "$Battery_Capacity" -le 20 ] && [ "$Battery_Capacity" -ge 10 ]; then
notify-send -e -u critical "Battery Low!" "Power running out: <b>''${Battery_Capacity}%</b>"
playsound
sleep 180
elif [ "$Battery_Capacity" -lt 10 ]; then
notify-send -e -u critical "Battery Low!" "<b>Save your works</b> before immediate shutdown."
playsound
@@ -170,7 +170,7 @@
packages.qtbatticon = pkgs.stdenv.mkDerivation {
pname = "qtbatticon";
version = "1.0";
src = pkgs.writeTextFile {
name = "qtbatticon.cpp";
text = ''
@@ -183,252 +183,253 @@
#include <QString>
#include <QDebug>
#include <cstdlib>
QString readFile(const QString &path) {
QFile f(path);
if (!f.open(QIODevice::ReadOnly)) return "";
QTextStream in(&f);
return in.readAll().trimmed();
}
int readInt(const QString &path) {
return readFile(path).toInt();
}
double readDouble(const QString &path) {
QFile f(path);
if (!f.open(QIODevice::ReadOnly)) return 0;
QTextStream in(&f);
return in.readAll().trimmed().toDouble();
}
int toStep(int capacity) {
return (capacity / 10) * 10;
}
QString pad3(int n) {
return QString("%1").arg(n, 3, 10, QChar('0'));
}
double getPowerW(const QString &batPath) {
double current_uA = readDouble(batPath + "/current_now");
double voltage_uV = readDouble(batPath + "/voltage_now");
if (current_uA > 0 && voltage_uV > 0) {
return (current_uA * voltage_uV) / 1e12;
}
return -1;
}
QIcon batteryIcon(int capacity, bool charging) {
int step = toStep(capacity);
QString num = pad3(step);
QString base = "/run/current-system/sw/share/icons/Papirus/24x24/panel/";
QString file;
if (charging) {
file = base + "battery-" + num + "-charging.svg";
} else {
file = base + "battery-" + num + ".svg";
}
QIcon icon(file);
if (icon.isNull()) {
qDebug() << "FAILED icon:" << file;
icon = QIcon(base + "battery-100.svg");
}
return icon;
}
void sendNotification(const QString &title, const QString &body) {
QString cmd = "notify-send \"" + title + "\" \"" + body + "\"";
system(cmd.toUtf8().constData());
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QString batPath = "/sys/class/power_supply/BAT1";
QSystemTrayIcon tray;
auto updateIcon = [&]() {
int capacity = readInt(batPath + "/capacity");
QString status = readFile(batPath + "/status");
bool charging = status.contains("Charging");
tray.setIcon(batteryIcon(capacity, charging));
};
auto notify = [&]() {
int capacity = readInt(batPath + "/capacity");
QString status = readFile(batPath + "/status");
bool charging = status.contains("Charging");
bool discharging = status.contains("Discharging");
double power = getPowerW(batPath);
QString state;
if (charging) state = "Charging";
else if (discharging) state = "Discharging";
else state = status;
QString powerStr = (power > 0.01)
? QString::number(power, 'f', 2) + " W"
: "N/A";
QString msg =
QString("%1\n%2%\n%3")
.arg(state)
.arg(capacity)
.arg(powerStr);
sendNotification("Battery status", msg);
};
QObject::connect(&tray, &QSystemTrayIcon::activated,
[&](QSystemTrayIcon::ActivationReason r) {
if (r == QSystemTrayIcon::Trigger) {
notify();
}
});
updateIcon();
tray.setVisible(true);
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, updateIcon);
timer.start(5000);
return app.exec();
}
'';
};
nativeBuildInputs = with pkgs; [
pkg-config
qt6.wrapQtAppsHook
];
buildInputs = with pkgs; [
qt6.qtbase
qt6.qtsvg
papirus-icon-theme
];
dontUnpack = true;
buildPhase = ''
g++ $src -o qtbatticon \
$(pkg-config --cflags --libs Qt6Widgets)
'';
installPhase = ''
mkdir -p $out/bin
install -m755 qtbatticon $out/bin/
'';
};
# This was replaced by caelestia shell's Game Mode
packages.custom-performance = pkgs.writeShellApplication {
name = "custom-performance";
runtimeInputs = with pkgs; [
hyprland
gawk
libnotify
];
text = ''
HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}')
if [ "$HYPRGAMEMODE" = 1 ] ; then
hyprctl --batch "\
keyword animations:enabled 0;\
keyword animation borderangle,0; \
keyword decoration:shadow:enabled 0;\
keyword decoration:blur:enabled 0;\
keyword decoration:fullscreen_opacity 1;\
keyword general:gaps_in 0;\
keyword general:gaps_out 0;\
keyword general:border_size 1;\
keyword decoration:rounding 0"
notify-send -u critical -t 5000 "Performance mode [ON]"
exit
else
notify-send -u critical -t 5000 "Performance mode [OFF]"
hyprctl reload
exit 0
fi
'';
};
# Old script that was used for the battery. Might not work.
packages.custom-olddeprecatedbatterynotify = pkgs.writeShellApplication {
name = "custom-olddeprecatedbatterynotify";
runtimeInputs = with pkgs; [
libnotify # provides notify-send
systemd # provides systemctl
];
text = ''
set -euo pipefail
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
INTERVAL="''${BATTERY_INTERVAL:-30}"
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
notify() {
notify-send -a "Battery" -u "$1" "$2" "$3"
}
get_info() {
total=0
count=0
for bat in /sys/class/power_supply/BAT*; do
[ -f "$bat/capacity" ] || continue
capacity=$(<"$bat/capacity")
status=$(<"$bat/status")
total=$((total + capacity))
count=$((count + 1))
done
[ "$count" -gt 0 ] || exit 0
percentage=$((total / count))
}
last_state=""
while true; do
get_info
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
notify critical "Battery Critically Low" "$percentage% suspending."
$ACTION
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
if [[ "$last_state" != "low" ]]; then
notify normal "Battery Low" "$percentage% remaining."
last_state="low"
fi
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
if [[ "$last_state" != "full" ]]; then
notify normal "Battery Full" "$percentage% unplug charger."
last_state="full"
fi
# This was replaced by caelestia shell's Game Mode
packages.custom-performance = pkgs.writeShellApplication {
name = "custom-performance";
runtimeInputs = with pkgs; [
hyprland
gawk
libnotify
];
text = ''
HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}')
if [ "$HYPRGAMEMODE" = 1 ] ; then
hyprctl --batch "\
keyword animations:enabled 0;\
keyword animation borderangle,0; \
keyword decoration:shadow:enabled 0;\
keyword decoration:blur:enabled 0;\
keyword decoration:fullscreen_opacity 1;\
keyword general:gaps_in 0;\
keyword general:gaps_out 0;\
keyword general:border_size 1;\
keyword decoration:rounding 0"
notify-send -u critical -t 5000 "Performance mode [ON]"
exit
else
last_state=""
notify-send -u critical -t 5000 "Performance mode [OFF]"
hyprctl reload
exit 0
fi
sleep "$INTERVAL"
done
'';
};};
flake.homeModules.cbatticon = { ... }: {
'';
};
# Old script that was used for the battery. Might not work.
packages.custom-olddeprecatedbatterynotify = pkgs.writeShellApplication {
name = "custom-olddeprecatedbatterynotify";
runtimeInputs = with pkgs; [
libnotify # provides notify-send
systemd # provides systemctl
];
text = ''
set -euo pipefail
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
INTERVAL="''${BATTERY_INTERVAL:-30}"
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
notify() {
notify-send -a "Battery" -u "$1" "$2" "$3"
}
get_info() {
total=0
count=0
for bat in /sys/class/power_supply/BAT*; do
[ -f "$bat/capacity" ] || continue
capacity=$(<"$bat/capacity")
status=$(<"$bat/status")
total=$((total + capacity))
count=$((count + 1))
done
[ "$count" -gt 0 ] || exit 0
percentage=$((total / count))
}
last_state=""
while true; do
get_info
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
notify critical "Battery Critically Low" "$percentage% suspending."
$ACTION
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
if [[ "$last_state" != "low" ]]; then
notify normal "Battery Low" "$percentage% remaining."
last_state="low"
fi
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
if [[ "$last_state" != "full" ]]; then
notify normal "Battery Full" "$percentage% unplug charger."
last_state="full"
fi
else
last_state=""
fi
sleep "$INTERVAL"
done
'';
};
};
flake.homeModules.cbatticon = _: {
# don't works. some GTK error. I let it here if someday, someone is interest in this shit.
# ChatGPT half baked a replacement that works on my system.
# see qtbatticon