nixpkgs/pkgs/tools/package-management/appimage-run/default.nix
tilpner 58443d8a50
appimageTools: init
The appimageTools attrset contains utilities to prevent
the usage of appimage-run to package AppImages, like done/attempted
in #49370 and #53156.

This has the advantage of allowing for per-package environment changes,
and extracts into the store instead of the users home directory.

The package list was extracted into appimageTools to prevent
duplication.
2019-02-23 21:04:21 +01:00

48 lines
1.3 KiB
Nix

{ stdenv, writeScript, buildFHSUserEnv, coreutils, file, libarchive
, extraPkgs ? pkgs: [], appimageTools }:
let
fhsArgs = appimageTools.defaultFhsEnvArgs;
in buildFHSUserEnv (fhsArgs // {
name = "appimage-run";
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
runScript = writeScript "appimage-exec" ''
#!${stdenv.shell}
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"
if ${file}/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
# is type-1 appimage
mkdir "$APPDIR"
${libarchive}/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
else
# is type-2 appimage
"$APPIMAGE" --appimage-extract 2>/dev/null
fi
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
'';
})