nix-matlab/flake.nix

107 lines
3.7 KiB
Nix
Raw Normal View History

2021-05-14 14:15:05 +00:00
{
description = "Nix files made to ease imperative installation of matlab";
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
outputs = { self, nixpkgs, flake-compat }:
let
# We don't use flake-utils.lib.eachDefaultSystem since only x86_64-linux is
# supported
pkgs = nixpkgs.legacyPackages.x86_64-linux;
targetPkgs = import ./common.nix;
runScriptPrefix = ''
2021-05-15 06:16:13 +00:00
# Needed for simulink even on wayland systems
2021-05-14 14:15:05 +00:00
export QT_QPA_PLATFORM=xcb
# Search for an imperative declaration of the installation directory of matlab
if [[ -f ~/.config/matlab/nix.sh ]]; then
source ~/.config/matlab/nix.sh
else
echo "nix-matlab-error: Did not find ~/.config/matlab/nix.sh" >&2
exit 1
fi
if [[ ! -d "$INSTALL_DIR" ]]; then
echo "nix-matlab-error: INSTALL_DIR $INSTALL_DIR isn't a directory" >&2
exit 2
fi
2021-05-14 14:15:05 +00:00
'';
2021-05-15 08:30:34 +00:00
desktopItem = pkgs.makeDesktopItem {
desktopName = "Matlab";
name = "matlab";
2021-05-15 08:52:09 +00:00
# We use substituteInPlace after we run `install`
exec = "@out@/bin/matlab %F";
2021-05-15 08:30:34 +00:00
icon = "matlab";
# Most of the following are copied from octave's desktop launcher
categories = "Utility;TextEditor;Development;IDE;";
mimeType = "text/x-octave;text/x-matlab;";
extraEntries = ''
Keywords=science;math;matrix;numerical computation;plotting;
'';
};
2021-05-14 14:15:05 +00:00
in {
packages.x86_64-linux.matlab = pkgs.buildFHSUserEnv {
name = "matlab";
inherit targetPkgs;
2021-05-15 08:30:34 +00:00
extraInstallCommands = ''
install -Dm644 ${desktopItem}/share/applications/matlab.desktop $out/share/applications/matlab.desktop
2021-05-15 08:52:09 +00:00
substituteInPlace $out/share/applications/matlab.desktop \
--replace "@out@" ${placeholder "out"}
2021-05-15 08:30:34 +00:00
install -Dm644 ${./icons/hicolor/256x256/matlab.png} $out/share/icons/hicolor/256x256/matlab.png
install -Dm644 ${./icons/hicolor/512x512/matlab.png} $out/share/icons/hicolor/512x512/matlab.png
install -Dm644 ${./icons/hicolor/64x64/matlab.png} $out/share/icons/hicolor/64x64/matlab.png
'';
2021-05-14 14:15:05 +00:00
runScript = runScriptPrefix + ''
exec $INSTALL_DIR/bin/matlab "$@"
2021-05-14 14:15:05 +00:00
'';
};
packages.x86_64-linux.matlab-shell = pkgs.buildFHSUserEnv {
name = "matlab-shell";
inherit targetPkgs;
runScript = ''
# needed for simulink in fact, but doesn't harm here as well.
export QT_QPA_PLATFORM=xcb
cat <<EOF
============================
welcome to nix-matlab shell!
To install matlab:
${nixpkgs.lib.strings.escape ["`" "'" "\"" "$"] (builtins.readFile ./install.adoc)}
4. Finish the installation, and exit the shell (with `exit`).
5. Continue on with the instructions for making the matlab executable available
anywhere on your system.
============================
EOF
exec bash
'';
2021-05-14 14:15:05 +00:00
};
2021-05-15 08:30:34 +00:00
packages.x86_64-linux.matlab-mlint = pkgs.buildFHSUserEnv {
2021-05-14 14:15:05 +00:00
name = "mlint";
inherit targetPkgs;
runScript = runScriptPrefix + ''
exec $INSTALL_DIR/bin/glnxa64/mlint "$@"
2021-05-14 14:15:05 +00:00
'';
};
overlay = final: prev: {
2021-05-15 08:30:34 +00:00
inherit (self.packages.x86_64-linux) matlab matlab-shell matlab-mlint;
2021-05-14 14:15:05 +00:00
};
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = (targetPkgs pkgs) ++ [
self.packages.x86_64-linux.matlab-shell
];
# From some reason using the attribute matlab-shell directly as the
# devShell doesn't make it run like that by default.
shellHook = ''
exec matlab-shell
'';
2021-05-14 14:15:05 +00:00
};
defaultPackage.x86_64-linux = self.packages.x86_64-linux.matlab;
};
}