python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / tools / misc / tlp / default.nix
blobcbcc2ba38d2126a9e9ecc4943acec6fa68f70152
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.5.0";
29   src = fetchFromGitHub {
30     owner = "linrunner";
31     repo = "TLP";
32     rev = version;
33     sha256 = "sha256-hHel3BVMzTYfE59kxxADnm8tqtUFntqS3RzmJSZlWjM=";
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   checkInputs = [ 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         $out/share/tlp/tpacpi-bat
104       )
105       for f in "''${fixup_perl[@]}"; do
106         wrapProgram "$f" --prefix PATH : "${paths}"
107       done
109       fixup_bash=(
110         $out/bin/*
111         $out/etc/NetworkManager/dispatcher.d/*
112         $out/lib/udev/tlp-*
113         $out/sbin/*
114         $out/share/tlp/bat.d/*
115         $out/share/tlp/func.d/*
116         $out/share/tlp/tlp-func-base
117       )
118       for f in "''${fixup_bash[@]}"; do
119         sed -i '2iexport PATH=${paths}:$PATH' "$f"
120       done
122       rm -rf $out/var
123       rm -rf $out/share/metainfo
124     '';
126   meta = with lib; {
127     description = "Advanced Power Management for Linux";
128     homepage =
129       "https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html";
130     platforms = platforms.linux;
131     maintainers = with maintainers; [ abbradar lovesegfault ];
132     license = licenses.gpl2Plus;
133   };