nixpkgs/pkgs/applications/science/math/mathematica/default.nix

157 lines
3.9 KiB
Nix
Raw Normal View History

{ stdenv
, coreutils
, patchelf
, requireFile
, alsaLib
2017-10-05 00:14:53 +00:00
, dbus
, fontconfig
, freetype
, gcc
, glib
, libpng
, ncurses
, opencv
, openssl
, unixODBC
2017-10-05 00:14:53 +00:00
, xkeyboard_config
, xorg
, zlib
, libxml2
, libuuid
}:
let
platform =
if stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux" then
"Linux"
else
2013-10-01 11:12:10 +00:00
throw "Mathematica requires i686-linux or x86_64 linux";
in
stdenv.mkDerivation rec {
2017-10-05 00:14:53 +00:00
version = "11.2.0";
name = "mathematica-${version}";
src = requireFile rec {
name = "Mathematica_${version}_LINUX.sh";
message = ''
This nix expression requires that ${name} is
already part of the store. Find the file on your Mathematica CD
and add it to the nix store with nix-store --add-fixed sha256 <FILE>.
'';
2017-10-05 00:14:53 +00:00
sha256 = "4a1293cc1c404303aa1cab1bd273c7be151d37ac5ed928fbbb18e9c5ab2d8df9";
};
buildInputs = [
coreutils
patchelf
alsaLib
coreutils
2017-10-05 00:14:53 +00:00
dbus
fontconfig
freetype
gcc.cc
gcc.libc
glib
ncurses
opencv
openssl
unixODBC
2017-10-05 00:14:53 +00:00
xkeyboard_config
libxml2
libuuid
2017-07-17 03:32:16 +00:00
zlib
] ++ (with xorg; [
libX11
libXext
libXtst
libXi
libXmu
libXrender
libxcb
libXcursor
libXfixes
libXrandr
libICE
libSM
]);
ldpath = stdenv.lib.makeLibraryPath buildInputs
+ stdenv.lib.optionalString (stdenv.system == "x86_64-linux")
(":" + stdenv.lib.makeSearchPathOutput "lib" "lib64" buildInputs);
phases = "unpackPhase installPhase fixupPhase";
unpackPhase = ''
echo "=== Extracting makeself archive ==="
# find offset from file
offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
dd if="$src" ibs=$offset skip=1 | tar -xf -
cd Unix
'';
installPhase = ''
cd Installer
# don't restrict PATH, that has already been done
sed -i -e 's/^PATH=/# PATH=/' MathInstaller
2016-11-23 15:54:06 +00:00
sed -i -e 's/\/bin\/bash/\/bin\/sh/' MathInstaller
echo "=== Running MathInstaller ==="
2016-11-23 15:54:06 +00:00
./MathInstaller -auto -createdir=y -execdir=$out/bin -targetdir=$out/libexec/Mathematica -silent
2017-07-17 03:32:16 +00:00
# Fix library paths
cd $out/libexec/Mathematica/Executables
2017-07-19 08:39:36 +00:00
for path in mathematica MathKernel Mathematica WolframKernel wolfram math; do
2017-07-19 06:18:44 +00:00
sed -i -e 's#export LD_LIBRARY_PATH$#export LD_LIBRARY_PATH=${zlib}/lib:\''${LD_LIBRARY_PATH}#' $path
2017-07-17 03:32:16 +00:00
done
2017-10-05 00:14:53 +00:00
# Fix xkeyboard config path for Qt
for path in mathematica Mathematica; do
line=$(grep -n QT_PLUGIN_PATH $path | sed 's/:.*//')
sed -i -e "$line iexport QT_XKB_CONFIG_ROOT=\"${xkeyboard_config}/share/X11/xkb\"" $path
done
'';
preFixup = ''
echo "=== PatchElfing away ==="
# This code should be a bit forgiving of errors, unfortunately
set +e
find $out/libexec/Mathematica/SystemFiles -type f -perm -0100 | while read f; do
type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/')
if [ -z "$type" ]; then
:
elif [ "$type" == "EXEC" ]; then
echo "patching $f executable <<"
patchelf --shrink-rpath "$f"
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
"$f" \
&& patchelf --shrink-rpath "$f" \
|| echo unable to patch ... ignoring 1>&2
elif [ "$type" == "DYN" ]; then
echo "patching $f library <<"
patchelf \
--set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
"$f" \
&& patchelf --shrink-rpath "$f" \
|| echo unable to patch ... ignoring 1>&2
else
echo "not patching $f <<: unknown elf type"
fi
done
'';
# all binaries are already stripped
dontStrip = true;
# we did this in prefixup already
dontPatchELF = true;
meta = {
description = "Wolfram Mathematica computational software system";
homepage = http://www.wolfram.com/mathematica/;
license = stdenv.lib.licenses.unfree;
};
}