From fca8aacba7f691b8a3476b75c87bd65f84026b63 Mon Sep 17 00:00:00 2001 From: David Crompton Date: Wed, 7 Feb 2024 13:59:38 -0500 Subject: [PATCH] Matlab: System Wide MATLAB Installation --- machines/kcnhub/packages/matlab.nix | 144 ++++++++++++++++- .../kcnhub/packages/matlab/install_file.txt | 146 +++++++++--------- 2 files changed, 212 insertions(+), 78 deletions(-) diff --git a/machines/kcnhub/packages/matlab.nix b/machines/kcnhub/packages/matlab.nix index 351da39..c0bc775 100644 --- a/machines/kcnhub/packages/matlab.nix +++ b/machines/kcnhub/packages/matlab.nix @@ -1,9 +1,143 @@ -{ config, lib, pkgs, nix-matlab, ... }: { +{ config, lib, pkgs, nix-matlab, ... }: let + # The matlab installation is held in the MATLAB_INSTALL_DIR MATLAB + # updates and toolboxes can primarily be handled with the matlab_mpm + # tool defined below. This file, alongside the matlab_install.txt + # describe the current version of MATLAB available on the + # system. Nix *can* fetch MATLAB and all its toolboxes, however not + # all MATLAB toolboxes can be installed via commands, some *must* be + # installed graphically, and otherwise are unsupported. So, for now, + # we try to make installation as documented and reproducible as + # possible. + + MATLAB_INSTALL_DIR = "/opt/MATLAB"; + + # MATLAB Package Manager: MPM + # + # This tool is used to guarantee (nearly) + # reproducible installations of MATLAB, and to easily allow for + # controlling what version of MATLAB is currently installed + + matlab-mpm = pkgs.stdenv.mkDerivation rec { + pname = "matlab-package-manager"; + version = "2023.12.1"; + + src = pkgs.fetchurl { + url = "https://ssd.mathworks.com/supportfiles/downloads/mpm/${version}/glnxa64/mpm"; + hash = "sha256-NlfPLDnpRIaKLLuIZAudnFHBKL04gzmypzp98QOa6+g="; + }; + + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + ]; + + buildInputs = with pkgs; [ + gawk + gnugrep + unzip + + linux-pam + libz + ]; + + unpackPhase = "cp $src ./mpm"; + + buildPhase = '' + tail -n +$(head -n20 ./mpm | grep "tail -n" | awk '{print $3}' | grep -o -E "[0-9]+") ./mpm > ./mpm.zip + ''; + + installPhase = '' + unzip -d $out ./mpm.zip + ''; + + passthru = { + executable = "bin/glnxa64/mpm"; + }; + }; + + + # Environment with the dependencies needed to run matlab (and + # matlab's installers) + matlab-env = pkgs.buildFHSUserEnv { + name = "matlab-env"; + targetPkgs = (ps: nix-matlab.targetPkgs ps); + }; + + # Script used to get the most up to date version of the desired MATLAB + matlab-update-script = pkgs.writeScriptBin "matlab_update_installation.sh" '' + #!${pkgs.bash}/bin/bash + + if [ "''${EUID:-$(id -u)}" -ne 0 ]; then + echo "Please make sure to run this script as root" + exit -1 + fi + + if [ ! -d "${MATLAB_INSTALL_DIR}" ]; then + echo "Make sure that '${MATLAB_INSTALL_DIR}' exists" + exit -1 + fi + + cd ${MATLAB_INSTALL_DIR} + cp ${./matlab/install_file.txt} ./install_file.txt + sed -e "s#@MATLAB_INSTALL_DIR@#${MATLAB_INSTALL_DIR}#" -i ./install_file.txt + + ${matlab-env}/bin/${matlab-env.name} -c '${matlab-mpm}/${matlab-mpm.executable} install --inputfile ./install_file.txt' + ''; + + desktopItem = pkgs.makeDesktopItem { + desktopName = "Matlab"; + name = "matlab"; + # We use substituteInPlace after we run `install` + # -desktop is needed, see: + # https://www.mathworks.com/matlabcentral/answers/20-how-do-i-make-a-desktop-launcher-for-matlab-in-linux#answer_25 + exec = "@out@/bin/matlab -desktop %F"; + icon = "matlab"; + # Most of the following are copied from octave's desktop launcher + categories = [ + "Utility" + "TextEditor" + "Development" + "IDE" + ]; + mimeTypes = [ + "text/x-octave" + "text/x-matlab" + ]; + keywords = [ + "science" + "math" + "matrix" + "numerical computation" + "plotting" + ]; + }; + + # Produce acessible executables to "f", e.g. "matlab" or "mex" + matlab-run = f: pkgs.buildFHSUserEnv { + name = f; + targetPkgs = nix-matlab.targetPkgs; + # If making MATLAB available, create Application Icon etc. + extraInstallCommands = pkgs.lib.strings.optionalString (f == "matlab") '' + install -Dm644 ${desktopItem}/share/applications/matlab.desktop $out/share/applications/matlab.desktop + substituteInPlace $out/share/applications/matlab.desktop \ + --replace "@out@" ${placeholder "out"} + install -Dm644 ${nix-matlab}/icons/hicolor/256x256/matlab.png $out/share/icons/hicolor/256x256/matlab.png + install -Dm644 ${nix-matlab}/icons/hicolor/512x512/matlab.png $out/share/icons/hicolor/512x512/matlab.png + install -Dm644 ${nix-matlab}/icons/hicolor/64x64/matlab.png $out/share/icons/hicolor/64x64/matlab.png + ''; + runScript = pkgs.writeScript "matlab-run-${f}-script" '' + export QT_QPA_PLATFORM=xcb + ${MATLAB_INSTALL_DIR}/bin/${f} "$@" + ''; + }; + +in { + environment.sessionVariables = { + inherit MATLAB_INSTALL_DIR; + }; environment.systemPackages = (with nix-matlab.packages.x86_64-linux; [ - matlab - matlab-shell - matlab-mlint - matlab-mex + matlab-update-script + (matlab-run "matlab") + (matlab-run "mex") ]) ++ (with pkgs; [ octaveFull ]); diff --git a/machines/kcnhub/packages/matlab/install_file.txt b/machines/kcnhub/packages/matlab/install_file.txt index ba794d3..0018414 100644 --- a/machines/kcnhub/packages/matlab/install_file.txt +++ b/machines/kcnhub/packages/matlab/install_file.txt @@ -60,7 +60,7 @@ updateLevel=6 # This will be substited with the output path of the nix derivation: # https://nixos.org/manual/nixpkgs/stable/#fun-substitute -destinationFolder=@out@ +destinationFolder=@MATLAB_INSTALL_DIR@ ######################################################################## ## INSTALL PRODUCTS @@ -68,21 +68,21 @@ destinationFolder=@out@ ## ## Uncomment the lines for the products you want to install. -#product.5G_Toolbox -#product.AUTOSAR_Blockset +product.5G_Toolbox +product.AUTOSAR_Blockset product.Aerospace_Blockset product.Aerospace_Toolbox product.Antenna_Toolbox product.Audio_Toolbox -#product.Automated_Driving_Toolbox +product.Automated_Driving_Toolbox product.Bioinformatics_Toolbox -#product.Bluetooth_Toolbox -product.C2000_Microcontroller_Blockset -product.Communications_Toolbox -product.Computer_Vision_Toolbox -product.Control_System_Toolbox +product.Bluetooth_Toolbox +#product.C2000_Microcontroller_Blockset +#product.Communications_Toolbox +#product.Computer_Vision_Toolbox +#product.Control_System_Toolbox product.Curve_Fitting_Toolbox -#product.DDS_Blockset +product.DDS_Blockset product.DSP_HDL_Toolbox product.DSP_System_Toolbox #product.Data_Acquisition_Toolbox @@ -90,19 +90,19 @@ product.Database_Toolbox product.Datafeed_Toolbox product.Deep_Learning_HDL_Toolbox product.Deep_Learning_Toolbox -#product.Econometrics_Toolbox +product.Econometrics_Toolbox #product.Embedded_Coder -#product.Filter_Design_HDL_Coder +product.Filter_Design_HDL_Coder #product.Financial_Instruments_Toolbox -#product.Financial_Toolbox -#product.Fixed-Point_Designer -#product.Fuzzy_Logic_Toolbox +product.Financial_Toolbox +product.Fixed-Point_Designer +product.Fuzzy_Logic_Toolbox product.GPU_Coder -product.Global_Optimization_Toolbox -product.HDL_Coder -product.HDL_Verifier +#product.Global_Optimization_Toolbox +#product.HDL_Coder +#product.HDL_Verifier product.Image_Acquisition_Toolbox -product.Image_Processing_Toolbox +#product.Image_Processing_Toolbox #product.Industrial_Communication_Toolbox #product.Instrument_Control_Toolbox #product.LTE_Toolbox @@ -111,75 +111,75 @@ product.MATLAB product.MATLAB_Coder product.MATLAB_Compiler product.MATLAB_Compiler_SDK -product.MATLAB_Parallel_Server -product.MATLAB_Production_Server +#product.MATLAB_Parallel_Server +#product.MATLAB_Production_Server product.MATLAB_Report_Generator product.MATLAB_Test product.MATLAB_Web_App_Server -#product.Mapping_Toolbox +product.Mapping_Toolbox product.Medical_Imaging_Toolbox #product.Mixed-Signal_Blockset -product.Model_Predictive_Control_Toolbox -product.Model-Based_Calibration_Toolbox -product.Motor_Control_Blockset +#product.Model_Predictive_Control_Toolbox +#product.Model-Based_Calibration_Toolbox +#product.Motor_Control_Blockset product.Navigation_Toolbox product.Optimization_Toolbox product.Parallel_Computing_Toolbox product.Partial_Differential_Equation_Toolbox -#product.Phased_Array_System_Toolbox +product.Phased_Array_System_Toolbox #product.Polyspace_Bug_Finder #product.Polyspace_Bug_Finder_Server #product.Polyspace_Code_Prover #product.Polyspace_Code_Prover_Server #product.Polyspace_Test #product.Powertrain_Blockset -product.Predictive_Maintenance_Toolbox +#product.Predictive_Maintenance_Toolbox #product.RF_Blockset #product.RF_PCB_Toolbox #product.RF_Toolbox #product.ROS_Toolbox #product.Radar_Toolbox -product.Reinforcement_Learning_Toolbox -product.Requirements_Toolbox -#product.Risk_Management_Toolbox -#product.Robotics_System_Toolbox +#product.Reinforcement_Learning_Toolbox +#product.Requirements_Toolbox +product.Risk_Management_Toolbox +product.Robotics_System_Toolbox #product.Robust_Control_Toolbox #product.Satellite_Communications_Toolbox product.Sensor_Fusion_and_Tracking_Toolbox -#product.SerDes_Toolbox +product.SerDes_Toolbox product.Signal_Integrity_Toolbox -product.Signal_Processing_Toolbox +#product.Signal_Processing_Toolbox product.SimBiology product.SimEvents product.Simscape product.Simscape_Battery -product.Simscape_Driveline -product.Simscape_Electrical -product.Simscape_Fluids -product.Simscape_Multibody +#product.Simscape_Driveline +#product.Simscape_Electrical +#product.Simscape_Fluids +#product.Simscape_Multibody product.Simulink -product.Simulink_3D_Animation -product.Simulink_Check -product.Simulink_Coder +#product.Simulink_3D_Animation +#product.Simulink_Check +#product.Simulink_Coder product.Simulink_Compiler product.Simulink_Control_Design product.Simulink_Coverage product.Simulink_Design_Optimization product.Simulink_Design_Verifier -product.Simulink_Desktop_Real-Time +#product.Simulink_Desktop_Real-Time product.Simulink_Fault_Analyzer product.Simulink_PLC_Coder -product.Simulink_Real-Time +#product.Simulink_Real-Time product.Simulink_Report_Generator product.Simulink_Test product.SoC_Blockset -product.Spreadsheet_Link +#product.Spreadsheet_Link product.Stateflow product.Statistics_and_Machine_Learning_Toolbox product.Symbolic_Math_Toolbox product.System_Composer -product.System_Identification_Toolbox -#product.Text_Analytics_Toolbox +#product.System_Identification_Toolbox +product.Text_Analytics_Toolbox #product.UAV_Toolbox #product.Vehicle_Dynamics_Blockset #product.Vehicle_Network_Toolbox @@ -201,7 +201,7 @@ product.Vision_HDL_Toolbox #product.Aerospace_Blockset_Interface_for_Unreal_Engine_Projects #product.Automated_Driving_Toolbox_Importer_for_Zenrin_Japan_Map_API_3.0_(Itsumo_NAVI_API_3.0)_Service #product.Automated_Driving_Toolbox_Interface_for_Unreal_Engine_4_Projects -product.CI/CD_Automation_for_Simulink_Check +#product.CI/CD_Automation_for_Simulink_Check #product.Communications_Toolbox_Support_Package_for_Analog_Devices_ADALM-Pluto_Radio #product.Communications_Toolbox_Support_Package_for_RTL-SDR_Radio #product.Communications_Toolbox_Support_Package_for_USRP_Embedded_Series_Radio @@ -209,9 +209,9 @@ product.CI/CD_Automation_for_Simulink_Check #product.Communications_Toolbox_Support_Package_for_Xilinx_Zynq-Based_Radio #product.Communications_Toolbox_Wireless_Network_Simulation_Library #product.Component_Deployment_Guideline_for_Embedded_Coder -product.Computer_Vision_Toolbox_Automated_Visual_Inspection_Library -product.Computer_Vision_Toolbox_Interface_for_OpenCV_in_MATLAB -product.Computer_Vision_Toolbox_Interface_for_OpenCV_in_Simulink +#product.Computer_Vision_Toolbox_Automated_Visual_Inspection_Library +#product.Computer_Vision_Toolbox_Interface_for_OpenCV_in_MATLAB +#product.Computer_Vision_Toolbox_Interface_for_OpenCV_in_Simulink #product.Computer_Vision_Toolbox_Model_for_Inflated-3D_Video_Classification #product.Computer_Vision_Toolbox_Model_for_Mask_R-CNN_Instance_Segmentation #product.Computer_Vision_Toolbox_Model_for_Object_Keypoint_Detection @@ -230,14 +230,14 @@ product.Computer_Vision_Toolbox_Interface_for_OpenCV_in_Simulink #product.Data_Acquisition_Toolbox_Support_Package_for_National_Instruments_NI-DAQmx_Devices #product.Data_Acquisition_Toolbox_Support_Package_for_Windows_Sound_Cards #product.Database_Toolbox_Interface_for_Neo4j_Bolt_Protocol -product.Deep_Learning_HDL_Toolbox_Support_Package_for_Intel_FPGA_and_SoC_Devices -product.Deep_Learning_HDL_Toolbox_Support_Package_for_Xilinx_FPGA_and_SoC_Devices +#product.Deep_Learning_HDL_Toolbox_Support_Package_for_Intel_FPGA_and_SoC_Devices +#product.Deep_Learning_HDL_Toolbox_Support_Package_for_Xilinx_FPGA_and_SoC_Devices #product.Deep_Learning_Toolbox_Converter_for_ONNX_Model_Format -product.Deep_Learning_Toolbox_Converter_for_PyTorch_Model_Format -product.Deep_Learning_Toolbox_Converter_for_TensorFlow_models +#product.Deep_Learning_Toolbox_Converter_for_PyTorch_Model_Format +#product.Deep_Learning_Toolbox_Converter_for_TensorFlow_models #product.Deep_Learning_Toolbox_Importer_for_Caffe_Models -product.Deep_Learning_Toolbox_Interface_for_TensorFlow_Lite -product.Deep_Learning_Toolbox_Model_Quantization_Library +#product.Deep_Learning_Toolbox_Interface_for_TensorFlow_Lite +#product.Deep_Learning_Toolbox_Model_Quantization_Library #product.Deep_Learning_Toolbox_Model_for_AlexNet_Network #product.Deep_Learning_Toolbox_Model_for_DarkNet-19_Network #product.Deep_Learning_Toolbox_Model_for_DarkNet-53_Network @@ -259,30 +259,30 @@ product.Deep_Learning_Toolbox_Model_Quantization_Library #product.Deep_Learning_Toolbox_Model_for_Xception_Network #product.Deep_Learning_Toolbox_Verification_Library #product.Embedded_Coder_Interface_to_QEMU_Emulator -product.Embedded_Coder_Support_Package_For_Linux_Applications +#product.Embedded_Coder_Support_Package_For_Linux_Applications #product.Embedded_Coder_Support_Package_for_ARM_Cortex-A_Processors #product.Embedded_Coder_Support_Package_for_ARM_Cortex-M_Processors #product.Embedded_Coder_Support_Package_for_ARM_Cortex-R_Processors -product.Embedded_Coder_Support_Package_for_BeagleBone_Black_Hardware +#product.Embedded_Coder_Support_Package_for_BeagleBone_Black_Hardware #product.Embedded_Coder_Support_Package_for_Infineon_AURIX_TC4x_Microcontrollers -product.Embedded_Coder_Support_Package_for_Intel_SoC_Devices -product.Embedded_Coder_Support_Package_for_STMicroelectronics_STM32_Processors -product.Embedded_Coder_Support_Package_for_Xilinx_Zynq_Platform +#product.Embedded_Coder_Support_Package_for_Intel_SoC_Devices +#product.Embedded_Coder_Support_Package_for_STMicroelectronics_STM32_Processors +#product.Embedded_Coder_Support_Package_for_Xilinx_Zynq_Platform #product.Ephemeris_Data_for_Aerospace_Toolbox #product.Extended_Tire_Features_for_Vehicle_Dynamics_Blockset #product.FMU_Builder_For_Simulink -product.GPU_Coder_Interface_for_Deep_Learning_Libraries -product.GUIDE_to_App_Designer_Migration_Tool_for_MATLAB +#product.GPU_Coder_Interface_for_Deep_Learning_Libraries +#product.GUIDE_to_App_Designer_Migration_Tool_for_MATLAB #product.Geoid_Data_for_Aerospace_Toolbox -product.HDL_Coder_Support_Package_for_Intel_FPGA_Boards -product.HDL_Coder_Support_Package_for_Intel_SoC_Devices -product.HDL_Coder_Support_Package_for_Microchip_FPGA_and_SoC_Devices -product.HDL_Coder_Support_Package_for_Xilinx_FPGA_Boards -product.HDL_Coder_Support_Package_for_Xilinx_RFSoC_Devices -product.HDL_Coder_Support_Package_for_Xilinx_Zynq_Platform -product.HDL_Verifier_Support_Package_for_Intel_FPGA_Boards -product.HDL_Verifier_Support_Package_for_Microsemi_FPGA_Boards -product.HDL_Verifier_Support_Package_for_Xilinx_FPGA_Boards +#product.HDL_Coder_Support_Package_for_Intel_FPGA_Boards +#product.HDL_Coder_Support_Package_for_Intel_SoC_Devices +#product.HDL_Coder_Support_Package_for_Microchip_FPGA_and_SoC_Devices +#product.HDL_Coder_Support_Package_for_Xilinx_FPGA_Boards +#product.HDL_Coder_Support_Package_for_Xilinx_RFSoC_Devices +#product.HDL_Coder_Support_Package_for_Xilinx_Zynq_Platform +#product.HDL_Verifier_Support_Package_for_Intel_FPGA_Boards +#product.HDL_Verifier_Support_Package_for_Microsemi_FPGA_Boards +#product.HDL_Verifier_Support_Package_for_Xilinx_FPGA_Boards #product.Image_Acquisition_Toolbox_Support_Package_for_DCAM_Hardware #product.Image_Acquisition_Toolbox_Support_Package_for_Kinect_for_Windows_Sensor #product.Image_Acquisition_Toolbox_Support_Package_for_Matrox_Hardware @@ -311,9 +311,9 @@ product.HDL_Verifier_Support_Package_for_Xilinx_FPGA_Boards #product.MATLAB_Basemap_Data_-_grayland #product.MATLAB_Basemap_Data_-_grayterrain #product.MATLAB_Basemap_Data_-_landcover -product.MATLAB_Client_for_MATLAB_Production_Server +#product.MATLAB_Client_for_MATLAB_Production_Server #product.MATLAB_Coder_Interface_for_Deep_Learning_Libraries -product.MATLAB_Coder_Interface_for_Visual_Studio_Code_Debugging +#product.MATLAB_Coder_Interface_for_Visual_Studio_Code_Debugging #product.MATLAB_Coder_Support_Package_for_NVIDIA_Jetson_and_NVIDIA_DRIVE_Platforms #product.MATLAB_Support_Package_for_Android_Sensors #product.MATLAB_Support_Package_for_Apple_iOS_Sensors