├── LICENSE ├── README.md ├── builder.sh └── default.nix /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 John David Reaver 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NixOS Matlab Installation 2 | 3 | This is a way to install Matlab on a NixOS machine. Matlab is hard to install 4 | on NixOS, primarily because 5 | 6 | 1. It has opaque dependencies. 7 | 2. It ships bundled with tons of libraries, but some of these expect external 8 | libraries. 9 | 3. It expects a normal Unix file structure. 10 | 11 | This is still a **work in progress**, so please file and issue or make a pull 12 | request if something doesn't work. I will also revise this README as I learn 13 | more about the installation. 14 | 15 | # Usage 16 | 17 | 1. Enter your file installation key, matlab version, and installation file name 18 | in the default.nix file 19 | 2. Go into builder.sh and change your installed Matlab packages in the 20 | `_input_file` variable. (Note that product.MATLAB is required) 21 | 3. Put your license.lic file in your current directory. 22 | 4. Copy your installer file to the /tmp directory. (Why? nix chokes when 23 | [large files are in the source tree](https://github.com/NixOS/nix/issues/358). 24 | Therefore, we need to use fetchurl, and we need the files in a place the 25 | builder can access.) 26 | 4. Run `nix-build default.nix` 27 | 28 | # Tips 29 | 30 | ## XMonad, AwesomeWM, and maybe others 31 | 32 | If Matlab appears as just a grey window, then you need to trick matlab into 33 | thinking you are using a different window manager. Install the `wmname` program 34 | and then type `wmname LG3D`. This works for a few java programs. 35 | 36 | # TODO 37 | 38 | * Don't require a tar file (allow zip) 39 | * Make configuration simple for users. Put all needed user info at the top of 40 | default.nix with comments and skeleton values. 41 | * Test mcc, mbuild, and mex to make sure they can find gcc correctly. 42 | * Use requireFile instead of forcing the user to put their installer file in 43 | /tmp 44 | * Add builder for Matlab Compiler Runtime 45 | -------------------------------------------------------------------------------- /builder.sh: -------------------------------------------------------------------------------- 1 | source $stdenv/setup 2 | 3 | # Pre-installation tasks like unpacking, changing path names, and using 4 | # patchelf on binary files 5 | echo "Unpacking source..." 6 | tar xfa $src 7 | cd MATLAB-Linux64/* 8 | 9 | echo "Patching install files..." 10 | substituteInPlace install \ 11 | --replace /bin/pwd $(type -P pwd) 12 | substituteInPlace bin/glnxa64/install_unix \ 13 | --replace /bin/pwd $(type -P pwd) 14 | 15 | # Create the silent installer files 16 | _input_file=$(pwd)/_installer_input.txt 17 | _activation_file=$(pwd)/_activation.ini 18 | echo " 19 | destinationFolder=$out 20 | agreeToLicense=yes 21 | mode=silent 22 | fileInstallationKey=$fileInstallationKey 23 | activationPropertiesFile=$_activation_file 24 | " >> $_input_file 25 | 26 | for product in $activatedProducts; do 27 | echo product.$product >> $_input_file 28 | done 29 | 30 | echo " 31 | isSilent=True 32 | activateCommand=activateOffline 33 | licenseFile=$licenseFile 34 | installLicenseFileDir=$out/licenses 35 | installLicenseFileName=license.lic 36 | " >> $_activation_file 37 | 38 | mkdir -p $out/licenses 39 | 40 | echo "Patching java..." 41 | patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 42 | --set-rpath "$libPath:$(patchelf --print-rpath sys/java/jre/glnxa64/jre/bin/java)"\ 43 | --force-rpath "sys/java/jre/glnxa64/jre/bin/java" 44 | 45 | # Run the installer with the generated input file 46 | echo "Running installer..." 47 | export MATLAB_ARCH=glnxa64 48 | ./install -inputFile $_input_file 49 | 50 | # Run patchelf and substituteInPlace on various files in the output 51 | echo "Patching output..." 52 | 53 | REPLACE_FILES=( 54 | $out/bin/activate_matlab.sh 55 | $out/bin/matlab 56 | $out/bin/mbuild 57 | $out/bin/mcc 58 | $out/bin/mex 59 | ) 60 | 61 | for f in ${REPLACE_FILES[*]}; do 62 | substituteInPlace $f\ 63 | --replace /bin/pwd $(type -P pwd)\ 64 | --replace /bin/echo $(type -P echo) 65 | wrapProgram $f --set MATLAB_ARCH glnxa64 66 | done 67 | 68 | PATCH_FILES=( 69 | $out/bin/glnxa64/MATLAB 70 | $out/bin/glnxa64/matlab_helper 71 | $out/bin/glnxa64/mcc 72 | $out/bin/glnxa64/mbuildHelp 73 | $out/bin/glnxa64/mex 74 | $out/bin/glnxa64/need_softwareopengl 75 | $out/sys/java/jre/glnxa64/jre/bin/java 76 | ) 77 | 78 | for f in ${PATCH_FILES[*]}; do 79 | patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 80 | --set-rpath "$libPath:$(patchelf --print-rpath $f)"\ 81 | --force-rpath $f 82 | done 83 | 84 | 85 | # Set the correct path to gcc 86 | CC_FILES=( 87 | $out/bin/mbuildopts.sh 88 | $out/bin/mexopts.sh 89 | ) 90 | for f in ${CC_FILES[*]}; do 91 | substituteInPlace $f\ 92 | --replace "CC='gcc'" "CC='${gcc48}/bin/gcc'" 93 | done 94 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | with import { }; 2 | 3 | let 4 | fileInstallationKey="XXXXX-XXXXX-XXXXX-XXXXX"; 5 | version = "R2014b"; 6 | filename = "MATLAB-Linux64.tar"; 7 | activatedProducts = [ 8 | "MATLAB" 9 | "MATLAB_Compiler" 10 | ]; 11 | in 12 | 13 | stdenv.mkDerivation { 14 | name = "matlab-${version}"; 15 | builder = ./builder.sh; 16 | 17 | src = fetchurl { 18 | url = "file:///tmp/${filename}"; 19 | sha256 = "2013893803cf1f1981ec73e6f4278f2bb9271818741ed38a6f15e4e20674fc06"; 20 | }; 21 | 22 | licenseFile = ./license.lic; 23 | fileInstallationKey = fileInstallationKey; 24 | activatedProducts = activatedProducts; 25 | 26 | inherit gcc48; 27 | 28 | buildInputs = [ 29 | gcc48 30 | makeWrapper 31 | ]; 32 | 33 | libPath = stdenv.lib.makeLibraryPath [ 34 | mesa_glu 35 | ncurses 36 | xorg.libXi 37 | xorg.libXext 38 | xorg.libXmu 39 | xorg.libXp 40 | xorg.libXpm 41 | xorg.libXrandr 42 | xorg.libXrender 43 | xorg.libXt 44 | xorg.libXtst 45 | xorg.libXxf86vm 46 | xorg.libX11 47 | zlib 48 | ]; 49 | 50 | } 51 | --------------------------------------------------------------------------------