lol
1{ stdenv, lib, fetchurl, pkgconfig
2, dpdk, libpcap, numactl, utillinux
3, gtk2, withGtk ? false
4}:
5
6let
7
8 # pktgen needs a specific version of lua to apply its patch (see lib/lua/Makefile).
9 lua = rec {
10 name = "lua-5.3.4";
11 basename = name + ".tar.gz";
12 src = fetchurl {
13 url = "https://www.lua.org/ftp/${basename}";
14 sha256 = "0320a8dg3aci4hxla380dx1ifkw8gj4gbw5c4dz41g1kh98sm0gn";
15 };
16 };
17
18in stdenv.mkDerivation rec {
19 name = "pktgen-${version}";
20 version = "3.5.0";
21
22 src = fetchurl {
23 url = "http://dpdk.org/browse/apps/pktgen-dpdk/snapshot/pktgen-${version}.tar.xz";
24 sha256 = "1gy99jr9dbwzi9pd3w5k673h3pfnbkz6rbzmrkwcyis72pnphy5z";
25 };
26
27 nativeBuildInputs = stdenv.lib.optionals withGtk [ pkgconfig ];
28
29 buildInputs =
30 [ dpdk libpcap numactl ]
31 ++ stdenv.lib.optionals withGtk [gtk2];
32
33 RTE_SDK = "${dpdk}/share/dpdk";
34 RTE_TARGET = "x86_64-native-linuxapp-gcc";
35 GUI = stdenv.lib.optionalString withGtk "true";
36
37 NIX_CFLAGS_COMPILE = [ "-msse3" ];
38
39 postPatch = let dpdkMajor = lib.versions.major dpdk.version; in ''
40 substituteInPlace app/Makefile --replace 'yy :=' 'yy := ${dpdkMajor} #'
41 substituteInPlace lib/common/lscpu.h --replace /usr/bin/lscpu ${utillinux}/bin/lscpu
42
43 ln -s ${lua.src} lib/lua/${lua.basename}
44 make -C lib/lua get_tarball # unpack and patch
45 substituteInPlace lib/lua/${lua.name}/src/luaconf.h --replace /usr/local $out
46 '';
47
48 installPhase = ''
49 install -d $out/bin
50 install -m 0755 app/${RTE_TARGET}/pktgen $out/bin
51 install -d $out/lib/lua/5.3
52 install -m 0644 Pktgen.lua $out/lib/lua/5.3
53 '';
54
55 enableParallelBuilding = true;
56
57 meta = with stdenv.lib; {
58 description = "Traffic generator powered by DPDK";
59 homepage = http://dpdk.org/;
60 license = licenses.bsdOriginal;
61 platforms = [ "x86_64-linux" ];
62 maintainers = [ maintainers.abuibrahim ];
63 };
64}