2019-02-26 12:45:54 +01:00
|
|
|
{ stdenv, writeScript, buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
2019-01-27 14:02:50 +01:00
|
|
|
, extraPkgs ? pkgs: [], appimageTools }:
|
2018-06-09 19:10:16 +02:00
|
|
|
|
2019-01-27 14:02:50 +01:00
|
|
|
let
|
|
|
|
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
|
|
|
in buildFHSUserEnv (fhsArgs // {
|
2018-06-09 19:10:16 +02:00
|
|
|
name = "appimage-run";
|
|
|
|
|
2019-01-27 14:02:50 +01:00
|
|
|
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
2018-06-09 19:10:16 +02:00
|
|
|
|
|
|
|
runScript = writeScript "appimage-exec" ''
|
2019-02-26 12:45:54 +01:00
|
|
|
#!${runtimeShell}
|
2018-06-09 19:10:16 +02:00
|
|
|
APPIMAGE="$(realpath "$1")"
|
|
|
|
|
|
|
|
if [ ! -x "$APPIMAGE" ]; then
|
|
|
|
echo "fatal: $APPIMAGE is not executable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHA256="$(${coreutils}/bin/sha256sum "$APPIMAGE" | cut -d ' ' -f 1)"
|
|
|
|
SQUASHFS_ROOT="''${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256/"
|
|
|
|
mkdir -p "$SQUASHFS_ROOT"
|
|
|
|
|
|
|
|
export APPDIR="$SQUASHFS_ROOT/squashfs-root"
|
|
|
|
if [ ! -x "$APPDIR" ]; then
|
|
|
|
cd "$SQUASHFS_ROOT"
|
2018-09-19 18:42:13 +02:00
|
|
|
|
|
|
|
if ${file}/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
|
|
|
|
# is type-1 appimage
|
2018-10-16 13:55:31 +02:00
|
|
|
mkdir "$APPDIR"
|
|
|
|
${libarchive}/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
|
2018-09-19 18:42:13 +02:00
|
|
|
else
|
|
|
|
# is type-2 appimage
|
|
|
|
"$APPIMAGE" --appimage-extract 2>/dev/null
|
|
|
|
fi
|
2018-06-09 19:10:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$APPDIR"
|
|
|
|
export PATH="$PATH:$PWD/usr/bin"
|
|
|
|
export APPIMAGE_SILENT_INSTALL=1
|
|
|
|
|
|
|
|
if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then
|
|
|
|
exec "$APPIMAGE_DEBUG_EXEC"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec ./AppRun
|
|
|
|
'';
|
2019-01-27 14:02:50 +01:00
|
|
|
})
|