dadc7eb329
Whenever we create scripts that are installed to $out, we must use runtimeShell in order to get the shell that can be executed on the machine we create the package for. This is relevant for cross-compiling. The only use case for stdenv.shell are scripts that are executed as part of the build system. Usages in checkPhase are borderline however to decrease the likelyhood of people copying the wrong examples, I decided to use runtimeShell as well.
48 lines
1.3 KiB
Nix
48 lines
1.3 KiB
Nix
{ stdenv, writeScript, buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
|
, extraPkgs ? pkgs: [], appimageTools }:
|
|
|
|
let
|
|
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
|
in buildFHSUserEnv (fhsArgs // {
|
|
name = "appimage-run";
|
|
|
|
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
|
|
|
runScript = writeScript "appimage-exec" ''
|
|
#!${runtimeShell}
|
|
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
|
|
'';
|
|
})
|