···1{ config, lib, pkgs, ... }:
02with lib;
03let
4+ cfg = config.services.tlp;
5+ enableRDW = config.networking.networkmanager.enable;
6+ tlp = pkgs.tlp.override { inherit enableRDW; };
7+ # TODO: Use this for having proper parameters in the future
8+ mkTlpConfig = tlpConfig: generators.toKeyValue {
9+ mkKeyValue = generators.mkKeyValueDefault {
10+ mkValueString = val:
11+ if isInt val then toString val
12+ else if isString val then val
13+ else if true == val then "1"
14+ else if false == val then "0"
15+ else if isList val then "\"" + (concatStringsSep " " val) + "\""
16+ else err "invalid value provided to mkTlpConfig:" (toString val);
17+ } "=";
18+ } tlpConfig;
00000019in
020{
021 ###### interface
022 options = {
023 services.tlp = {
024 enable = mkOption {
25 type = types.bool;
26 default = false;
···32 default = "";
33 description = "Additional configuration variables for TLP";
34 };
035 };
036 };
37038 ###### implementation
039 config = mkIf cfg.enable {
40+ boot.kernelModules = [ "msr" ];
4142+ environment.etc = {
43+ "tlp.conf".text = cfg.extraConfig;
44+ } // optionalAttrs enableRDW {
45+ "NetworkManager/dispatcher.d/99tlp-rdw-nm".source =
46+ "${tlp}/etc/NetworkManager/dispatcher.d/99tlp-rdw-nm";
47+ };
4849+ environment.systemPackages = [ tlp ];
5051+ # FIXME: When the config is parametrized we need to move these into a
52+ # conditional on the relevant options being enabled.
53+ powerManagement = {
54+ scsiLinkPolicy = null;
55+ cpuFreqGovernor = null;
56+ cpufreq.max = null;
57+ cpufreq.min = null;
58+ };
5960+ services.udev.packages = [ tlp ];
06162+ systemd = {
63+ packages = [ tlp ];
64+ # XXX: These must always be disabled/masked according to [1].
65+ #
66+ # [1]: https://github.com/linrunner/TLP/blob/a9ada09e0821f275ce5f93dc80a4d81a7ff62ae4/tlp-stat.in#L319
67+ sockets.systemd-rfkill.enable = false;
68+ services.systemd-rfkill.enable = false;
6970+ services.tlp = {
71+ # XXX: The service should reload whenever the configuration changes,
72+ # otherwise newly set power options remain inactive until reboot (or
73+ # manual unit restart.)
74+ restartTriggers = [ config.environment.etc."tlp.conf".source ];
75+ # XXX: When using systemd.packages (which we do above) the [Install]
76+ # section of systemd units does not work (citation needed) so we manually
77+ # enforce it here.
78+ wantedBy = [ "multi-user.target" ];
79 };
8081+ services.tlp-sleep = {
82+ # XXX: When using systemd.packages (which we do above) the [Install]
83+ # section of systemd units does not work (citation needed) so we manually
84+ # enforce it here.
85+ before = [ "sleep.target" ];
86 wantedBy = [ "sleep.target" ];
87+ # XXX: `tlp suspend` requires /var/lib/tlp to exist in order to save
88+ # some stuff in there. There is no way, that I know of, to do this in
89+ # the package itself, so we do it here instead making sure the unit
90+ # won't fail due to the save dir not existing.
91+ serviceConfig.StateDirectory = "tlp";
000000092 };
93 };
000000000000000094 };
095}
···1+commit c44347b3b813e209fff537b4d46d23430727a5e2
2+Author: Bernardo Meurer <meurerbernardo@gmail.com>
3+Date: Tue Feb 25 21:27:39 2020 -0800
4+5+ makefile: correctly sed paths
6+7+ The default Makefile for tlp makes a mess with catenating `DESTDIR` to
8+ everything, but then not actualy using the catenated (_ prefixed)
9+ variables to sed it's `.in` files.
10+11+ This patch makes sure that it correctly sets the paths, taking `DESTDIR`
12+ in account where it makes sense (e.g. /bin where we want $out/bin) but
13+ not where it doesn't (/etc/tlp.conf should be just that).
14+15+ The reason DESTDIR is used at all, as opposed to the more appropriate
16+ PREFIX, is covered in the nix formula, and is (also) due to the Makefile
17+ being a bit "different."
18+19+diff --git a/Makefile b/Makefile
20+index b5af74e..95122df 100644
21+--- a/Makefile
22++++ b/Makefile
23+@@ -47,17 +47,17 @@ _TPACPIBAT = $(DESTDIR)$(TPACPIBAT)
24+25+ SED = sed \
26+ -e "s|@TLPVER@|$(TLPVER)|g" \
27+- -e "s|@TLP_SBIN@|$(TLP_SBIN)|g" \
28+- -e "s|@TLP_TLIB@|$(TLP_TLIB)|g" \
29+- -e "s|@TLP_FLIB@|$(TLP_FLIB)|g" \
30+- -e "s|@TLP_ULIB@|$(TLP_ULIB)|g" \
31++ -e "s|@TLP_SBIN@|$(_SBIN)|g" \
32++ -e "s|@TLP_TLIB@|$(_TLIB)|g" \
33++ -e "s|@TLP_FLIB@|$(_FLIB)|g" \
34++ -e "s|@TLP_ULIB@|$(_ULIB)|g" \
35+ -e "s|@TLP_CONFUSR@|$(TLP_CONFUSR)|g" \
36+ -e "s|@TLP_CONFDIR@|$(TLP_CONFDIR)|g" \
37+- -e "s|@TLP_CONFDEF@|$(TLP_CONFDEF)|g" \
38++ -e "s|@TLP_CONFDEF@|$(_CONFDEF)|g" \
39+ -e "s|@TLP_CONF@|$(TLP_CONF)|g" \
40+ -e "s|@TLP_RUN@|$(TLP_RUN)|g" \
41+ -e "s|@TLP_VAR@|$(TLP_VAR)|g" \
42+- -e "s|@TPACPIBAT@|$(TPACPIBAT)|g"
43++ -e "s|@TPACPIBAT@|$(_TPACPIBAT)|g"
44+45+ INFILES = \
46+ tlp \