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