about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/math/wolfram-engine/default.nix
blob: 685bc1bff3b18e72bdb023ce3f9a6df5cc89815e (plain) (blame)
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
{ lib
, stdenv
, autoPatchelfHook
, requireFile
, callPackage
, makeWrapper
, alsa-lib
, dbus
, fontconfig
, freetype
, gcc
, glib
, installShellFiles
, libssh2
, ncurses
, opencv4
, openssl
, unixODBC
, xkeyboard_config
, xorg
, zlib
, libxml2
, libuuid
, lang ? "en"
, libGL
, libGLU
, wrapQtAppsHook
}:

let
  l10n = import ./l10ns.nix {
    lib = lib;
    inherit requireFile lang;
  };
  dirName = "WolframEngine";
in
stdenv.mkDerivation rec {
  inherit (l10n) version name src;

  nativeBuildInputs = [
    autoPatchelfHook
    installShellFiles
    wrapQtAppsHook
  ];
  dontWrapQtApps = true;

  buildInputs = [
    alsa-lib
    dbus
    fontconfig
    freetype
    gcc.cc
    gcc.libc
    glib
    libssh2
    ncurses
    opencv4
    openssl
    stdenv.cc.cc.lib
    unixODBC
    xkeyboard_config
    libxml2
    libuuid
    zlib
    libGL
    libGLU
  ] ++ (with xorg; [
    libX11
    libXext
    libXtst
    libXi
    libXmu
    libXrender
    libxcb
    libXcursor
    libXfixes
    libXrandr
    libICE
    libSM
  ]);

  # some bundled libs are found through LD_LIBRARY_PATH
  autoPatchelfIgnoreMissingDeps = true;

  ldpath = lib.makeLibraryPath buildInputs
    + lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux")
      (":" + lib.makeSearchPathOutput "lib" "lib64" buildInputs);

  unpackPhase = ''
    # 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
    sed -i -e 's/^PATH=/# PATH=/' -e 's/=`id -[ug]`/=0/' MathInstaller

    # Installer wants to write default config in HOME
    export HOME=$(mktemp -d)

    # Fix the installation script
    patchShebangs MathInstaller
    substituteInPlace MathInstaller \
      --replace '`hostname`' "" \
      --replace "chgrp" "# chgrp" \
      --replace "chown" ": # chown"

    # Install the desktop items
    export XDG_DATA_HOME="$out/share"

    ./MathInstaller -auto -createdir=y -execdir=$out/bin -targetdir=$out/libexec/${dirName} -silent

    # Fix library paths
    cd $out/libexec/${dirName}/Executables
    for path in MathKernel math mcc wolfram; do
      makeWrapper $out/libexec/${dirName}/Executables/$path $out/bin/$path --set LD_LIBRARY_PATH "${zlib}/lib:${stdenv.cc.cc.lib}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}"
    done

    for path in WolframKernel wolframscript; do
      makeWrapper $out/libexec/${dirName}/SystemFiles/Kernel/Binaries/Linux-x86-64/$path $out/bin/$path --set LD_LIBRARY_PATH "${zlib}/lib:${stdenv.cc.cc.lib}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}"
    done

    wrapQtApp "$out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer" \
      --set LD_LIBRARY_PATH "${zlib}/lib:${stdenv.cc.cc.lib}/lib:${libssh2}/lib:\''${LD_LIBRARY_PATH}" \
      --set QT_XKB_CONFIG_ROOT "${xkeyboard_config}/share/X11/xkb"
    if ! isELF "$out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer"; then
      substituteInPlace $out/libexec/${dirName}/SystemFiles/FrontEnd/Binaries/Linux-x86-64/WolframPlayer \
        --replace "TopDirectory=" "TopDirectory=$out/libexec/${dirName} #";
    fi

    for path in WolframPlayer wolframplayer; do
      makeWrapper $out/libexec/${dirName}/Executables/$path $out/bin/$path
    done

    # Install man pages
    installManPage $out/libexec/${dirName}/SystemFiles/SystemDocumentation/Unix/*
  '';

  # This is primarily an IO bound build; there's little benefit to building remotely.
  preferLocalBuild = true;

  # Stripping causes the program to core dump.
  dontStrip = true;

  meta = with lib; {
    description = "Wolfram Engine computational software system";
    homepage = "https://www.wolfram.com/engine/";
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license = licenses.unfree;
    maintainers = with maintainers; [ fbeffa ];
    platforms = [ "x86_64-linux" ];
  };
}