#
# Laptop power-saving configuration.
#
# vim: et:ts=2:sw=2:
#
{ lib, pkgs, ... }:
let
  powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl";
in
{
  # Set up a power saving policy manager.
  services.power-profiles-daemon.enable = lib.mkForce true;

  # Profile its CLI.
  environment.systemPackages = [ pkgs.power-profiles-daemon ];

  # Automatically switch power profile on AC plug/unplug.
  services.udev.extraRules = ''
    SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="${powerprofilesctl} set performance"
    SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="${powerprofilesctl} set power-saver"
  '';
}
