1{ lib, stdenv, fetchFromGitHub, buildPackages, ncurses }:
2
3let dialect = with lib; last (splitString "-" stdenv.hostPlatform.system); in
4
5stdenv.mkDerivation rec {
6 pname = "lsof";
7 version = "4.94.0";
8
9 depsBuildBuild = [ buildPackages.stdenv.cc ];
10 buildInputs = [ ncurses ];
11
12 src = fetchFromGitHub {
13 owner = "lsof-org";
14 repo = "lsof";
15 rev = version;
16 sha256 = "0yxv2jg6rnzys49lyrz9yjb4knamah4xvlqj596y6ix3vm4k3chp";
17 };
18
19 patches = [ ./no-build-info.patch ];
20
21 postPatch = lib.optionalString stdenv.hostPlatform.isMusl ''
22 substituteInPlace dialects/linux/dlsof.h --replace "defined(__UCLIBC__)" 1
23 '' + lib.optionalString stdenv.isDarwin ''
24 sed -i 's|lcurses|lncurses|g' Configure
25 '';
26
27 # Stop build scripts from searching global include paths
28 LSOF_INCLUDE = "${lib.getDev stdenv.cc.libc}/include";
29 configurePhase = "LINUX_CONF_CC=$CC_FOR_BUILD LSOF_CC=$CC LSOF_AR=\"$AR cr\" LSOF_RANLIB=$RANLIB ./Configure -n ${dialect}";
30 preBuild = ''
31 for filepath in $(find dialects/${dialect} -type f); do
32 sed -i "s,/usr/include,$LSOF_INCLUDE,g" $filepath
33 done
34 '';
35
36 installPhase = ''
37 # Fix references from man page https://github.com/lsof-org/lsof/issues/66
38 substituteInPlace Lsof.8 \
39 --replace ".so ./00DIALECTS" "" \
40 --replace ".so ./version" ".ds VN ${version}"
41 mkdir -p $out/bin $out/man/man8
42 cp Lsof.8 $out/man/man8/lsof.8
43 cp lsof $out/bin
44 '';
45
46 meta = with lib; {
47 homepage = "https://github.com/lsof-org/lsof";
48 description = "A tool to list open files";
49 longDescription = ''
50 List open files. Can show what process has opened some file,
51 socket (IPv6/IPv4/UNIX local), or partition (by opening a file
52 from it).
53 '';
54 maintainers = [ maintainers.dezgeg ];
55 platforms = platforms.unix;
56 license = licenses.purdueBsd;
57 };
58}