nixpkgs-suyu/modules/config/power-management.nix
Eelco Dolstra cf36b3db80 * If power management is enabled, set the governor to ‘ondemand’ by
default.  See
  
    http://www.codon.org.uk/~mjg59/power/good_practices.html
    
  for the reasoning.  (Basically, the ‘performance’ and ‘powersave’
  governors don't actually provide extra performance or power savings
  in most cases.)

  It used to be that desktop environments like KDE were able to set
  the governor through HAL (e.g. KDE could be configured to switch to
  the powersave governor when the user unplugs his laptop).  However,
  this is no longer the case with upower — it is now expected that
  everybody uses the ondemand governor.  See

    http://old.nabble.com/-PATCH--powerdevil-remove-cpufreq.patch-td27815354.html

* Rename ‘cpuFreqGovernor’ to ‘powerManagement.cpuFreqGovernor’.

* Include cpufreq-utils in the system path if a governor is set, since
  we depend on it anyway.

svn path=/nixos/trunk/; revision=30991
2011-12-20 22:44:58 +00:00

98 lines
2.1 KiB
Nix

{ config, pkgs, ... }:
with pkgs.lib;
let
cfg = config.powerManagement;
sleepHook = pkgs.writeScript "sleep-hook.sh"
''
#! ${pkgs.stdenv.shell}
action="$1"
case "$action" in
hibernate|suspend)
${cfg.powerDownCommands}
;;
thaw|resume)
${cfg.resumeCommands}
${cfg.powerUpCommands}
;;
esac
'';
in
{
###### interface
options = {
powerManagement = {
enable = mkOption {
default = false;
description =
''
Whether to enable power management. This includes support
for suspend-to-RAM and powersave features on laptops.
'';
};
resumeCommands = mkOption {
default = "";
description = "Commands executed after the system resumes from suspend-to-RAM.";
};
powerUpCommands = mkOption {
default = "";
example = "${pkgs.hdparm}/sbin/hdparm -B 255 /dev/sda";
description =
''
Commands executed when the machine powers up. That is,
they're executed both when the system first boots and when
it resumes from suspend or hibernation.
'';
};
powerDownCommands = mkOption {
default = "";
example = "${pkgs.hdparm}/sbin/hdparm -B 255 /dev/sda";
description =
''
Commands executed when the machine powers down. That is,
they're executed both when the system shuts down and when
it goes to suspend or hibernation.
'';
};
};
};
###### implementation
config = mkIf cfg.enable {
# Enable the ACPI daemon. Not sure whether this is essential.
services.acpid.enable = true;
environment.systemPackages = [ pkgs.pmutils ];
environment.etc = singleton
{ source = sleepHook;
target = "pm/sleep.d/00sleep-hook";
};
boot.kernelModules =
[ "acpi_cpufreq" "cpufreq_performance" "cpufreq_powersave" "cpufreq_ondemand"
"p4_clockmod"
];
powerManagement.cpuFreqGovernor = "ondemand";
};
}