2009-11-15 13:48:42 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.powerManagement;
|
|
|
|
|
|
|
|
sleepHook = pkgs.writeScript "sleep-hook.sh"
|
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell}
|
|
|
|
action="$1"
|
|
|
|
if [ "$action" = "resume" ]; then
|
2009-11-15 13:56:40 +01:00
|
|
|
${cfg.resumeCommands}
|
|
|
|
${cfg.powerUpCommands}
|
2009-11-15 13:48:42 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
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.";
|
|
|
|
};
|
|
|
|
|
2009-11-15 13:56:40 +01: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-11-15 13:48:42 +01: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";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|