Merge pull request #211867 from wegank/scilab-bin-refactor

scilab-bin: refactor

authored by Weijia Wang and committed by GitHub 4389f864 31ce09b3

+51 -61
+51 -61
pkgs/applications/science/math/scilab-bin/default.nix
··· 1 - { lib, stdenv, fetchurl, undmg, makeWrapper, xorg }: 1 + { lib 2 + , stdenv 3 + , fetchurl 4 + , makeWrapper 5 + , undmg 6 + , autoPatchelfHook 7 + , alsa-lib 8 + , ncurses5 9 + , xorg 10 + }: 2 11 3 12 let 4 13 pname = "scilab-bin"; ··· 26 35 platforms = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ]; 27 36 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 28 37 license = lib.licenses.gpl2Only; 38 + mainProgram = "scilab"; 29 39 }; 30 40 31 41 darwin = stdenv.mkDerivation rec { 32 42 inherit pname version src meta; 33 43 34 - nativeBuildInputs = [ undmg makeWrapper ]; 44 + nativeBuildInputs = [ 45 + makeWrapper 46 + undmg 47 + ]; 35 48 36 49 sourceRoot = "scilab-${version}.app"; 37 50 38 51 installPhase = '' 52 + runHook preInstall 53 + 39 54 mkdir -p $out/{Applications/scilab.app,bin} 40 55 cp -R . $out/Applications/scilab.app 41 56 makeWrapper $out/{Applications/scilab.app/Contents/MacOS,bin}/scilab 57 + 58 + runHook postInstall 42 59 ''; 43 60 }; 44 61 45 62 linux = stdenv.mkDerivation rec { 46 63 inherit pname version src meta; 47 64 48 - libPath = lib.makeLibraryPath [ 49 - stdenv.cc.cc 50 - xorg.libX11 51 - xorg.libXext 52 - xorg.libXi 53 - xorg.libXrender 54 - xorg.libXtst 55 - xorg.libXxf86vm 56 - ]; 57 - 58 - fixupPhase = '' 59 - sed -i 's|\$(/bin/|$(|g' bin/scilab 60 - sed -i 's|/usr/bin/||g' bin/scilab 61 - 62 - sci="$out/opt/scilab-${version}" 63 - fullLibPath="$sci/lib/scilab:$sci/lib/thirdparty:$libPath" 64 - fullLibPath="$fullLibPath:$sci/lib/thirdparty/redist" 65 - 66 - patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ 67 - --set-rpath "$fullLibPath" bin/scilab-bin 68 - find . -name '*.so' -type f | while read file; do 69 - patchelf --set-rpath "$fullLibPath" "$file" 2>/dev/null 70 - done 71 - ''; 72 - 73 - installPhase = '' 74 - mkdir -p "$out/opt/scilab-${version}" 75 - cp -r . "$out/opt/scilab-${version}/" 76 - 77 - # Create bin/ dir 78 - mkdir "$out/bin" 79 - 80 - # Creating executable symlinks 81 - ln -s "$out/opt/scilab-${version}/bin/scilab" "$out/bin/scilab" 82 - ln -s "$out/opt/scilab-${version}/bin/scilab-cli" "$out/bin/scilab-cli" 83 - ln -s "$out/opt/scilab-${version}/bin/scilab-adv-cli" "$out/bin/scilab-adv-cli" 84 - 85 - # Creating desktop config dir 86 - mkdir -p "$out/share/applications" 87 - 88 - # Moving desktop config files 89 - mv $out/opt/scilab-${version}/share/applications/*.desktop $out/share/applications 65 + nativeBuildInputs = [ 66 + autoPatchelfHook 67 + ]; 90 68 91 - # Fixing Exec paths and launching each app with a terminal 92 - sed -i -e "s|Exec=|Exec=$out/opt/scilab-${version}/bin/|g" \ 93 - -e "s|Terminal=.*$|Terminal=true|g" $out/share/applications/*.desktop 69 + buildInputs = [ 70 + alsa-lib 71 + ncurses5 72 + stdenv.cc.cc 73 + ] ++ (with xorg; [ 74 + libX11 75 + libXcursor 76 + libXext 77 + libXft 78 + libXi 79 + libXrandr 80 + libXrender 81 + libXtst 82 + libXxf86vm 83 + ]); 94 84 95 - # Moving icons to the appropriate locations 96 - for path in $out/opt/scilab-${version}/share/icons/hicolor/*/*/* 97 - do 98 - newpath=$(echo $path | sed 's|/opt/scilab-${version}||g') 99 - filename=$(echo $path | sed 's|.*/||g') 100 - dir=$(echo $newpath | sed "s|$filename||g") 101 - mkdir -p $dir 102 - mv $path $newpath 103 - done 85 + installPhase = '' 86 + runHook preInstall 104 87 105 - # Removing emptied folders 106 - rm -rf $out/opt/scilab-${version}/share/{applications,icons} 88 + mkdir -p $out 89 + mv -t $out bin include lib share thirdparty 90 + sed -i \ 91 + -e 's|\$(/bin/|$(|g' \ 92 + -e 's|/usr/bin/||g' \ 93 + $out/bin/{scilab,xcos} 94 + sed -i \ 95 + -e "s|Exec=|Exec=$out/bin/|g" \ 96 + -e "s|Terminal=.*$|Terminal=true|g" \ 97 + $out/share/applications/*.desktop 107 98 108 - # Moving other share/ folders 109 - mv $out/opt/scilab-${version}/share/{appdata,locale,mime} $out/share 110 - ''; 99 + runHook postInstall 100 + ''; 111 101 }; 112 102 in 113 103 if stdenv.isDarwin then darwin else linux