Merge pull request #380 from LunNova/asus-battery-fix
asus/battery.nix: fix chargeUpto after suspend/resume, make script optional
This commit is contained in:
commit
c730530902
|
@ -3,19 +3,35 @@ let
|
||||||
p = pkgs.writeScriptBin "charge-upto" ''
|
p = pkgs.writeScriptBin "charge-upto" ''
|
||||||
echo ''${0:-100} > /sys/class/power_supply/BAT0/charge_control_end_threshold
|
echo ''${0:-100} > /sys/class/power_supply/BAT0/charge_control_end_threshold
|
||||||
'';
|
'';
|
||||||
cfg = config.hardware.asus;
|
cfg = config.hardware.asus.battery;
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
options.hardware.asus.battery.chargeUpto = lib.mkOption {
|
options.hardware.asus.battery = {
|
||||||
description = "Maximum level of charge for your battery, as a percentage.";
|
chargeUpto = lib.mkOption {
|
||||||
default = 100;
|
description = "Maximum level of charge for your battery, as a percentage.";
|
||||||
type = lib.types.int;
|
default = 100;
|
||||||
|
type = lib.types.int;
|
||||||
|
};
|
||||||
|
enableChargeUptoScript = lib.mkOption {
|
||||||
|
description = "Whether to add charge-upto to environment.systemPackages. `charge-upto 75` temporarily sets the charge limit to 75%.";
|
||||||
|
default = true;
|
||||||
|
type = lib.types.bool;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
environment.systemPackages = [ p ];
|
environment.systemPackages = lib.mkIf cfg.enableChargeUptoScript [ p ];
|
||||||
systemd.tmpfiles.rules = [
|
systemd.services.battery-charge-threshold = {
|
||||||
"w /sys/class/power_supply/BAT0/charge_control_end_threshold - - - - ${toString cfg.battery.chargeUpto}"
|
wantedBy = [ "local-fs.target" "suspend.target" ];
|
||||||
];
|
after = [ "local-fs.target" "suspend.target" ];
|
||||||
|
description = "Set the battery charge threshold to ${toString cfg.chargeUpto}%";
|
||||||
|
startLimitBurst = 5;
|
||||||
|
startLimitIntervalSec = 1;
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
Restart = "on-failure";
|
||||||
|
ExecStart = "${pkgs.runtimeShell} -c 'echo ${toString cfg.chargeUpto} > /sys/class/power_supply/BAT0/charge_control_end_threshold'";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue