Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appimageTools: clean appimage-exec.sh options #82266

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions pkgs/build-support/appimage/appimage-exec.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!@shell@
# shellcheck shell=bash

if [ -n "$DEBUG" ] ; then
set -x
fi

PATH="@path@:$PATH"
apprun_opt=true

#DEBUG=0

# src : AppImage
# dest : let's unpack() create the directory
# out : target directory, assumed to not exist yet
unpack() {
local src=$1
local out=$2
Expand Down Expand Up @@ -66,7 +65,8 @@ apprun() {
if [ ! -x "$APPDIR" ]; then
mkdir -p "$(dirname "$APPDIR")"
unpack "$APPIMAGE" "$APPDIR"
else echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
else
echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
fi

export PATH="$PATH:$PWD/usr/bin"
Expand All @@ -91,8 +91,10 @@ Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]

-h show this message
-d debug mode
-x <directory> : extract appimage in the directory then exit.
-w <directory> : run uncompressed appimage directory (used in appimageTools)
-x <APPDIR> : extract appimage in the directory then exit.

<AppImage> could be an uncompressed appimage directory (APPDIR).
This is the use case in appimageTools.

[AppImage options]: Options are passed on to the appimage.
If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable.
Expand All @@ -101,18 +103,14 @@ EOF
exit 1
}

while getopts "x:w:dh" option; do
while getopts "x:dh" option; do
case "${option}" in
d) set -x
;;
x) # eXtract
unpack_opt=true
APPDIR=${OPTARG}
;;
w) # WrapAppImage
export APPDIR=${OPTARG}
wrap_opt=true
;;
h) usage
;;
*)
Expand All @@ -122,21 +120,18 @@ while getopts "x:w:dh" option; do
done
shift $((OPTIND-1))

if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then
if [[ $unpack_opt = true ]] && [[ -f "$1" ]]; then
APPIMAGE="$1"
unpack "$APPIMAGE" "$APPDIR"
exit
elif [[ -d "$1" ]]; then
export APPDIR="$1"
shift
wrap "$@"
exit
else
elif [[ -f "$1" ]]; then
APPIMAGE="$(realpath "$1")" || usage
shift
fi

if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
unpack "$APPIMAGE" "$APPDIR"
exit
fi

if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
apprun
wrap "$@"
exit
fi
18 changes: 11 additions & 7 deletions pkgs/build-support/appimage/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
, lib, runCommand }:

rec {
appimage-exec = pkgs.substituteAll {
appimage-exec = with pkgs; substituteAll {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
appimage-exec = with pkgs; substituteAll {
appimage-exec = substituteAll {

It's best to be explicit about the dependencies and add it to the function parameters instead.

src = ./appimage-exec.sh;
isExecutable = true;
dir = "bin";
path = with pkgs; lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];
path = lib.makeBinPath [ shellcheck pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ];
#checkPhase is not enabled in substituteAll
postInstall = ''
${shellcheck}/bin/shellcheck $out/bin/appimage-exec.sh
'';
};

extract = { name, src }: runCommand "${name}-extracted" {
Expand All @@ -20,19 +24,19 @@ rec {
# for compatibility, deprecated
extractType1 = extract;
extractType2 = extract;
wrapType1 = wrapType2;
wrapType1 = wrap;
wrapType2 = wrap;

wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv (defaultFhsEnvArgs // {
wrapAppImage = args@{ name, src, extraPkgs ? pkgs: [], ... }: buildFHSUserEnv (defaultFhsEnvArgs // {
inherit name;

targetPkgs = pkgs: [ appimage-exec ]
++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs;

runScript = "appimage-exec.sh -w ${src}";
runScript = "appimage-exec.sh ${src}";
} // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage))));

wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // {
inherit name extraPkgs;
wrap = args@{ name, src, ... }: wrapAppImage (args // {
src = extract { inherit name src; };
});

Expand Down