nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 addDriverRunpath,
3 autoPatchelfHook,
4 lib,
5 makeWrapper,
6 requireFile,
7 runCommand,
8 stdenv,
9 symlinkJoin,
10 # arguments from default.nix
11 lang,
12 meta,
13 name,
14 src,
15 version,
16 # dependencies
17 alsa-lib,
18 cudaPackages,
19 cups,
20 dbus,
21 flite,
22 fontconfig,
23 freetype,
24 gcc-unwrapped,
25 glib,
26 gmpxx,
27 keyutils,
28 libGL,
29 libGLU,
30 libpcap,
31 libtins,
32 libuuid,
33 libxkbcommon,
34 libxml2,
35 llvmPackages,
36 matio,
37 mpfr,
38 ncurses,
39 opencv4,
40 openjdk11,
41 openssl,
42 pciutils,
43 tre,
44 unixODBC,
45 xcbutilimage,
46 xcbutilkeysyms,
47 xkeyboard_config,
48 libxtst,
49 libxscrnsaver,
50 libxrender,
51 libxrandr,
52 libxmu,
53 libxi,
54 libxinerama,
55 libxfixes,
56 libxext,
57 libxdamage,
58 libxcursor,
59 libxcomposite,
60 libx11,
61 libsm,
62 libice,
63 libxcb,
64 zlib,
65 # options
66 cudaSupport,
67}:
68
69let
70 cudaEnv = symlinkJoin {
71 name = "mathematica-cuda-env";
72 paths = with cudaPackages; [
73 cuda_cudart
74 cuda_nvcc
75 libcublas
76 libcufft
77 libcurand
78 libcusparse
79 ];
80 postBuild = ''
81 if [ ! -e $out/lib/libcuda.so ]; then
82 ln -s ${addDriverRunpath.driverLink}/lib/libcuda.so $out/lib
83 fi
84 ln -s lib $out/lib64
85 '';
86 };
87
88in
89stdenv.mkDerivation {
90 inherit
91 meta
92 name
93 src
94 version
95 ;
96
97 nativeBuildInputs = [
98 autoPatchelfHook
99 makeWrapper
100 ]
101 ++ lib.optional cudaSupport addDriverRunpath;
102
103 buildInputs = [
104 alsa-lib
105 cups.lib
106 dbus
107 flite
108 fontconfig
109 freetype
110 glib
111 gmpxx
112 keyutils.lib
113 libGL
114 libGLU
115 libpcap
116 libtins
117 libuuid
118 libxkbcommon
119 libxml2
120 llvmPackages.libllvm.lib
121 matio
122 mpfr
123 ncurses
124 opencv4
125 openjdk11
126 openssl
127 pciutils
128 tre
129 unixODBC
130 xcbutilimage
131 xcbutilkeysyms
132 xkeyboard_config
133 libice
134 libsm
135 libx11
136 libxscrnsaver
137 libxcomposite
138 libxcursor
139 libxdamage
140 libxext
141 libxfixes
142 libxi
143 libxinerama
144 libxmu
145 libxrandr
146 libxrender
147 libxtst
148 libxcb
149 ]
150 ++ lib.optional cudaSupport cudaEnv;
151
152 wrapProgramFlags = [
153 "--prefix LD_LIBRARY_PATH : ${
154 lib.makeLibraryPath [
155 dbus
156 gcc-unwrapped.lib
157 zlib
158 ]
159 }"
160 "--prefix PATH : ${lib.makeBinPath [ stdenv.cc ]}"
161 # Fix libQt errors - #96490
162 "--set USE_WOLFRAM_LD_LIBRARY_PATH 1"
163 # Fix xkeyboard config path for Qt
164 "--set QT_XKB_CONFIG_ROOT ${xkeyboard_config}/share/X11/xkb"
165 # if wayland isn't supported we fail over to xcb
166 # see https://github.com/qt/qtbase/blob/35d0f012ee9b95e8cf3563a41d710ff3c023d841/src/gui/kernel/qguiapplication.cpp#L1218
167 "--set QT_QPA_PLATFORM wayland;xcb"
168 ]
169 ++ lib.optionals cudaSupport [
170 "--set CUDA_PATH ${cudaEnv}"
171 "--set NVIDIA_DRIVER_LIBRARY_PATH ${addDriverRunpath.driverLink}/lib/libnvidia-tls.so"
172 "--set CUDA_LIBRARY_PATH ${addDriverRunpath.driverLink}/lib/libcuda.so"
173 ];
174
175 unpackPhase = ''
176 runHook preUnpack
177
178 # Find offset from file
179 offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
180 tail -c +$(($offset + 1)) $src | tar -xf -
181
182 runHook postUnpack
183 '';
184
185 installPhase = ''
186 runHook preInstall
187
188 cd "$TMPDIR/Unix/Installer"
189
190 mkdir -p "$out/lib/udev/rules.d"
191
192 # Set name of installer file
193 if [ -f "MathInstaller" ]; then
194 INSTALLER="MathInstaller"
195 else
196 INSTALLER="WolframInstaller"
197 fi
198 # Patch Installer's shebangs and udev rules dir
199 patchShebangs $INSTALLER
200 substituteInPlace $INSTALLER \
201 --replace /etc/udev/rules.d $out/lib/udev/rules.d
202
203 # Remove PATH restriction, root and avahi daemon checks, and hostname call
204 sed -i '
205 s/^\s*PATH=/# &/
206 s/isRoot="false"/# &/
207 s/^\s*checkAvahiDaemon$/:/
208 s/^\s*installBundledInstall$/:/
209 s/`hostname`/""/
210 ' $INSTALLER
211
212 # NOTE: some files placed under HOME may be useful
213 XDG_DATA_HOME="$out/share" HOME="$TMPDIR/home" vernierLink=y \
214 ./$INSTALLER -execdir="$out/bin" -targetdir="$out/libexec/Mathematica" -auto -verbose -createdir=y
215
216 # Check if Installer produced any errors
217 errLog="$out/libexec/Mathematica/InstallErrors"
218 if [ -f "$errLog" ]; then
219 echo "Installation errors:"
220 cat "$errLog"
221 return 1
222 fi
223
224 runHook postInstall
225 '';
226
227 preFixup = ''
228 for bin in $out/libexec/Mathematica/Executables/*; do
229 wrapProgram "$bin" ''${wrapProgramFlags[@]}
230 done
231 '';
232
233 dontConfigure = true;
234 dontBuild = true;
235
236 # This is primarily an IO bound build; there's little benefit to building remotely
237 preferLocalBuild = true;
238
239 # All binaries are already stripped
240 dontStrip = true;
241
242 # NOTE: Some deps are still not found; ignore for now
243 autoPatchelfIgnoreMissingDeps = true;
244}