nixpkgs/nixos/modules/services/hardware/tlp.nix
Shea Levy 9adad8612b Revert "Merge branch 'modprobe-fix' of git://github.com/abbradar/nixpkgs"
Was meant to go into staging, sorry

This reverts commit 57b2d1e9b0, reversing
changes made to 760b2b9048.
2016-08-15 19:05:52 -04:00

116 lines
2.5 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.tlp;
enableRDW = config.networking.networkmanager.enable;
tlp = pkgs.tlp.override {
inherit enableRDW;
};
# XXX: We can't use writeTextFile + readFile here because it triggers
# TLP build to get the .drv (even on --dry-run).
confFile = pkgs.runCommand "tlp"
{ config = cfg.extraConfig;
passAsFile = [ "config" ];
}
''
cat ${tlp}/etc/default/tlp > $out
cat $configPath >> $out
'';
in
{
###### interface
options = {
services.tlp = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the TLP daemon.";
};
extraConfig = mkOption {
type = types.str;
default = "";
description = "Additional configuration variables for TLP";
};
};
};
###### implementation
config = mkIf cfg.enable {
powerManagement.scsiLinkPolicy = null;
powerManagement.cpuFreqGovernor = null;
systemd.services = {
tlp = {
description = "TLP system startup/shutdown";
after = [ "multi-user.target" ];
wantedBy = [ "multi-user.target" ];
before = [ "shutdown.target" ];
restartTriggers = [ confFile ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${tlp}/bin/tlp init start";
ExecStop = "${tlp}/bin/tlp init stop";
};
environment.MODULE_DIR="/run/current-system/kernel-modules/lib/modules/";
};
tlp-sleep = {
description = "TLP suspend/resume";
wantedBy = [ "sleep.target" ];
before = [ "sleep.target" ];
unitConfig = {
StopWhenUnneeded = true;
};
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${tlp}/bin/tlp suspend";
ExecStop = "${tlp}/bin/tlp resume";
};
environment.MODULE_DIR="/run/current-system/kernel-modules/lib/modules/";
};
};
services.udev.packages = [ tlp ];
environment.etc = [{ source = confFile;
target = "default/tlp";
}
] ++ optional enableRDW {
source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm";
target = "NetworkManager/dispatcher.d/99tlp-rdw-nm";
};
environment.systemPackages = [ tlp ];
boot.kernelModules = [ "msr" ];
};
}