2009-11-15 13:48:42 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.powerManagement;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
powerManagement = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2012-10-05 04:10:35 +02:00
|
|
|
default = true;
|
2009-11-15 13:48:42 +01:00
|
|
|
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 20:20:50 +02:00
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2010-12-02 21:23:45 +01: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 20:20:50 +02:00
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
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;
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
boot.kernelModules =
|
2013-01-14 08:07:35 +01:00
|
|
|
[ "acpi_cpufreq" "powernow-k8" "cpufreq_performance" "cpufreq_powersave" "cpufreq_ondemand"
|
2012-03-17 18:26:17 +01:00
|
|
|
"cpufreq_conservative"
|
2010-08-10 03:00:09 +02:00
|
|
|
];
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2012-01-13 14:26:52 +01:00
|
|
|
powerManagement.cpuFreqGovernor = mkDefault "ondemand";
|
|
|
|
powerManagement.scsiLinkPolicy = mkDefault "min_power";
|
2012-10-04 23:57:10 +02:00
|
|
|
|
|
|
|
# Service executed before suspending/hibernating.
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services."pre-sleep" =
|
2012-10-04 23:57:10 +02:00
|
|
|
{ description = "Pre-Sleep Actions";
|
|
|
|
wantedBy = [ "sleep.target" ];
|
|
|
|
before = [ "sleep.target" ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
${cfg.powerDownCommands}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Service executed before suspending/hibernating. There doesn't
|
|
|
|
# seem to be a good way to hook in a service to be executed after
|
|
|
|
# both suspend *and* hibernate, so have a separate one for each.
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services."post-suspend" =
|
2012-10-04 23:57:10 +02:00
|
|
|
{ description = "Post-Suspend Actions";
|
|
|
|
wantedBy = [ "suspend.target" ];
|
|
|
|
after = [ "systemd-suspend.service" ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
${cfg.resumeCommands}
|
|
|
|
${cfg.powerUpCommands}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services."post-hibernate" =
|
2012-10-04 23:57:10 +02:00
|
|
|
{ description = "Post-Hibernate Actions";
|
|
|
|
wantedBy = [ "hibernate.target" ];
|
|
|
|
after = [ "systemd-hibernate.service" ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
${cfg.resumeCommands}
|
|
|
|
${cfg.powerUpCommands}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|