1{
2 lib,
3 fetchFromGitHub,
4 fetchpatch2,
5 stdenv,
6 autoreconfHook,
7 pkg-config,
8 ncurses,
9 libcap,
10 libnl,
11 sensorsSupport ? stdenv.hostPlatform.isLinux,
12 lm_sensors,
13 systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd,
14 systemd,
15}:
16
17assert systemdSupport -> stdenv.hostPlatform.isLinux;
18
19stdenv.mkDerivation rec {
20 pname = "htop-vim";
21 version = "3.4.0";
22
23 src = fetchFromGitHub {
24 owner = "htop-dev";
25 repo = "htop-vim";
26 rev = version;
27 hash = "sha256-4M2Kzy/tTpIZzpyubnXWywQh7Np5InT4sYkVG2v6wWs";
28 };
29
30 patches = [
31 (fetchpatch2 {
32 name = "vim-keybindings.patch";
33 url = "https://aur.archlinux.org/cgit/aur.git/plain/vim-keybindings.patch?h=htop-vim&id=d10f022b3ca1207200187a55f5b116a5bd8224f7";
34 hash = "sha256-fZDTA2dCOmXxUYD6Wm41q7TxL7fgQOj8a/8yJC7Zags=";
35 })
36 ];
37
38 # upstream removed pkg-config support and uses dlopen now
39 postPatch =
40 let
41 libnlPath = lib.getLib libnl;
42 in
43 lib.optionalString stdenv.hostPlatform.isLinux ''
44 substituteInPlace configure.ac \
45 --replace-fail /usr/include/libnl3 ${lib.getDev libnl}/include/libnl3
46 substituteInPlace linux/LibNl.c \
47 --replace-fail libnl-3.so ${libnlPath}/lib/libnl-3.so \
48 --replace-fail libnl-genl-3.so ${libnlPath}/lib/libnl-genl-3.so
49 '';
50
51 nativeBuildInputs = [ autoreconfHook ] ++ lib.optional stdenv.hostPlatform.isLinux pkg-config;
52
53 buildInputs = [
54 ncurses
55 ]
56 ++ lib.optionals stdenv.hostPlatform.isLinux [
57 libcap
58 libnl
59 ]
60 ++ lib.optional sensorsSupport lm_sensors
61 ++ lib.optional systemdSupport systemd;
62
63 configureFlags = [
64 "--enable-unicode"
65 "--sysconfdir=/etc"
66 ]
67 ++ lib.optionals stdenv.hostPlatform.isLinux [
68 "--enable-affinity"
69 "--enable-capabilities"
70 "--enable-delayacct"
71 ]
72 ++ lib.optional sensorsSupport "--enable-sensors";
73
74 postFixup =
75 let
76 optionalPatch = pred: so: lib.optionalString pred "patchelf --add-needed ${so} $out/bin/htop";
77 in
78 lib.optionalString (!stdenv.hostPlatform.isStatic) ''
79 ${optionalPatch sensorsSupport "${lib.getLib lm_sensors}/lib/libsensors.so"}
80 ${optionalPatch systemdSupport "${systemd}/lib/libsystemd.so"}
81 '';
82
83 meta = with lib; {
84 description = "Interactive process viewer, with vim-style keybindings";
85 homepage = "https://aur.archlinux.org/packages/htop-vim";
86 license = licenses.gpl2Only;
87 platforms = platforms.all;
88 maintainers = with maintainers; [ thiagokokada ];
89 mainProgram = "htop";
90 };
91}