summary refs log tree commit diff
path: root/pkgs/applications/science/math/scilab-bin/default.nix
blob: 65d8c145bef6f813981ea922ff9181a3fb098297 (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
{ stdenv, fetchurl, lib, xorg }:

let
  badArch = throw "scilab-bin requires i686-linux or x86_64-linux";

  architecture =
    if stdenv.hostPlatform.system == "i686-linux" then
      "i686"
    else if stdenv.hostPlatform.system == "x86_64-linux" then
      "x86_64"
    else
      badArch;
in
stdenv.mkDerivation rec {
  pname = "scilab-bin";
  version = "6.1.1";

  src = fetchurl {
    url = "https://www.scilab.org/download/${version}/scilab-${version}.bin.linux-${architecture}.tar.gz";
    sha256 =
      if stdenv.hostPlatform.system == "i686-linux" then
        "0fgjc2ak3b2qi6yin3fy50qwk2bcj0zbz1h4lyyic9n1n1qcliib"
      else if stdenv.hostPlatform.system == "x86_64-linux" then
        "sha256-PuGnz2YdAhriavwnuf5Qyy0cnCeRHlWC6dQzfr7bLHk="
      else
        badArch;
  };

  libPath = lib.makeLibraryPath [
    stdenv.cc.cc
    xorg.libX11
    xorg.libXext
    xorg.libXi
    xorg.libXrender
    xorg.libXtst
    xorg.libXxf86vm
  ];

  fixupPhase = ''
    sed -i 's|\$(/bin/|$(|g' bin/scilab
    sed -i 's|/usr/bin/||g' bin/scilab

    sci="$out/opt/scilab-${version}"
    fullLibPath="$sci/lib/scilab:$sci/lib/thirdparty:$libPath"
    fullLibPath="$fullLibPath:$sci/lib/thirdparty/redist"

    patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
             --set-rpath "$fullLibPath" bin/scilab-bin
    find . -name '*.so' -type f | while read file; do
      patchelf --set-rpath "$fullLibPath" "$file" 2>/dev/null
    done
  '';

  installPhase = ''
    mkdir -p "$out/opt/scilab-${version}"
    cp -r . "$out/opt/scilab-${version}/"

    # Create bin/ dir
    mkdir "$out/bin"

    # Creating executable symlinks
    ln -s "$out/opt/scilab-${version}/bin/scilab" "$out/bin/scilab"
    ln -s "$out/opt/scilab-${version}/bin/scilab-cli" "$out/bin/scilab-cli"
    ln -s "$out/opt/scilab-${version}/bin/scilab-adv-cli" "$out/bin/scilab-adv-cli"

    # Creating desktop config dir
    mkdir -p "$out/share/applications"

    # Moving desktop config files
    mv $out/opt/scilab-${version}/share/applications/*.desktop $out/share/applications

    # Fixing Exec paths and launching each app with a terminal
    sed -i -e "s|Exec=|Exec=$out/opt/scilab-${version}/bin/|g" \
           -e "s|Terminal=.*$|Terminal=true|g" $out/share/applications/*.desktop

    # Moving icons to the appropriate locations
    for path in $out/opt/scilab-${version}/share/icons/hicolor/*/*/*
    do
      newpath=$(echo $path | sed 's|/opt/scilab-${version}||g')
      filename=$(echo $path | sed 's|.*/||g')
      dir=$(echo $newpath | sed "s|$filename||g")
      mkdir -p $dir
      mv $path $newpath
    done

    # Removing emptied folders
    rm -rf $out/opt/scilab-${version}/share/{applications,icons}

    # Moving other share/ folders
    mv $out/opt/scilab-${version}/share/{appdata,locale,mime} $out/share
  '';

  meta = {
    homepage = "http://www.scilab.org/";
    description = "Scientific software package for numerical computations (Matlab lookalike)";
    # see http://www.scilab.org/legal_notice
    license = "Scilab";
  };
}