@@ -0,0 +1,98 @@
1+{ stdenv
2+, fetchFromGitHub, fetchurl
3+, python
4+
5+# for binding generation
6+, castxml ? null
7+
8+# can take a long time, generates > 30000 images/graphs
9+, enableDoxygen ? false
10+
11+# e.g. "optimized" or "debug". If not set, use default one
12+, build_profile ? null
13+
14+# --enable-examples
15+, withExamples ? false
16+
17+# very long
18+, withManual ? false, doxygen ? null, graphviz ? null, imagemagick ? null
19+# for manual, tetex is used to get the eps2pdf binary
20+# texlive to get latexmk. building manual still fails though
21+, dia, tetex ? null, ghostscript ? null, texlive ? null
22+
23+# generates python bindings
24+, generateBindings ? false, ncurses ? null
25+
26+# All modules can be enabled by choosing 'all_modules'.
27+# we include here the DCE mandatory ones
28+, modules ? [ "core" "network" "internet" "point-to-point" "fd-net-device" "netanim"]
29+, gcc6
30+, lib
31+}:
32+
33+let
34+ pythonEnv = python.withPackages(ps:
35+ stdenv.lib.optional withManual ps.sphinx
36+ ++ stdenv.lib.optionals generateBindings (with ps;[ pybindgen pygccxml ])
37+ );
38+in
39+stdenv.mkDerivation rec {
40+
41+ name = "ns-3.${version}";
42+ version = "28";
43+
44+ # the all in one https://www.nsnam.org/release/ns-allinone-3.27.tar.bz2;
45+ # fetches everything (netanim, etc), this package focuses on ns3-core
46+ src = fetchFromGitHub {
47+ owner = "nsnam";
48+ repo = "ns-3-dev-git";
49+ rev = name;
50+ sha256 = "17kzfjpgw2mvyx1c9bxccnvw67jpk09fxmcnlkqx9xisk10qnhng";
51+ };
52+
53+ # ncurses is a hidden dependency of waf when checking python
54+ buildInputs = lib.optionals generateBindings [ castxml ncurses ]
55+ ++ stdenv.lib.optional enableDoxygen [ doxygen graphviz imagemagick ]
56+ ++ stdenv.lib.optional withManual [ dia tetex ghostscript texlive.combined.scheme-medium ];
57+
58+ propagatedBuildInputs = [ gcc6 pythonEnv ];
59+
60+ postPatch = ''
61+ patchShebangs ./waf
62+ patchShebangs doc/ns3_html_theme/get_version.sh
63+ '';
64+
65+ configureScript = "${python.interpreter} ./waf configure";
66+
67+ configureFlags = with stdenv.lib; [
68+ "--enable-modules=${stdenv.lib.concatStringsSep "," modules}"
69+ "--with-python=${pythonEnv.interpreter}"
70+ ]
71+ ++ optional (build_profile != null) "--build-profile=${build_profile}"
72+ ++ optional generateBindings [ ]
73+ ++ optional withExamples " --enable-examples "
74+ ++ optional doCheck " --enable-tests "
75+ ;
76+
77+ postBuild = with stdenv.lib; let flags = concatStringsSep ";" (
78+ optional enableDoxygen "./waf doxygen"
79+ ++ optional withManual "./waf sphinx"
80+ );
81+ in "${flags}"
82+ ;
83+
84+ doCheck = true;
85+
86+ # we need to specify the proper interpreter else ns3 can check against a
87+ # different version even though we
88+ checkPhase = ''
89+ ${pythonEnv.interpreter} ./test.py
90+ '';
91+
92+ meta = {
93+ homepage = http://www.nsnam.org;
94+ license = stdenv.lib.licenses.gpl3;
95+ description = "A discrete time event network simulator";
96+ platforms = with stdenv.lib.platforms; unix;
97+ };
98+}