~vonfry/omnetpp-nix

ref: 48a32dcf365f9a9b789594e0c02f3d5738b0a429 omnetpp-nix/default.nix -rw-r--r-- 6.8 KiB
48a32dcfVonfry Add LICENSE 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{ stdenv, callPackage, lib, fetchurl, gawk, file, which, bison, flex, perl,
  qtbase, wrapQtAppsHook, libxml2, zlib, nemiver, withIDE ? true, jdk,
  makeWrapper, glib, cairo, gsettings-desktop-schemas, gtk, swt, fontconfig,
  freetype, libX11, libXrender, libXtst, webkitgtk, libsoup, atk, gdk-pixbuf,
  pango, libglvnd, libsecret, withNEDDocGen ? true, graphviz, doxygen,
  with3dVisualization ? false, openscenegraph, osgearth, withParallel ? true,
  openmpi, withPCAP ? true, libpcap, QT_STYLE_OVERRIDE ? "fusion",
  python ? null, R ? null, sqlite, preferSqlite ? true,
  # not free
  akaroa ? null
}:

assert withIDE -> ! builtins.any isNull [ jdk ];
assert (withIDE && withNEDDocGen) -> ! builtins.any isNull [ doxygen graphviz ];
assert with3dVisualization -> ! builtins.any isNull [ osgearth openscenegraph ];
assert withParallel -> ! isNull openmpi;
assert withPCAP -> ! isNull libpcap;

with lib;
let
  qtbaseDevDirs =
    mapAttrsToList (n: _: n)
                   (filterAttrs (_: v: v == "directory")
                                (builtins.readDir (qtbase.dev + /include)));
  qtbaseCFlags =
    concatMapStringsSep " "
                        (x: "-isystem ${qtbase.dev + /include}/${x}")
                        qtbaseDevDirs;
  libxml2CFlags = "-isystem ${libxml2.dev}/include/libxml2";

  OMNETPP_IMAGE_PATH = [ "./images"
                         "./bitmaps"
                         "${placeholder "out"}/share/images"
                       ];
in
stdenv.mkDerivation rec {
  pname = "omnetpp";
  version = "5.6.2";

  src = fetchurl {
    url = "https://github.com/omnetpp/omnetpp/releases/download/${pname}-${version}/${pname}-${version}-src-linux.tgz";
    sha256 = "0r8vfy90xah7wp49kdlz0a5x0b6nxy2ny9w45cbxr1l4759xdc4p";
  };

  outputs = [ "out" ];

  inherit QT_STYLE_OVERRIDE OMNETPP_IMAGE_PATH;

  propagatedNativeBuildInputs = [ gawk which perl file wrapQtAppsHook ];

  nativeBuildInputs = optional withIDE [ makeWrapper ];

  propagatedBuildInputs = [ python R sqlite ]
                       ++ optionals with3dVisualization [ osgearth
                                                          openscenegraph
                                                        ]
                       ++ optionals (withIDE && withNEDDocGen) [ graphviz
                                                                 doxygen
                                                               ]
                       ++ optional withParallel openmpi;
  buildInputs = [ nemiver akaroa zlib libxml2  qtbase bison flex ]
             ++ optionals withIDE [ jdk  webkitgtk gtk
                                    fontconfig freetype libX11 libXrender
                                    glib gsettings-desktop-schemas swt cairo
                                    libsoup atk gdk-pixbuf pango libsecret
                                    libglvnd
                                  ] # some of them has been contained in propagatedbuildinputs
             ++ optionals (withIDE && withNEDDocGen) [ graphviz doxygen ]
             ++ optional withPCAP libpcap;

  qtWrappersArgs = [ "--set QT_STYLE_OVERRIDE ${QT_STYLE_OVERRIDE}" ];

  NIX_CFLAGS_COMPILE = concatStringsSep " " [ qtbaseCFlags libxml2CFlags ];

  prePatch = ''
    substituteInPlace src/utils/Makefile \
      --replace \$\(HOME\) \$\(TMPDIR\)
    patchShebangs src/utils
  '';

  patches = [ ./patch.omnetpp ];

  configureFlags = [ "WITH_TKENV=no"
                     "OMNETPP_IMAGE_PATH=\"${concatStringsSep ";" OMNETPP_IMAGE_PATH}\""
                   ]
                   ++ optionals (!with3dVisualization) [ "WITH_OSG=no"
                                                         "WITH_OSGEARTH=no"
                                                       ]
                   ++ optional (!withParallel) "WITH_PARSIM=no"
                   ++ optional preferSqlite "PREFER_SQLITE_RESULT_FILES=yes";

  preConfigure = ''
    omnetpp_root=`pwd`
    export PATH=$omnetpp_root/bin:$PATH
    export HOSTNAME
    export HOST
    export QT_SELECT=5 # on systems with qtchooser, switch to Qt5
    # use patch instead, becasue of configure script has a problem with space
    # split between ~isystem~ and ~path~.
    export AR="ar cr"
    '';

  enableParallelBuilding = true;

  # Because omnetpp configure and makefile don't have install flag. In common,
  # all things run under omnetpp source directory. So I copy some file into out
  # directory by myself, but I don't know whether it can work or not.
  installPhase = ''
    runHook preInstall

    mkdir -p ${placeholder "out"}

    find samples -type d -name out | xargs rm -r

    installFiles=(lib bin include ide)
    for f in ''${installFiles[@]}; do
      cp -r $f ${placeholder "out"}
    done

    mkdir -p ${placeholder "out"}/share
    shareFiles=(Makefile.inc samples doc images)
    for f in ''${shareFiles[@]}; do
      cp -r $f ${placeholder "out"}/share
    done

    mkdir -p ${placeholder "out"}/share/emacs/site-lisp
    cp misc/emacs/*.el ${placeholder "out"}/share/emacs/site-lisp/

    runHook postInstall
    '';

  preFixup = ''
    (
      build_pwd=$(pwd)
      for bin in $(find ${placeholder "out"} -type f -executable); do
        rpath=$(patchelf --print-rpath $bin  \
                | sed -E "s,$build_pwd,${placeholder "out"}:,g" \
               || echo )
        if [ -n "$rpath" ]; then
          patchelf --set-rpath "$rpath" $bin
        fi
      done
    )
    '';

  dontStrip = true;

  postFixup = ''
    ( # wrap ide
      cd ${placeholder "out"}/ide
      patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux*.so.2 ./omnetpp
      wrapProgram ${placeholder "out"}/ide/omnetpp \
        --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH" \
        --prefix LD_LIBRARY_PATH : ${jdk}/lib/openjdk/lib/amd64 \
        --prefix LD_LIBRARY_PATH : ${makeLibraryPath (flatten
                                      [ freetype fontconfig libX11 libXrender
                                        zlib glib gtk libXtst webkitgtk swt
                                        cairo libsoup atk gdk-pixbuf pango
                                        libglvnd libsecret
                                      ])} \
        --prefix PATH : ${makeBinPath [ jdk ]}
    )
    for bin in $(find ${placeholder "out"}/share/samples -type f -executable); do
      wrapQtApp $bin \
        --set QT_STYLE_OVERRIDE ${QT_STYLE_OVERRIDE} \
        --prefix OMNETPP_IMAGE_PATH ";" "${concatStringsSep ";" OMNETPP_IMAGE_PATH}"
    done

    (
        cd ${placeholder "out"}/bin
        substituteInPlace opp_configfilepath \
          --replace ".." "../share"
    )
    wrapProgram ${placeholder "out"}/bin/omnetpp \
          --set GTK_THEME Awaita
    '';

  meta = with lib; {
    homepage= "https://omnetpp.org";
    description = "OMNeT++ is an extensible, modular, component-based C++ simulation library and framework, primarily for building network simulators.";
    license = licenses.unlicense;
    platforms = platforms.unix;
  };
}