1{ lib
2, stdenv
3, fetchurl
4, ncurses
5, pkg-config
6, fetchpatch
7
8 # `ps` with systemd support is able to properly report different
9 # attributes like unit name, so we want to have it on linux.
10, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd
11, systemd
12
13 # procps is mostly Linux-only. Most commands require a running Linux
14 # system (or very similar like that found in Cygwin). The one
15 # exception is ‘watch’ which is portable enough to run on pretty much
16 # any UNIX-compatible system.
17, watchOnly ? !(stdenv.isLinux || stdenv.isCygwin)
18
19, binlore
20, procps
21}:
22
23stdenv.mkDerivation rec {
24 pname = "procps";
25 version = "3.3.17";
26
27 # The project's releases are on SF, but git repo on gitlab.
28 src = fetchurl {
29 url = "mirror://sourceforge/procps-ng/procps-ng-${version}.tar.xz";
30 sha256 = "sha256-RRiz56r9NOwH0AY9JQ/UdJmbILIAIYw65W9dIRPxQbQ=";
31 };
32
33 patches = [
34 ./v3-CVE-2023-4016.patch
35 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
36 # NOTE: Starting from 4.x we will not need a patch anymore, but need to add
37 # "--disable-w" to configureFlags instead to prevent the utmp errors
38 (fetchpatch {
39 name = "musl-fix-includes.patch";
40 url = "https://git.alpinelinux.org/aports/plain/main/procps/musl-fixes.patch?id=37cb5b6ef194db66d9ed07c8ecab59bca3b91215";
41 sha256 = "sha256-DphAvESmVg1U3bJABU95R++QD34odStCl82EF0vmht0=";
42 })
43 ];
44
45 buildInputs = [ ncurses ]
46 ++ lib.optional withSystemd systemd;
47 nativeBuildInputs = [ pkg-config ];
48
49 makeFlags = [ "usrbin_execdir=$(out)/bin" ]
50 ++ lib.optionals watchOnly [ "watch" "PKG_LDFLAGS=" ];
51
52 enableParallelBuilding = true;
53
54 # Too red; 8bit support for fixing https://github.com/NixOS/nixpkgs/issues/275220
55 configureFlags = [ "--disable-modern-top" "--enable-watch8bit" ]
56 ++ lib.optional withSystemd "--with-systemd"
57 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
58 "ac_cv_func_malloc_0_nonnull=yes"
59 "ac_cv_func_realloc_0_nonnull=yes"
60 ];
61
62 installPhase = lib.optionalString watchOnly ''
63 install -m 0755 -D watch $out/bin/watch
64 install -m 0644 -D watch.1 $out/share/man/man1/watch.1
65 '';
66
67 # no obvious exec in documented arguments; haven't trawled source
68 # to figure out what exec binlore hits on
69 passthru.binlore.out = binlore.synthesize procps ''
70 execer cannot bin/{ps,top,free}
71 '';
72
73 meta = with lib; {
74 homepage = "https://gitlab.com/procps-ng/procps";
75 description = "Utilities that give information about processes using the /proc filesystem";
76 priority = 11; # less than coreutils, which also provides "kill" and "uptime"
77 license = licenses.gpl2Plus;
78 platforms = platforms.unix;
79 maintainers = [ maintainers.typetetris ];
80 };
81}