1{ stdenv, fetchurl, buildPackages, ncurses }:
2
3let dialect = with stdenv.lib; last (splitString "-" stdenv.system); in
4
5stdenv.mkDerivation rec {
6 name = "lsof-${version}";
7 version = "4.89";
8
9 depsBuildBuild = [ buildPackages.stdenv.cc ];
10 buildInputs = [ ncurses ];
11
12 src = fetchurl {
13 urls =
14 ["ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_${version}.tar.bz2"]
15 ++ map (
16 # the tarball is moved after new version is released
17 isOld: "ftp://sunsite.ualberta.ca/pub/Mirror/lsof/"
18 + "${stdenv.lib.optionalString isOld "OLD/"}lsof_${version}.tar.bz2"
19 ) [ false true ]
20 ++ map (
21 # the tarball is moved after new version is released
22 isOld: "http://www.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/"
23 + "${stdenv.lib.optionalString isOld "OLD/"}lsof_${version}.tar.bz2"
24 ) [ false true ]
25 ;
26 sha256 = "061p18v0mhzq517791xkjs8a5dfynq1418a1mwxpji69zp2jzb41";
27 };
28
29 unpackPhase = "tar xvjf $src; cd lsof_*; tar xvf lsof_*.tar; sourceRoot=$( echo lsof_*/); ";
30
31 patches = [ ./dfile.patch ];
32
33 postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
34 substituteInPlace dialects/linux/dlsof.h --replace "defined(__UCLIBC__)" 1
35 '';
36
37 # Stop build scripts from searching global include paths
38 LSOF_INCLUDE = "${stdenv.cc.libc}/include";
39 configurePhase = "LINUX_CONF_CC=$CC_FOR_BUILD LSOF_CC=$CC LSOF_AR=\"$AR cr\" LSOF_RANLIB=$RANLIB ./Configure -n ${dialect}";
40 preBuild = ''
41 sed -i Makefile -e 's/^CFGF=/& -DHASIPv6=1/;' -e 's/-lcurses/-lncurses/'
42 for filepath in $(find dialects/${dialect} -type f); do
43 sed -i "s,/usr/include,$LSOF_INCLUDE,g" $filepath
44 done
45 '';
46
47 installPhase = ''
48 mkdir -p $out/bin $out/man/man8
49 cp lsof.8 $out/man/man8/
50 cp lsof $out/bin
51 '';
52
53 meta = {
54 homepage = ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/;
55 description = "A tool to list open files";
56 longDescription = ''
57 List open files. Can show what process has opened some file,
58 socket (IPv6/IPv4/UNIX local), or partition (by opening a file
59 from it).
60 '';
61 maintainers = [ ];
62 platforms = stdenv.lib.platforms.unix;
63 };
64}