about summary refs log tree commit diff
path: root/pkgs/applications/science/math/mathematica/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/science/math/mathematica/default.nix')
-rw-r--r--pkgs/applications/science/math/mathematica/default.nix209
1 files changed, 42 insertions, 167 deletions
diff --git a/pkgs/applications/science/math/mathematica/default.nix b/pkgs/applications/science/math/mathematica/default.nix
index d24cff9e86cee..e48af60cc2fb7 100644
--- a/pkgs/applications/science/math/mathematica/default.nix
+++ b/pkgs/applications/science/math/mathematica/default.nix
@@ -1,173 +1,48 @@
-{ lib
-, stdenv
-, autoPatchelfHook
-, buildEnv
-, makeWrapper
-, requireFile
-, alsa-lib
-, cups
-, dbus
-, flite
-, fontconfig
-, freetype
-, gcc-unwrapped
-, glib
-, gmpxx
-, keyutils
-, libGL
-, libGLU
-, libpcap
-, libtins
-, libuuid
-, libxkbcommon
-, libxml2
-, llvmPackages_12
-, matio
-, mpfr
-, ncurses
-, opencv4
-, openjdk11
-, openssl
-, pciutils
-, tre
-, unixODBC
-, xkeyboard_config
-, xorg
-, zlib
+{ callPackage
+, config
+, lib
+, cudaPackages
+, cudaSupport ? config.cudaSupport or false
 , lang ? "en"
+, version ? null
 }:
 
-let
-  l10n = import ./l10ns.nix {
-    inherit lib requireFile lang;
-  };
-in stdenv.mkDerivation {
-  inherit (l10n) version name src;
-
-  nativeBuildInputs = [
-    autoPatchelfHook
-    makeWrapper
-  ];
-
-  buildInputs = [
-    alsa-lib
-    cups.lib
-    dbus
-    flite
-    fontconfig
-    freetype
-    glib
-    gmpxx
-    keyutils.lib
-    libGL
-    libGLU
-    libpcap
-    libtins
-    libuuid
-    libxkbcommon
-    libxml2
-    llvmPackages_12.libllvm.lib
-    matio
-    mpfr
-    ncurses
-    opencv4
-    openjdk11
-    openssl
-    pciutils
-    tre
-    unixODBC
-    xkeyboard_config
-  ] ++ (with xorg; [
-    libICE
-    libSM
-    libX11
-    libXScrnSaver
-    libXcomposite
-    libXcursor
-    libXdamage
-    libXext
-    libXfixes
-    libXi
-    libXinerama
-    libXmu
-    libXrandr
-    libXrender
-    libXtst
-    libxcb
-  ]);
-
-  wrapProgramFlags = [
-    "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ gcc-unwrapped.lib zlib ]}"
-    "--prefix PATH : ${lib.makeBinPath [ stdenv.cc ]}"
-    # Fix libQt errors - #96490
-    "--set USE_WOLFRAM_LD_LIBRARY_PATH 1"
-    # Fix xkeyboard config path for Qt
-    "--set QT_XKB_CONFIG_ROOT ${xkeyboard_config}/share/X11/xkb"
-  ];
-
-  unpackPhase = ''
-    runHook preUnpack
-
-    # Find offset from file
-    offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
-    tail -c +$(($offset + 1)) $src | tar -xf -
-
-    runHook postUnpack
-  '';
-
-  installPhase = ''
-    runHook preInstall
-
-    cd "$TMPDIR/Unix/Installer"
-
-    mkdir -p "$out/lib/udev/rules.d"
-
-    # Patch MathInstaller's shebangs and udev rules dir
-    patchShebangs MathInstaller
-    substituteInPlace MathInstaller \
-      --replace /etc/udev/rules.d $out/lib/udev/rules.d
-
-    # Remove PATH restriction, root and avahi daemon checks, and hostname call
-    sed -i '
-      s/^PATH=/# &/
-      s/isRoot="false"/# &/
-      s/^checkAvahiDaemon$/# &/
-      s/`hostname`/""/
-    ' MathInstaller
-
-    # NOTE: some files placed under HOME may be useful
-    XDG_DATA_HOME="$out/share" HOME="$TMPDIR/home" vernierLink=y \
-      ./MathInstaller -execdir="$out/bin" -targetdir="$out/libexec/Mathematica" -auto -verbose -createdir=y
-
-    # Check if MathInstaller produced any errors
-    errLog="$out/libexec/Mathematica/InstallErrors"
-    if [ -f "$errLog" ]; then
-      echo "Installation errors:"
-      cat "$errLog"
-      return 1
-    fi
-
-    runHook postInstall
-  '';
-
-  preFixup = ''
-    for bin in $out/libexec/Mathematica/Executables/*; do
-      wrapProgram "$bin" ''${wrapProgramFlags[@]}
-    done
-  '';
-
-  dontConfigure = true;
-  dontBuild = true;
-
-  # This is primarily an IO bound build; there's little benefit to building remotely
-  preferLocalBuild = true;
-
-  # All binaries are already stripped
-  dontStrip = true;
-
-  # NOTE: Some deps are still not found; ignore for now
-  autoPatchelfIgnoreMissingDeps = true;
-
+let versions = callPackage ./versions.nix { };
+
+    matching-versions =
+      lib.sort (v1: v2: lib.versionAtLeast v1.version v2.version) (lib.filter
+        (v: v.lang == lang
+            && (if version == null then true else isMatching v.version version))
+        versions);
+
+    found-version =
+      if matching-versions == []
+      then throw ("No registered Mathematica version found to match"
+                  + " version=${version} and language=${lang}")
+      else lib.head matching-versions;
+
+    specific-drv = ./. + "/(lib.versions.major found-version.version).nix";
+
+    real-drv = if lib.pathExists specific-drv
+               then specific-drv
+               else ./generic.nix;
+
+    isMatching = v1: v2:
+      let as      = lib.splitVersion v1;
+          bs      = lib.splitVersion v2;
+          n       = lib.min (lib.length as) (lib.length bs);
+          sublist = l: lib.sublist 0 n l;
+      in lib.compareLists lib.compare (sublist as) (sublist bs) == 0;
+
+in
+
+callPackage real-drv {
+  inherit cudaSupport cudaPackages;
+  inherit (found-version) version lang src;
+  name = ("mathematica"
+          + lib.optionalString cudaSupport "-cuda"
+          + "-${found-version.version}"
+          + lib.optionalString (lang != "en") "-${lang}");
   meta = with lib; {
     description = "Wolfram Mathematica computational software system";
     homepage = "http://www.wolfram.com/mathematica/";