1{
2 lib,
3 stdenv,
4 autoPatchelfHook,
5 requireFile,
6 alsa-lib,
7 dbus,
8 fontconfig,
9 freetype,
10 gcc,
11 glib,
12 installShellFiles,
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 wrapQtAppsHook,
27}:
28
29let
30 l10n = import ./l10ns.nix {
31 lib = lib;
32 inherit requireFile lang;
33 };
34 dirName = "WolframEngine";
35in
36stdenv.mkDerivation rec {
37 inherit (l10n) version name src;
38
39 nativeBuildInputs = [
40 autoPatchelfHook
41 installShellFiles
42 wrapQtAppsHook
43 ];
44 dontWrapQtApps = true;
45
46 buildInputs = [
47 alsa-lib
48 dbus
49 fontconfig
50 freetype
51 gcc.cc
52 gcc.libc
53 glib
54 libssh2
55 ncurses
56 opencv4
57 openssl
58 (lib.getLib stdenv.cc.cc)
59 unixODBC
60 xkeyboard_config
61 libxml2
62 libuuid
63 zlib
64 libGL
65 libGLU
66 ]
67 ++ (with xorg; [
68 libX11
69 libXext
70 libXtst
71 libXi
72 libXmu
73 libXrender
74 libxcb
75 libXcursor
76 libXfixes
77 libXrandr
78 libICE
79 libSM
80 ]);
81
82 # some bundled libs are found through LD_LIBRARY_PATH
83 autoPatchelfIgnoreMissingDeps = true;
84
85 ldpath =
86 lib.makeLibraryPath buildInputs
87 + lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") (
88 ":" + lib.makeSearchPathOutput "lib" "lib64" buildInputs
89 );
90
91 unpackPhase = ''
92 # find offset from file
93 offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
94 dd if="$src" ibs=$offset skip=1 | tar -xf -
95 cd Unix
96 '';
97
98 installPhase = ''
99 cd Installer
100 sed -i -e 's/^PATH=/# PATH=/' -e 's/=`id -[ug]`/=0/' MathInstaller
101
102 # Installer wants to write default config in HOME
103 export HOME=$(mktemp -d)
104
105 # Fix the installation script
106 patchShebangs MathInstaller
107 substituteInPlace MathInstaller \
108 --replace-fail '`hostname`' "" \
109 --replace-fail "chgrp" "# chgrp" \
110 --replace-fail "chown" ": # chown"
111
112 # Install the desktop items
113 export XDG_DATA_HOME="$out/share"
114
115 ./MathInstaller -auto -createdir=y -execdir=$out/bin -targetdir=$out/libexec/${dirName} -silent
116
117 # Fix library paths
118 cd $out/libexec/${dirName}/Executables
119 for path in MathKernel math mcc wolfram; do
120 makeWrapper $out/libexec/${dirName}/Executables/$path $out/bin/$path --set LD_LIBRARY_PATH "${zlib}/lib:${lib.getLib stdenv.cc.cc}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}"
121 done
122
123 for path in WolframKernel wolframscript; do
124 makeWrapper $out/libexec/${dirName}/SystemFiles/Kernel/Binaries/Linux-x86-64/$path $out/bin/$path --set LD_LIBRARY_PATH "${zlib}/lib:${lib.getLib stdenv.cc.cc}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}"
125 done
126
127 wrapQtApp "$out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer" \
128 --set LD_LIBRARY_PATH "${zlib}/lib:${lib.getLib stdenv.cc.cc}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}" \
129 --set QT_XKB_CONFIG_ROOT "${xkeyboard_config}/share/X11/xkb"
130 if ! isELF "$out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer"; then
131 substituteInPlace $out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer \
132 --replace-fail "TopDirectory=" "TopDirectory=$out/libexec/${dirName} #";
133 fi
134
135 for path in WolframPlayer wolframplayer; do
136 makeWrapper $out/libexec/${dirName}/Executables/$path $out/bin/$path
137 done
138
139 # Install man pages
140 installManPage $out/libexec/${dirName}/SystemFiles/SystemDocumentation/Unix/*
141 '';
142
143 # This is primarily an IO bound build; there's little benefit to building remotely.
144 preferLocalBuild = true;
145
146 # Stripping causes the program to core dump.
147 dontStrip = true;
148
149 meta = with lib; {
150 description = "Wolfram Engine computational software system";
151 homepage = "https://www.wolfram.com/engine/";
152 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
153 license = licenses.unfree;
154 maintainers = with maintainers; [ fbeffa ];
155 platforms = [ "x86_64-linux" ];
156 };
157}