about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/misc/tlp/default.nix
blob: e5932d9e9462a8b58ea4be8518cbc1defa532132 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{ stdenv, lib, fetchFromGitHub, perl, makeWrapper, file, systemd, iw, rfkill
, hdparm, ethtool, inetutils , kmod, pciutils, smartmontools
, x86_energy_perf_policy, gawk, gnugrep, coreutils, utillinux
, checkbashisms, shellcheck
, enableRDW ? false, networkmanager
}:

let
  paths = lib.makeBinPath
          ([ iw rfkill hdparm ethtool inetutils systemd kmod pciutils smartmontools
             x86_energy_perf_policy gawk gnugrep coreutils utillinux
           ]
           ++ lib.optional enableRDW networkmanager
          );

in stdenv.mkDerivation rec {
  pname = "tlp";
  version = "1.2.2";

  src = fetchFromGitHub {
    owner = "linrunner";
    repo = "TLP";
    rev = version;
    sha256 = "0vm31ca6kdak9xzwskz7a8hvdp67drfh2zcdwlz3260r8r2ypgg1";
  };

  outRef = placeholder "out";

  makeFlags = [
    "DESTDIR=${outRef}"
    "TLP_SBIN=${outRef}/bin"
    "TLP_BIN=${outRef}/bin"
    "TLP_TLIB=${outRef}/share/tlp"
    "TLP_FLIB=${outRef}/share/tlp/func.d"
    "TLP_ULIB=${outRef}/lib/udev"
    "TLP_NMDSP=${outRef}/etc/NetworkManager/dispatcher.d"
    "TLP_SHCPL=${outRef}/share/bash-completion/completions"
    "TLP_MAN=${outRef}/share/man"
    "TLP_META=${outRef}/share/metainfo"

    "TLP_NO_INIT=1"
  ];

  nativeBuildInputs = [ makeWrapper file ];

  buildInputs = [ perl ];

  installTargets = [ "install-tlp" "install-man" ] ++ stdenv.lib.optional enableRDW "install-rdw";

  checkInputs = [
    checkbashisms
    shellcheck
  ];

  doCheck = true;
  checkTarget = [ "checkall" ];

  postInstall = ''
    cp -r $out/$out/* $out
    rm -rf $out/$(echo "$NIX_STORE" | cut -d "/" -f2)

    for i in $out/bin/* $out/lib/udev/tlp-* ${lib.optionalString enableRDW "$out/etc/NetworkManager/dispatcher.d/*"}; do
      if file "$i" | grep -q Perl; then
        # Perl script; use wrapProgram
        wrapProgram "$i" \
          --prefix PATH : "${paths}"
      else
        # Bash script
        sed -i '2iexport PATH=${paths}:$PATH' "$i"
      fi
    done
  '';

  meta = with stdenv.lib; {
    description = "Advanced Power Management for Linux";
    homepage = https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html;
    platforms = platforms.linux;
    maintainers = with maintainers; [ abbradar ];
    license = licenses.gpl2Plus;
  };
}