biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / tools / misc / tlp / default.nix
blob8c2e3a9b7949d5f5ed59f070b400cd524a662f0e
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   buildInputs = [ perl ];
43   nativeBuildInputs = [ makeWrapper ];
45   # XXX: While [1] states that DESTDIR should not be used, and that the correct
46   # variable to set is, in fact, PREFIX, tlp thinks otherwise. The Makefile for
47   # tlp concerns itself only with DESTDIR [2] (possibly incorrectly) and so we set
48   # that as opposed to PREFIX, despite what [1] says.
49   #
50   # [1]: https://github.com/NixOS/nixpkgs/issues/65718
51   # [2]: https://github.com/linrunner/TLP/blob/ab788abf4936dfb44fbb408afc34af834230a64d/Makefile#L4-L46
52   makeFlags = [
53     "TLP_NO_INIT=1"
54     "TLP_WITH_ELOGIND=0"
55     "TLP_WITH_SYSTEMD=1"
57     "DESTDIR=${placeholder "out"}"
58     "TLP_BATD=/share/tlp/bat.d"
59     "TLP_BIN=/bin"
60     "TLP_CONFDEF=/share/tlp/defaults.conf"
61     "TLP_CONFREN=/share/tlp/rename.conf"
62     "TLP_FLIB=/share/tlp/func.d"
63     "TLP_MAN=/share/man"
64     "TLP_META=/share/metainfo"
65     "TLP_SBIN=/sbin"
66     "TLP_SHCPL=/share/bash-completion/completions"
67     "TLP_TLIB=/share/tlp"
68   ];
70   installTargets = [ "install-tlp" "install-man" ]
71   ++ lib.optionals enableRDW [ "install-rdw" "install-man-rdw" ];
73   doCheck = true;
74   nativeCheckInputs = [ checkbashisms perlcritic shellcheck ];
75   checkTarget = [ "checkall" ];
77   # TODO: Consider using resholve here
78   postInstall = let
79     paths = lib.makeBinPath (
80       [
81         coreutils
82         ethtool
83         gawk
84         gnugrep
85         gnused
86         hdparm
87         iw
88         kmod
89         pciutils
90         perl
91         smartmontools
92         systemd
93         util-linux
94       ] ++ lib.optional enableRDW networkmanager
95         ++ lib.optional (lib.meta.availableOn stdenv.hostPlatform x86_energy_perf_policy) x86_energy_perf_policy
96     );
97   in
98     ''
99       fixup_perl=(
100         $out/share/tlp/tlp-pcilist
101         $out/share/tlp/tlp-readconfs
102         $out/share/tlp/tlp-usblist
103       )
104       for f in "''${fixup_perl[@]}"; do
105         wrapProgram "$f" --prefix PATH : "${paths}"
106       done
108       fixup_bash=(
109         $out/bin/*
110         $out/etc/NetworkManager/dispatcher.d/*
111         $out/lib/udev/tlp-*
112         $out/sbin/*
113         $out/share/tlp/bat.d/*
114         $out/share/tlp/func.d/*
115         $out/share/tlp/tlp-func-base
116       )
117       for f in "''${fixup_bash[@]}"; do
118         sed -i '2iexport PATH=${paths}:$PATH' "$f"
119       done
121       rm -rf $out/var
122       rm -rf $out/share/metainfo
123     '';
125   meta = with lib; {
126     description = "Advanced Power Management for Linux";
127     homepage =
128       "https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html";
129     changelog = "https://github.com/linrunner/TLP/releases/tag/${version}";
130     platforms = platforms.linux;
131     mainProgram = "tlp";
132     maintainers = with maintainers; [ abbradar lovesegfault ];
133     license = licenses.gpl2Plus;
134   };