base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12 (#356361)
[NixPkgs.git] / pkgs / tools / misc / tlp / default.nix
blobb70476166fc2fcadc613cf4c062f4a57dafe12e8
1 { stdenv
2 , lib
3 , checkbashisms
4 , coreutils
5 , ethtool
6 , fetchFromGitHub
7 , gawk
8 , gnugrep
9 , gnused
10 , hdparm
11 , iw
12 , kmod
13 , makeWrapper
14 , pciutils
15 , perl
16 , perlcritic
17 , shellcheck
18 , smartmontools
19 , systemd
20 , util-linux
21 , x86_energy_perf_policy
22   # RDW only works with NetworkManager, and thus is optional with default off
23 , enableRDW ? false
24 , networkmanager
25 }: stdenv.mkDerivation rec {
26   pname = "tlp";
27   version = "1.7.0";
29   src = fetchFromGitHub {
30     owner = "linrunner";
31     repo = "TLP";
32     rev = version;
33     hash = "sha256-kjtszDLlnIkBi3yU/AyGSV8q7QBuZbDhsqJ8AvULb0M=";
34   };
36   # XXX: See patch files for relevant explanations.
37   patches = [
38     ./patches/0001-makefile-correctly-sed-paths.patch
39     ./patches/0002-reintroduce-tlp-sleep-service.patch
40   ];
42   postPatch = ''
43     substituteInPlace Makefile --replace-fail ' ?= /usr/' ' ?= /'
44   '';
46   buildInputs = [ perl ];
47   nativeBuildInputs = [ makeWrapper ];
49   # XXX: While [1] states that DESTDIR should not be used, and that the correct
50   # variable to set is, in fact, PREFIX, tlp thinks otherwise. The Makefile for
51   # tlp concerns itself only with DESTDIR [2] (possibly incorrectly) and so we set
52   # that as opposed to PREFIX, despite what [1] says.
53   #
54   # [1]: https://github.com/NixOS/nixpkgs/issues/65718
55   # [2]: https://github.com/linrunner/TLP/blob/ab788abf4936dfb44fbb408afc34af834230a64d/Makefile#L4-L46
56   makeFlags = [
57     "TLP_NO_INIT=1"
58     "TLP_WITH_ELOGIND=0"
59     "TLP_WITH_SYSTEMD=1"
61     "DESTDIR=${placeholder "out"}"
62   ];
64   installTargets = [ "install-tlp" "install-man" ]
65   ++ lib.optionals enableRDW [ "install-rdw" "install-man-rdw" ];
67   doCheck = true;
68   nativeCheckInputs = [ checkbashisms perlcritic shellcheck ];
69   checkTarget = [ "checkall" ];
71   # TODO: Consider using resholve here
72   postInstall = let
73     paths = lib.makeBinPath (
74       [
75         coreutils
76         ethtool
77         gawk
78         gnugrep
79         gnused
80         hdparm
81         iw
82         kmod
83         pciutils
84         perl
85         smartmontools
86         systemd
87         util-linux
88       ] ++ lib.optional enableRDW networkmanager
89         ++ lib.optional (lib.meta.availableOn stdenv.hostPlatform x86_energy_perf_policy) x86_energy_perf_policy
90     );
91   in
92     ''
93       fixup_perl=(
94         $out/share/tlp/tlp-pcilist
95         $out/share/tlp/tlp-readconfs
96         $out/share/tlp/tlp-usblist
97       )
98       for f in "''${fixup_perl[@]}"; do
99         wrapProgram "$f" --prefix PATH : "${paths}"
100       done
102       fixup_bash=(
103         $out/bin/*
104         $out/etc/NetworkManager/dispatcher.d/*
105         $out/lib/udev/tlp-*
106         $out/sbin/*
107         $out/share/tlp/bat.d/*
108         $out/share/tlp/func.d/*
109         $out/share/tlp/tlp-func-base
110       )
111       for f in "''${fixup_bash[@]}"; do
112         sed -i '2iexport PATH=${paths}:$PATH' "$f"
113       done
115       rm -rf $out/var
116       rm -rf $out/share/metainfo
117     '';
119   meta = with lib; {
120     description = "Advanced Power Management for Linux";
121     homepage =
122       "https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html";
123     changelog = "https://github.com/linrunner/TLP/releases/tag/${version}";
124     platforms = platforms.linux;
125     mainProgram = "tlp";
126     maintainers = with maintainers; [ abbradar lovesegfault ];
127     license = licenses.gpl2Plus;
128   };