#
# Laptop power-saving configuration.
#
# vim: et:ts=2:sw=2:
#
{ config, pkgs, ... }:
{
  # Keep our thermals nice and happy.
  services.thermald.enable = !pkgs.stdenv.isAarch64;

  # Set up a power saving policy manager.
  services.tlp = {
    enable = true;
    settings = {

      # Keep our battery healthy, when possible.
      # Comment this out before trips or etc, if needed.
      START_CHARGE_THRESH_BAT0 = 75;
      STOP_CHARGE_THRESH_BAT0 = 80;

      #
      # Battery optimizations, so we don't burn through power as hard.
      #

      # Don't run bluetooth or cellular unless we turn them on explicitly.
      DEVICES_TO_DISABLE_ON_STARTUP = "bluetooth";

      # Conserve power harder when on battery, and push performance harder on AC.
      CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
      PLATFORM_PROFILE_ON_BAT = "low-power";
      CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
      PLATFORM_PROFILE_ON_AC = "performance";

      # Disable turbo boost on battery.
      CPU_BOOST_ON_BAT = 0;
      CPU_HWP_DYN_BOOST_ON_BAT = 0;

    };
  };
}
