lol
1{ lib, stdenv
2, coreutils
3, patchelf
4, requireFile
5, callPackage
6, makeWrapper
7, alsa-lib
8, dbus
9, fontconfig
10, freetype
11, gcc
12, glib
13, libssh2
14, ncurses
15, opencv4
16, openssl
17, unixODBC
18, xkeyboard_config
19, xorg
20, zlib
21, libxml2
22, libuuid
23, lang ? "en"
24, libGL
25, libGLU
26}:
27
28let
29 l10n =
30 import ./l10ns.nix {
31 lib = lib;
32 inherit requireFile lang;
33 };
34in
35stdenv.mkDerivation rec {
36 inherit (l10n) version name src;
37
38 buildInputs = [
39 coreutils
40 patchelf
41 makeWrapper
42 alsa-lib
43 coreutils
44 dbus
45 fontconfig
46 freetype
47 gcc.cc
48 gcc.libc
49 glib
50 libssh2
51 ncurses
52 opencv4
53 openssl
54 stdenv.cc.cc.lib
55 unixODBC
56 xkeyboard_config
57 libxml2
58 libuuid
59 zlib
60 libGL
61 libGLU
62 ] ++ (with xorg; [
63 libX11
64 libXext
65 libXtst
66 libXi
67 libXmu
68 libXrender
69 libxcb
70 libXcursor
71 libXfixes
72 libXrandr
73 libICE
74 libSM
75 ]);
76
77 ldpath = lib.makeLibraryPath buildInputs
78 + lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux")
79 (":" + lib.makeSearchPathOutput "lib" "lib64" buildInputs);
80
81 unpackPhase = ''
82 echo "=== Extracting makeself archive ==="
83 # find offset from file
84 offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
85 dd if="$src" ibs=$offset skip=1 | tar -xf -
86 cd Unix
87 '';
88
89 installPhase = ''
90 cd Installer
91 # don't restrict PATH, that has already been done
92 sed -i -e 's/^PATH=/# PATH=/' MathInstaller
93 sed -i -e 's/\/bin\/bash/\/bin\/sh/' MathInstaller
94
95 echo "=== Running MathInstaller ==="
96 ./MathInstaller -auto -createdir=y -execdir=$out/bin -targetdir=$out/libexec/Mathematica -silent
97
98 # Fix library paths
99 cd $out/libexec/Mathematica/Executables
100 for path in mathematica MathKernel Mathematica WolframKernel wolfram math; do
101 sed -i -e "2iexport LD_LIBRARY_PATH=${zlib}/lib:${stdenv.cc.cc.lib}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}\n" $path
102 done
103
104 # Fix xkeyboard config path for Qt
105 for path in mathematica Mathematica; do
106 sed -i -e "2iexport QT_XKB_CONFIG_ROOT=\"${xkeyboard_config}/share/X11/xkb\"\n" $path
107 done
108
109 # Remove some broken libraries
110 rm -f $out/libexec/Mathematica/SystemFiles/Libraries/Linux-x86-64/libz.so*
111
112 # Set environment variable to fix libQt errors - see https://github.com/NixOS/nixpkgs/issues/96490
113 wrapProgram $out/bin/mathematica --set USE_WOLFRAM_LD_LIBRARY_PATH 1
114 '';
115
116 preFixup = ''
117 echo "=== PatchElfing away ==="
118 # This code should be a bit forgiving of errors, unfortunately
119 set +e
120 find $out/libexec/Mathematica/SystemFiles -type f -perm -0100 | while read f; do
121 type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/')
122 if [ -z "$type" ]; then
123 :
124 elif [ "$type" == "EXEC" ]; then
125 echo "patching $f executable <<"
126 patchelf --shrink-rpath "$f"
127 patchelf \
128 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
129 --set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
130 "$f" \
131 && patchelf --shrink-rpath "$f" \
132 || echo unable to patch ... ignoring 1>&2
133 elif [ "$type" == "DYN" ]; then
134 echo "patching $f library <<"
135 patchelf \
136 --set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
137 "$f" \
138 && patchelf --shrink-rpath "$f" \
139 || echo unable to patch ... ignoring 1>&2
140 else
141 echo "not patching $f <<: unknown elf type"
142 fi
143 done
144 '';
145
146 dontBuild = true;
147
148 # This is primarily an IO bound build; there's little benefit to building remotely.
149 preferLocalBuild = true;
150
151 # all binaries are already stripped
152 dontStrip = true;
153
154 # we did this in prefixup already
155 dontPatchELF = true;
156
157 meta = with lib; {
158 description = "Wolfram Mathematica computational software system";
159 homepage = "http://www.wolfram.com/mathematica/";
160 license = licenses.unfree;
161 maintainers = with maintainers; [ herberteuler ];
162 platforms = [ "x86_64-linux" ];
163 };
164}