2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-11-15 15:48:42 +03:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2009-11-15 15:48:42 +03:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.powerManagement;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
powerManagement = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.bool;
|
2012-10-05 06:10:35 +04:00
|
|
|
default = true;
|
2009-11-15 15:48:42 +03:00
|
|
|
description =
|
|
|
|
''
|
|
|
|
Whether to enable power management. This includes support
|
|
|
|
for suspend-to-RAM and powersave features on laptops.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
resumeCommands = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.lines;
|
2009-11-15 15:48:42 +03:00
|
|
|
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 {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.lines;
|
2009-11-15 15:56:40 +03:00
|
|
|
default = "";
|
2014-08-28 01:41:15 +04:00
|
|
|
example = literalExample ''
|
|
|
|
"''${pkgs.hdparm}/sbin/hdparm -B 255 /dev/sda"
|
|
|
|
'';
|
2009-11-15 15:56:40 +03:00
|
|
|
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 {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.lines;
|
2010-12-02 23:23:45 +03:00
|
|
|
default = "";
|
2014-08-28 01:41:15 +04:00
|
|
|
example = literalExample ''
|
|
|
|
"''${pkgs.hdparm}/sbin/hdparm -B 255 /dev/sda"
|
|
|
|
'';
|
2010-12-02 23:23:45 +03:00
|
|
|
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 {
|
|
|
|
|
2014-03-18 03:07:46 +04:00
|
|
|
# FIXME: Implement powersave governor for sandy bridge or later Intel CPUs
|
2012-01-13 17:26:52 +04:00
|
|
|
powerManagement.cpuFreqGovernor = mkDefault "ondemand";
|
|
|
|
powerManagement.scsiLinkPolicy = mkDefault "min_power";
|
2012-10-05 01:57:10 +04:00
|
|
|
|
2013-08-24 19:47:06 +04:00
|
|
|
systemd.targets.post-resume = {
|
2013-08-27 10:03:49 +04:00
|
|
|
description = "Post-Resume Actions";
|
2013-08-24 19:47:06 +04:00
|
|
|
requires = [ "post-resume.service" ];
|
|
|
|
after = [ "post-resume.service" ];
|
|
|
|
wantedBy = [ "sleep.target" ];
|
|
|
|
unitConfig.StopWhenUnneeded = true;
|
|
|
|
};
|
|
|
|
|
2012-10-05 01:57:10 +04:00
|
|
|
# Service executed before suspending/hibernating.
|
2013-01-16 15:33:18 +04:00
|
|
|
systemd.services."pre-sleep" =
|
2012-10-05 01:57:10 +04:00
|
|
|
{ description = "Pre-Sleep Actions";
|
|
|
|
wantedBy = [ "sleep.target" ];
|
|
|
|
before = [ "sleep.target" ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
${cfg.powerDownCommands}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
2013-08-24 19:47:06 +04:00
|
|
|
systemd.services."post-resume" =
|
|
|
|
{ description = "Post-Resume Actions";
|
|
|
|
after = [ "suspend.target" "hibernate.target" "hybrid-sleep.target" ];
|
2012-10-05 01:57:10 +04:00
|
|
|
script =
|
|
|
|
''
|
2015-10-06 19:47:47 +03:00
|
|
|
${config.systemd.package}/bin/systemctl try-restart post-resume.target
|
2012-10-05 01:57:10 +04:00
|
|
|
${cfg.resumeCommands}
|
|
|
|
${cfg.powerUpCommands}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
|
2009-11-15 15:48:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|