nixpkgs/pkgs/tools/misc/tlp/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.2 KiB
Nix
Raw Normal View History

2020-02-26 01:39:35 +00:00
{ stdenv
, lib
, checkbashisms
, coreutils
, ethtool
, fetchFromGitHub
, gawk
, gnugrep
, gnused
, hdparm
, iw
, kmod
, makeWrapper
, pciutils
, perl
2021-10-16 06:45:44 +00:00
, perlcritic
2020-02-26 01:39:35 +00:00
, shellcheck
, smartmontools
, systemd
2020-11-24 15:29:28 +00:00
, util-linux
2020-02-26 01:39:35 +00:00
, x86_energy_perf_policy
# RDW only works with NetworkManager, and thus is optional with default off
, enableRDW ? false
, networkmanager
}: stdenv.mkDerivation rec {
pname = "tlp";
2024-10-15 11:49:21 +00:00
version = "1.7.0";
2015-01-02 15:11:29 +00:00
src = fetchFromGitHub {
owner = "linrunner";
repo = "TLP";
rev = version;
2024-10-15 11:49:21 +00:00
hash = "sha256-kjtszDLlnIkBi3yU/AyGSV8q7QBuZbDhsqJ8AvULb0M=";
};
2020-02-26 01:39:35 +00:00
# XXX: See patch files for relevant explanations.
2021-10-16 06:45:44 +00:00
patches = [
./patches/0001-makefile-correctly-sed-paths.patch
2022-01-24 02:34:38 +00:00
./patches/0002-reintroduce-tlp-sleep-service.patch
2021-10-16 06:45:44 +00:00
];
2015-01-02 15:11:29 +00:00
postPatch = ''
substituteInPlace Makefile --replace-fail ' ?= /usr/' ' ?= /'
'';
2020-02-26 01:39:35 +00:00
buildInputs = [ perl ];
nativeBuildInputs = [ makeWrapper ];
2020-02-26 01:39:35 +00:00
# XXX: While [1] states that DESTDIR should not be used, and that the correct
# variable to set is, in fact, PREFIX, tlp thinks otherwise. The Makefile for
# tlp concerns itself only with DESTDIR [2] (possibly incorrectly) and so we set
# that as opposed to PREFIX, despite what [1] says.
#
# [1]: https://github.com/NixOS/nixpkgs/issues/65718
# [2]: https://github.com/linrunner/TLP/blob/ab788abf4936dfb44fbb408afc34af834230a64d/Makefile#L4-L46
makeFlags = [
"TLP_NO_INIT=1"
2020-02-26 01:39:35 +00:00
"TLP_WITH_ELOGIND=0"
"TLP_WITH_SYSTEMD=1"
2015-01-02 15:11:29 +00:00
2022-01-24 02:34:38 +00:00
"DESTDIR=${placeholder "out"}"
2019-04-03 07:11:41 +00:00
];
2020-02-26 01:39:35 +00:00
installTargets = [ "install-tlp" "install-man" ]
++ lib.optionals enableRDW [ "install-rdw" "install-man-rdw" ];
2021-10-16 06:45:44 +00:00
doCheck = true;
nativeCheckInputs = [ checkbashisms perlcritic shellcheck ];
2019-04-03 07:11:41 +00:00
checkTarget = [ "checkall" ];
2021-10-16 06:45:44 +00:00
# TODO: Consider using resholve here
2020-02-26 01:39:35 +00:00
postInstall = let
paths = lib.makeBinPath (
[
coreutils
ethtool
gawk
gnugrep
gnused
hdparm
iw
kmod
pciutils
perl
smartmontools
systemd
2020-11-24 15:29:28 +00:00
util-linux
2020-02-26 01:39:35 +00:00
] ++ lib.optional enableRDW networkmanager
2021-02-25 16:21:13 +00:00
++ lib.optional (lib.meta.availableOn stdenv.hostPlatform x86_energy_perf_policy) x86_energy_perf_policy
2020-02-26 01:39:35 +00:00
);
in
''
fixup_perl=(
$out/share/tlp/tlp-pcilist
$out/share/tlp/tlp-readconfs
$out/share/tlp/tlp-usblist
)
for f in "''${fixup_perl[@]}"; do
wrapProgram "$f" --prefix PATH : "${paths}"
done
2016-11-23 15:07:29 +00:00
2020-02-26 01:39:35 +00:00
fixup_bash=(
$out/bin/*
$out/etc/NetworkManager/dispatcher.d/*
$out/lib/udev/tlp-*
$out/sbin/*
2021-10-16 06:45:44 +00:00
$out/share/tlp/bat.d/*
2020-02-26 01:39:35 +00:00
$out/share/tlp/func.d/*
$out/share/tlp/tlp-func-base
)
for f in "''${fixup_bash[@]}"; do
sed -i '2iexport PATH=${paths}:$PATH' "$f"
done
2021-10-16 06:45:44 +00:00
rm -rf $out/var
rm -rf $out/share/metainfo
2020-02-26 01:39:35 +00:00
'';
2015-01-02 15:11:29 +00:00
2020-02-26 01:39:35 +00:00
meta = with lib; {
2015-01-02 15:11:29 +00:00
description = "Advanced Power Management for Linux";
2020-02-26 01:39:35 +00:00
homepage =
"https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html";
changelog = "https://github.com/linrunner/TLP/releases/tag/${version}";
2015-01-02 15:11:29 +00:00
platforms = platforms.linux;
2024-05-02 13:10:01 +00:00
mainProgram = "tlp";
2020-02-26 04:03:16 +00:00
maintainers = with maintainers; [ abbradar lovesegfault ];
2015-01-02 15:11:29 +00:00
license = licenses.gpl2Plus;
};
}