Files
nixos/modules/laptop/battery.nix
2025-09-18 12:39:26 +02:00

43 lines
849 B
Nix

{ config, lib, ... }:
let
inherit (lib) mkOption types;
singleBat = {
START_CHARGE_THRESH_BAT0 = 65;
STOP_CHARGE_THRESH_BAT0 = 85;
};
doubleBat = singleBat // {
START_CHARGE_THRESH_BAT1 = 65;
STOP_CHARGE_THRESH_BAT1 = 85;
};
in {
options.batMode = mkOption {
type = types.enum [ "single" "double" ];
default = "single";
};
config = {
powerManagement.powertop.enable = true;
services.upower = {
enable = true;
# In accordance with waybar battery colors
percentageLow = 30;
percentageCritical = 20;
percentageAction = 15;
criticalPowerAction = "PowerOff"; # This can destroy work
usePercentageForPolicy = true;
};
services.tlp = {
enable = true;
settings = if config.batMode == "single" then singleBat else doubleBat;
};
};
}