feat: nb add battery max charge option and quick change for it
This commit is contained in:
parent
8f2a1e1357
commit
92a216c920
5 changed files with 136 additions and 73 deletions
|
|
@ -5,7 +5,8 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz";
|
||||
in {
|
||||
in
|
||||
{
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
nixpkgs.config.allowBroken = true;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ in {
|
|||
./modules/ollama.nix
|
||||
./modules/qdrant.nix
|
||||
./modules/battery-brightness.nix
|
||||
./modules/charge-control.nix
|
||||
./modules/suspend-fixes.nix
|
||||
|
||||
./cachix.nix
|
||||
|
|
|
|||
91
hosts/nb/modules/charge-control.nix
Normal file
91
hosts/nb/modules/charge-control.nix
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
{ pkgs, ... }:
|
||||
let
|
||||
charge-limit-apply = pkgs.writeShellScriptBin "charge-limit-apply" ''
|
||||
if [ "$1" != "80" ] && [ "$1" != "100" ]; then
|
||||
echo "Usage: charge-limit-apply <80|100>" >&2
|
||||
exit 1
|
||||
fi
|
||||
${pkgs.fw-ectool}/bin/ectool fwchargelimit "$1"
|
||||
echo "$1" > /run/fw-charge-limit
|
||||
chmod 644 /run/fw-charge-limit
|
||||
'';
|
||||
|
||||
charge-limit-menu = pkgs.writeShellScriptBin "charge-limit-menu" ''
|
||||
choice=$(printf "80%%\n100%%" | ${pkgs.wofi}/bin/wofi --dmenu --prompt "Charge limit")
|
||||
case "$choice" in
|
||||
"80%") /run/wrappers/bin/sudo ${charge-limit-apply}/bin/charge-limit-apply 80 ;;
|
||||
"100%") /run/wrappers/bin/sudo ${charge-limit-apply}/bin/charge-limit-apply 100 ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
waybar-battery = pkgs.writeShellScriptBin "waybar-battery" ''
|
||||
charging_icons=("" "" "" "" "" "" "" "" "" "")
|
||||
default_icons=("" "" "" "" "" "" "" "" "" "")
|
||||
|
||||
bat_path=$(echo /sys/class/power_supply/BAT*)
|
||||
capacity=$(cat "$bat_path/capacity" 2>/dev/null || echo 0)
|
||||
status=$(cat "$bat_path/status" 2>/dev/null || echo "Unknown")
|
||||
limit=$(cat /run/fw-charge-limit 2>/dev/null || echo 80)
|
||||
|
||||
# Select icon based on capacity (10 icons, index 0-9)
|
||||
idx=$(( capacity / 11 ))
|
||||
if [ "$idx" -gt 9 ]; then idx=9; fi
|
||||
|
||||
if [ "$status" = "Charging" ]; then
|
||||
icon="''${charging_icons[$idx]}"
|
||||
else
|
||||
icon="''${default_icons[$idx]}"
|
||||
fi
|
||||
|
||||
# Determine CSS class
|
||||
class=""
|
||||
if [ "$capacity" -le 15 ]; then
|
||||
class="critical"
|
||||
elif [ "$capacity" -le 30 ]; then
|
||||
class="warning"
|
||||
elif [ "$capacity" -ge 95 ]; then
|
||||
class="good"
|
||||
fi
|
||||
|
||||
tooltip="Battery: ''${capacity}% [''${status}]\nCharge limit: ''${limit}%"
|
||||
|
||||
${pkgs.jq}/bin/jq -cn \
|
||||
--arg text "$icon ''${capacity}% (''${limit}%)" \
|
||||
--arg tooltip "$tooltip" \
|
||||
--arg class "$class" \
|
||||
'{text: $text, tooltip: $tooltip, class: $class}'
|
||||
'';
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [
|
||||
pkgs.fw-ectool
|
||||
charge-limit-apply
|
||||
charge-limit-menu
|
||||
waybar-battery
|
||||
];
|
||||
|
||||
security.sudo.extraRules = [
|
||||
{
|
||||
users = [ "dominik" ];
|
||||
commands = [
|
||||
{
|
||||
command = "${charge-limit-apply}/bin/charge-limit-apply";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
systemd.services.fw-charge-limit = {
|
||||
description = "Set Framework charge limit on boot";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${pkgs.writeShellScript "fw-charge-limit-init" ''
|
||||
${pkgs.fw-ectool}/bin/ectool fwchargelimit 80
|
||||
echo 80 > /run/fw-charge-limit
|
||||
chmod 644 /run/fw-charge-limit
|
||||
''}";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -15,7 +15,8 @@ let
|
|||
};
|
||||
variants = [ "qt5" ];
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
../sway/sway.nix
|
||||
../sway/launcher-cleanup.nix
|
||||
|
|
@ -173,9 +174,6 @@ in {
|
|||
DISK_IDLE_SECS_ON_AC = 0;
|
||||
DISK_IDLE_SECS_ON_BAT = 2;
|
||||
|
||||
# Battery charge thresholds (Framework 13 recommendation)
|
||||
START_CHARGE_THRESH_BAT0 = 60;
|
||||
STOP_CHARGE_THRESH_BAT0 = 80;
|
||||
};
|
||||
|
||||
boot.plymouth = {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
"cpu",
|
||||
"custom/left-arrow-light",
|
||||
"custom/left-arrow-dark",
|
||||
"battery",
|
||||
"custom/battery",
|
||||
"custom/left-arrow-light",
|
||||
"custom/left-arrow-dark",
|
||||
"disk",
|
||||
|
|
@ -109,39 +109,11 @@
|
|||
"interval": 5,
|
||||
"format": " {usage:2}%"
|
||||
},
|
||||
"battery": {
|
||||
"states": {
|
||||
"good": 95,
|
||||
"warning": 30,
|
||||
"critical": 15
|
||||
},
|
||||
"format": "{icon} {capacity}%",
|
||||
"format-icons": {
|
||||
"charging": [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"default": [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
]
|
||||
},
|
||||
"custom/battery": {
|
||||
"exec": "waybar-battery",
|
||||
"return-type": "json",
|
||||
"interval": 10,
|
||||
"on-click": "charge-limit-menu"
|
||||
},
|
||||
"disk": {
|
||||
"interval": 5,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ window#waybar {
|
|||
#pulseaudio,
|
||||
#memory,
|
||||
#cpu,
|
||||
#battery,
|
||||
#custom-battery,
|
||||
#disk,
|
||||
#tray {
|
||||
background: #252525;
|
||||
|
|
@ -62,7 +62,7 @@ window#waybar {
|
|||
#cpu {
|
||||
color: #bd93f9;
|
||||
}
|
||||
#battery {
|
||||
#custom-battery {
|
||||
color: #f1fa8c;
|
||||
}
|
||||
#disk {
|
||||
|
|
@ -77,7 +77,7 @@ window#waybar {
|
|||
#pulseaudio,
|
||||
#memory,
|
||||
#cpu,
|
||||
#battery,
|
||||
#custom-battery,
|
||||
#disk {
|
||||
padding: 0 10px;
|
||||
padding-left: 5px;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue