Commit 20a1040d22ab

Vincent Demeester <vincent@sbr.pm>
2026-03-16 11:10:09
feat(kyushu): add battery charge threshold scripts
Added officemode (70-80%) and roadmode (0-100%) scripts to control battery charge thresholds via sysfs. Defaults to office mode on boot for better long-term battery health. Sudo NOPASSWD rules allow unprivileged toggling.
1 parent 1420a46
Changed files (1)
systems
systems/kyushu/extra.nix
@@ -3,6 +3,18 @@
   lib,
   ...
 }:
+let
+  officemode = pkgs.writeShellScriptBin "officemode" ''
+    echo "80" > /sys/class/power_supply/BAT0/charge_control_end_threshold
+    echo "70" > /sys/class/power_supply/BAT0/charge_control_start_threshold
+    echo "Office mode: charging between 70%–80%"
+  '';
+  roadmode = pkgs.writeShellScriptBin "roadmode" ''
+    echo "100" > /sys/class/power_supply/BAT0/charge_control_end_threshold
+    echo "0" > /sys/class/power_supply/BAT0/charge_control_start_threshold
+    echo "Road mode: charging to 100%"
+  '';
+in
 {
 
   imports = [
@@ -95,10 +107,39 @@
     netConf = "192.168.12.70";
   };
 
+  # Battery charge thresholds: default to office mode on boot
+  systemd.services.battery-charge-threshold = {
+    description = "Set battery charge threshold to office mode (80%)";
+    wantedBy = [ "multi-user.target" ];
+    after = [ "multi-user.target" ];
+    serviceConfig = {
+      Type = "oneshot";
+      ExecStart = "${officemode}/bin/officemode";
+    };
+  };
+
+  security.sudo.extraRules = [
+    {
+      groups = [ "wheel" ];
+      commands = [
+        {
+          command = "${officemode}/bin/officemode";
+          options = [ "NOPASSWD" ];
+        }
+        {
+          command = "${roadmode}/bin/roadmode";
+          options = [ "NOPASSWD" ];
+        }
+      ];
+    }
+  ];
+
   environment.systemPackages = with pkgs; [
     kanata
     nixos-rebuild-ng
     battery-monitor
+    officemode
+    roadmode
     jayrah
     jayrat
     # backup