battery charge limit

This commit is contained in:
mjallen18
2025-11-20 14:58:21 -06:00
parent 76f0e8f176
commit 0eed44ef6d
5 changed files with 50 additions and 157 deletions

View File

@@ -0,0 +1,43 @@
# echo 81 | sudo tee /sys/class/power_supply/macsmc-battery/charge_control_end_threshold
{
config,
pkgs,
lib,
namespace,
...
}:
with lib;
let
inherit (lib.${namespace}) mkOpt;
cfg = config.${namespace}.hardware.battery;
in
{
options.${namespace}.hardware.battery = {
enable = mkEnableOption "battery charge limit service";
chargeLimit = mkOpt types.int 81 "Charge limit for the battery, ex: 81 = 80% charge limit";
battery = mkOpt types.str "" "Path to the battery charge limit file";
};
config = mkIf cfg.enable {
systemd = {
services = {
set-charge-limit = {
enable = true;
wantedBy = [ "multi-user.target" ];
path = [
pkgs.uutils-coreutils-noprefix
];
script = ''
${pkgs.uutils-coreutils-noprefix}/bin/echo ${toString cfg.chargeLimit} | tee ${cfg.battery}
'';
serviceConfig = {
Type = "oneshot";
TimeoutSec = "5s";
};
};
};
};
};
}

View File

@@ -78,7 +78,7 @@ in
environment = {
systemPackages = with pkgs; [
attic-client
uutils-coreutils
uutils-coreutils-noprefix
uutils-diffutils
uutils-findutils
coreutils