nixos/tlp: add service
This commit is contained in:
parent
0c9c74de19
commit
b7b3a0972d
@ -149,6 +149,7 @@
|
|||||||
./services/hardware/pommed.nix
|
./services/hardware/pommed.nix
|
||||||
./services/hardware/sane.nix
|
./services/hardware/sane.nix
|
||||||
./services/hardware/tcsd.nix
|
./services/hardware/tcsd.nix
|
||||||
|
./services/hardware/tlp.nix
|
||||||
./services/hardware/thinkfan.nix
|
./services/hardware/thinkfan.nix
|
||||||
./services/hardware/udev.nix
|
./services/hardware/udev.nix
|
||||||
./services/hardware/udisks2.nix
|
./services/hardware/udisks2.nix
|
||||||
|
93
nixos/modules/services/hardware/tlp.nix
Normal file
93
nixos/modules/services/hardware/tlp.nix
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.services.tlp;
|
||||||
|
|
||||||
|
tlp = pkgs.tlp.override { kmod = config.system.sbin.modprobe; };
|
||||||
|
|
||||||
|
confFile = pkgs.writeText "tlp" (builtins.readFile "${tlp}/etc/default/tlp" + cfg.extraConfig);
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
systemd.services = {
|
||||||
|
tlp = {
|
||||||
|
description = "TLP system startup/shutdown";
|
||||||
|
|
||||||
|
after = [ "multi-user.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
before = [ "shutdown.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
ExecStart = "${tlp}/bin/tlp init start";
|
||||||
|
ExecStop = "${tlp}/bin/tlp init stop";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.udev.packages = [ tlp ];
|
||||||
|
|
||||||
|
environment.etc = [{ source = confFile;
|
||||||
|
target = "default/tlp";
|
||||||
|
}
|
||||||
|
] ++ optional tlp.enableRDW {
|
||||||
|
source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm";
|
||||||
|
target = "NetworkManager/dispatcher.d/99tlp-rdw-nm";
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = [ tlp ];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user