1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-12-27 12:09:45 +01:00

asus/battery.nix: fix chargeUpto after suspend/resume, make script optional

This commit is contained in:
Luna Nova 2022-02-19 16:01:05 -08:00
parent 10eab1c4cd
commit acded13f27
No known key found for this signature in database

View file

@ -3,19 +3,35 @@ let
p = pkgs.writeScriptBin "charge-upto" ''
echo ''${0:-100} > /sys/class/power_supply/BAT0/charge_control_end_threshold
'';
cfg = config.hardware.asus;
cfg = config.hardware.asus.battery;
in
{
options.hardware.asus.battery.chargeUpto = lib.mkOption {
description = "Maximum level of charge for your battery, as a percentage.";
default = 100;
type = lib.types.int;
options.hardware.asus.battery = {
chargeUpto = lib.mkOption {
description = "Maximum level of charge for your battery, as a percentage.";
default = 100;
type = lib.types.int;
};
addChargeUptoScript = 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 = {
environment.systemPackages = [ p ];
systemd.tmpfiles.rules = [
"w /sys/class/power_supply/BAT0/charge_control_end_threshold - - - - ${toString cfg.battery.chargeUpto}"
];
environment.systemPackages = lib.mkIf cfg.addChargeUptoScript [ p ];
systemd.services.battery-charge-threshold = {
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 = "/bin/sh -c 'echo ${toString cfg.chargeUpto} > /sys/class/power_supply/BAT0/charge_control_end_threshold'";
};
};
};
}