at 15.09-beta 2.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7cfg = config.services.tlp; 8 9tlp = pkgs.tlp.override { kmod = config.system.sbin.modprobe; }; 10 11confFile = pkgs.writeText "tlp" (builtins.readFile "${tlp}/etc/default/tlp" + cfg.extraConfig); 12 13in 14 15{ 16 17 ###### interface 18 19 options = { 20 21 services.tlp = { 22 23 enable = mkOption { 24 type = types.bool; 25 default = false; 26 description = "Whether to enable the TLP daemon."; 27 }; 28 29 extraConfig = mkOption { 30 type = types.str; 31 default = ""; 32 description = "Additional configuration variables for TLP"; 33 }; 34 35 }; 36 37 }; 38 39 40 ###### implementation 41 42 config = mkIf cfg.enable { 43 44 systemd.services = { 45 tlp = { 46 description = "TLP system startup/shutdown"; 47 48 after = [ "multi-user.target" ]; 49 wantedBy = [ "multi-user.target" ]; 50 before = [ "shutdown.target" ]; 51 52 serviceConfig = { 53 Type = "oneshot"; 54 RemainAfterExit = true; 55 ExecStart = "${tlp}/bin/tlp init start"; 56 ExecStop = "${tlp}/bin/tlp init stop"; 57 }; 58 }; 59 60 tlp-sleep = { 61 description = "TLP suspend/resume"; 62 63 wantedBy = [ "sleep.target" ]; 64 before = [ "sleep.target" ]; 65 66 unitConfig = { 67 StopWhenUnneeded = true; 68 }; 69 70 serviceConfig = { 71 Type = "oneshot"; 72 RemainAfterExit = true; 73 ExecStart = "${tlp}/bin/tlp suspend"; 74 ExecStop = "${tlp}/bin/tlp resume"; 75 }; 76 }; 77 }; 78 79 services.udev.packages = [ tlp ]; 80 81 environment.etc = [{ source = confFile; 82 target = "default/tlp"; 83 } 84 ] ++ optional tlp.enableRDW { 85 source = "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm"; 86 target = "NetworkManager/dispatcher.d/99tlp-rdw-nm"; 87 }; 88 89 environment.systemPackages = [ tlp ]; 90 91 }; 92 93}