2009-11-15 15:48:42 +03:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.powerManagement;
|
|
|
|
|
|
|
|
sleepHook = pkgs.writeScript "sleep-hook.sh"
|
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell}
|
|
|
|
action="$1"
|
2010-12-02 23:23:45 +03:00
|
|
|
case "$action" in
|
|
|
|
hibernate|suspend)
|
|
|
|
${cfg.powerDownCommands}
|
|
|
|
;;
|
|
|
|
thaw|resume)
|
|
|
|
${cfg.resumeCommands}
|
|
|
|
${cfg.powerUpCommands}
|
|
|
|
;;
|
2010-12-08 22:46:52 +03:00
|
|
|
esac
|
2009-11-15 15:48:42 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
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.";
|
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:56:40 +03:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2010-12-02 23:23:45 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
|
|
|
|
###### 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";
|
|
|
|
};
|
2010-07-12 21:50:02 +04:00
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
boot.kernelModules =
|
|
|
|
[ "acpi_cpufreq" "cpufreq_performance" "cpufreq_powersave" "cpufreq_ondemand"
|
2012-01-14 02:25:16 +04:00
|
|
|
"p4_clockmod" "cpufreq_conservative"
|
2010-08-10 05:00:09 +04:00
|
|
|
];
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2012-01-13 17:26:52 +04:00
|
|
|
powerManagement.cpuFreqGovernor = mkDefault "ondemand";
|
|
|
|
powerManagement.scsiLinkPolicy = mkDefault "min_power";
|
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|