fix(power): coalesce charge-limit reapply events
All checks were successful
Check / eval (push) Successful in 3m16s
All checks were successful
Check / eval (push) Successful in 3m16s
USB-C power event bursts could repeatedly restart and SIGTERM the settling oneshot until systemd reached its start limit. Let successful runs return inactive and use coalescing start jobs for immediate and delayed reapplication. Verified: V0 nix flake check --no-build, module parse, and git diff --check; V2 focused battery-charge-limit KVM test with a 12-event active-run burst. V3 hardware item #101 remains queued.
This commit is contained in:
@@ -66,7 +66,6 @@ in
|
||||
path = [ pkgs.jq pkgs.coreutils ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
set -euo pipefail
|
||||
@@ -153,10 +152,14 @@ in
|
||||
|
||||
# Writable threshold for the logged-in user (menu live apply) + AC
|
||||
# re-apply of the oneshot. Laptop only; no-op when the attr is absent.
|
||||
# Immediate + delayed restart: Dell/Latitude firmware often stomps the
|
||||
# Immediate + delayed start: Dell/Latitude firmware often stomps the
|
||||
# threshold to 100 right after unplug; a single immediate oneshot
|
||||
# loses the race (hardware: unplug→100, plug→80). systemd-run hands
|
||||
# the delayed restart off so udev's short RUN budget is not held.
|
||||
# the delayed start off so udev's short RUN budget is not held. Keep the
|
||||
# oneshot inactive after success and use `start`, not `restart`: a USB-C
|
||||
# dock can emit a burst of Mains change events, and restart would SIGTERM
|
||||
# the in-flight one-second settling pass until systemd hits its start
|
||||
# limit. Concurrent starts instead coalesce safely.
|
||||
services.udev.extraRules = lib.mkIf cfg.laptop (
|
||||
let
|
||||
systemctl = "${config.systemd.package}/bin/systemctl";
|
||||
@@ -166,8 +169,8 @@ in
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Battery", TEST=="charge_types", GROUP="users", MODE="0664"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Battery", TEST=="charge_type", GROUP="users", MODE="0664"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Battery", TEST=="charge_control_start_threshold", GROUP="users", MODE="0664"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="${systemctl} --no-block restart nomarchy-battery-charge-limit.service"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="${systemdRun} --no-block --collect --on-active=2s --timer-property=AccuracySec=200ms ${systemctl} --no-block restart nomarchy-battery-charge-limit.service"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="${systemctl} --no-block start nomarchy-battery-charge-limit.service"
|
||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="${systemdRun} --no-block --collect --on-active=2s --timer-property=AccuracySec=200ms ${systemctl} --no-block start nomarchy-battery-charge-limit.service"
|
||||
''
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user