change(laptop): more batt changes

This commit is contained in:
2026-01-21 00:48:51 +00:00
parent a7c6dc133e
commit f5bc2ef54f

View File

@@ -141,58 +141,38 @@ let
'';
in
{
services.tuned = {
enable = false;
profiles = {
doloro-power-saver = {
main = {
include = "powersave, intel-best_power_efficiency_mode";
};
script = {
script = "\${i:PROFILE_DIR}/script.sh";
};
};
doloro-balanced = {
main = {
include = "balanced";
};
script = {
script = "${battery-limit-script}/bin/set-battery-limit";
};
};
};
};
environment.etc = {
"tuned/recommend.conf" = {
text = tuned-auto-profile-config;
};
"tuned/profiles/doloro-power-saver/script.sh" = {
text = "${one-with-all}";
mode = "0777";
};
};
systemd.services = {
# Tells tuned "hey, re-eval system state and change profiles accordingly"
send-sighup-to-tuned = {
serviceConfig = {
ExecStart = "${pkgs.killall}/bin/killall -1 .tuned-wrapped";
Restart = "always";
RestartSec = "30s";
};
wantedBy = [ "multi-user.target" ];
};
tuned-auto-profile = {
description = "Enable Auto Profile in TuneD";
after = [ "network.target" ]; # Ensure network is up (if needed for TuneD)
wantedBy = [ "multi-user.target" ]; # Start in the default target mode
services.tlp = {
enable = true;
settings = {
# Wireless power saving
WIFI_PWR_ON_BAT = "1";
# Command to run
serviceConfig = {
ExecStart = "${pkgs.tuned}/bin/tuned-adm auto_profile";
Restart = "on-failure";
RestartSec = 5; # Wait 5 seconds before retrying if it fails
Environment = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; # Ensure PATH is correct
};
# USB autosuspend
USB_AUTOSUSPEND = "1";
# SATA drive power management
SATA_LINKPWR_ON_BAT = "min_power";
# PCI Express Active-State Power Management (ASPM)
PCIE_ASPM_ON_BAT = "powersupersave";
# Runtime Power Management for PCI(e) buses/devices
RUNTIME_PM_ON_BAT = "auto";
# Disable Bluetooth on battery
# DEVICES_TO_DISABLE_ON_BAT = "bluetooth";
# Restore brightness on battery
RESTORE_BRIGHTNESS_ON_BAT = "1";
PCIE_ASPM_ON_AC = "balanced";
DEVICES_TO_DISABLE_ON_BAT_NOT_IN_USE = "bluetooth wifi wwan";
INTEL_GPU_MAX_FREQ_ON_AC = 0;
INTEL_GPU_MAX_FREQ_ON_BAT = 800;
PLATFORM_PROFILE_ON_AC = "balanced";
PLATFORM_PROFILE_ON_BAT = "quiet";
START_CHARGE_THRESH_BAT0 = 40; # 40 and below it starts to charge
STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging
};
};
services.thermald.enable = true;
@@ -200,6 +180,27 @@ in
enable = true;
};
services.auto-cpufreq.enable = true;
systemd.targets = {
"ac" = {
description = "On AC power";
unitConfig = {
StopWhenUnneeded = "yes";
};
};
"battery" = {
description = "On battery power";
unitConfig = {
StopWhenUnneeded = "yes";
};
};
};
services.udev.extraRules = ''
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/run/current-system/systemd/bin/systemctl start battery.target"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/run/current-system/systemd/bin/systemctl start ac.target"
'';
services.auto-cpufreq.settings = {
battery = {
governor = "powersave";
@@ -226,6 +227,20 @@ in
SuspendEstimationSec=120
'';
systemd.services.gpu-limit-on-batt = {
enable = true;
description = "Using rfkill; disable all rf devices before sleeping.";
before = [ "battery.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.intel-gpu-tools}/bin/intel_gpu_frequency -e";
RemainAfterExit = true;
};
wantedBy = [ "battery.target" ];
partOf = [ "battery.target" ];
};
systemd.services.rfkill-sleep-wake = {
enable = true;
description = "Using rfkill; disable all rf devices before sleeping.";