1{
2 lib,
3 stdenv,
4 fetchurl,
5 versionCheckHook,
6 libpcap,
7 pkg-config,
8 openssl,
9 lua5_4,
10 pcre2,
11 liblinear,
12 libssh2,
13 zlib,
14 withLua ? true,
15}:
16
17stdenv.mkDerivation rec {
18 pname = "nmap";
19 version = "7.97";
20
21 src = fetchurl {
22 url = "https://nmap.org/dist/nmap-${version}.tar.bz2";
23 hash = "sha256-r5jyeSXGcMJX3Zap3fJyTgbLebL9Hg0IySBjFr4WRcA=";
24 };
25
26 prePatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
27 substituteInPlace libz/configure \
28 --replace /usr/bin/libtool ar \
29 --replace 'AR="libtool"' 'AR="ar"' \
30 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
31 '';
32
33 configureFlags = [
34 (if withLua then "--with-liblua=${lua5_4}" else "--without-liblua")
35 "--without-ndiff"
36 "--without-zenmap"
37 ];
38
39 postInstall = ''
40 install -m 444 -D nselib/data/passwords.lst $out/share/wordlists/nmap.lst
41 '';
42
43 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
44 install_name_tool -change liblinear.so.5 ${liblinear.out}/lib/liblinear.5.dylib $out/bin/nmap
45 '';
46
47 makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
48 "AR=${stdenv.cc.bintools.targetPrefix}ar"
49 "RANLIB=${stdenv.cc.bintools.targetPrefix}ranlib"
50 "CC=${stdenv.cc.targetPrefix}gcc"
51 ];
52
53 nativeBuildInputs = [ pkg-config ];
54 buildInputs = [
55 pcre2
56 liblinear
57 libssh2
58 libpcap
59 openssl
60 zlib
61 ];
62
63 enableParallelBuilding = true;
64
65 doCheck = false; # fails 3 tests, probably needs the net
66
67 nativeInstallCheckInputs = [
68 versionCheckHook
69 ];
70 versionCheckProgramArg = "-V";
71 doInstallCheck = true;
72
73 meta = {
74 description = "Free and open source utility for network discovery and security auditing";
75 homepage = "http://www.nmap.org";
76 changelog = "https://nmap.org/changelog.html#${version}";
77 license = lib.licenses.gpl2Only;
78 platforms = lib.platforms.all;
79 maintainers = with lib.maintainers; [
80 thoughtpolice
81 fpletz
82 ];
83 };
84}