Commit 50d13f5fe684

Vincent Demeester <vincent@sbr.pm>
2022-09-19 15:57:48
systems/aomi: create 2 scripts for charge threshold
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 1929229
Changed files (1)
systems
systems/hosts/aomi.nix
@@ -16,6 +16,16 @@ let
   endpointPort = if secretCondition then (import secretPath).wg.listenPort else 0;
   endpointPublicKey = strings.optionalString secretCondition (import secretPath).wireguard.kerkouane.publicKey;
   metadata = importTOML ../../ops/hosts.toml;
+
+  # Scripts
+  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
+  '';
+  roadmode = pkgs.writeShellScriptBin "roadmode" ''
+    echo "100" > /sys/class/power_supply/BAT0/charge_control_end_threshold
+    echo "99" > /sys/class/power_supply/BAT0/charge_control_start_threshold
+  '';
 in
 {
   imports = [
@@ -53,6 +63,18 @@ in
     hostName = hostname;
   };
 
+  environment.systemPackages = [ officemode roadmode ];
+  security.sudo.extraRules = [
+    # Allow execution of roadmode and officemode by users in wheel, without a password
+    {
+      groups = [ "wheel" ];
+      commands = [
+        { command = "${officemode}"; options = [ "NOPASSWD" ]; }
+        { command = "${roadmode}"; options = [ "NOPASSWD" ]; }
+      ];
+    }
+  ];
+
   # extract this from desktop
   networking.networkmanager = {
     enable = true;