aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/appimage
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-12-21 06:05:12 +0100
committerMx Kookie <kookie@spacekookie.de>2020-12-21 06:05:12 +0100
commitf107be784e6d5da5f90735765a68fdff96acfbb4 (patch)
tree145573a598009fb6adbd5ef7fbce0a850681f5f0 /infra/libkookie/nixpkgs/pkgs/build-support/appimage
parent2e04b35e5ac3a9123cafffbc84494fa4d389cca0 (diff)
parente9158eca70ae59e73fae23be5d13d3fa0cfc78b4 (diff)
Add 'infra/libkookie/nixpkgs/' from commit 'e9158eca70ae59e73fae23be5d13d3fa0cfc78b4'
git-subtree-dir: infra/libkookie/nixpkgs git-subtree-mainline: 2e04b35e5ac3a9123cafffbc84494fa4d389cca0 git-subtree-split: e9158eca70ae59e73fae23be5d13d3fa0cfc78b4
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/build-support/appimage')
-rwxr-xr-xinfra/libkookie/nixpkgs/pkgs/build-support/appimage/appimage-exec.sh142
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/appimage/default.nix190
2 files changed, 332 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/appimage/appimage-exec.sh b/infra/libkookie/nixpkgs/pkgs/build-support/appimage/appimage-exec.sh
new file mode 100755
index 000000000000..7986c589667b
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/appimage/appimage-exec.sh
@@ -0,0 +1,142 @@
+#!@shell@
+# shellcheck shell=bash
+
+if [ -n "$DEBUG" ] ; then
+ set -x
+fi
+
+PATH="@path@:$PATH"
+apprun_opt=true
+
+# src : AppImage
+# dest : let's unpack() create the directory
+unpack() {
+ local src="$1"
+ local out="$2"
+
+ # https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
+ local appimageSignature;
+ appimageSignature="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $10$11;}')"
+ local appimageType;
+ appimageType="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $12;}')"
+
+ # check AppImage signature
+ if [ "$appimageSignature" != "4149" ]; then
+ echo "Not an AppImage file"
+ exit
+ fi
+
+ case "$appimageType" in
+ "01")
+ echo "Uncompress $(basename "$src") of type $appimageType"
+ mkdir "$out"
+ pv "$src" | bsdtar -x -C "$out" -f -
+ ;;
+
+ "02")
+ # This method avoid issues with non executable appimages,
+ # non-native packer, packer patching and squashfs-root destination prefix.
+
+ # multiarch offset one-liner using same method as AppImage
+ # see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
+ offset=$(LC_ALL=C readelf -h "$src" | awk 'NR==13{e_shoff=$5} NR==18{e_shentsize=$5} NR==19{e_shnum=$5} END{print e_shoff+e_shentsize*e_shnum}')
+ echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset"
+ unsquashfs -q -d "$out" -o "$offset" "$src"
+ chmod go-w "$out"
+ ;;
+
+ # "03")
+ # get ready, https://github.com/TheAssassin/type3-runtime
+
+ *)
+ echo Unsupported AppImage Type: "$appimageType"
+ exit
+ ;;
+ esac
+ echo "$(basename "$src") is now installed in $out"
+}
+
+apprun() {
+
+ SHA256=$(sha256sum "$APPIMAGE" | awk '{print $1}')
+ export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256"
+
+ #compatibility
+ if [ -x "$APPDIR/squashfs-root" ]; then APPDIR="$APPDIR/squashfs-root"; fi
+
+ if [ ! -x "$APPDIR" ]; then
+ mkdir -p "$(dirname "$APPDIR")"
+ unpack "$APPIMAGE" "$APPDIR"
+ else echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
+ fi
+
+ export PATH="$PATH:$PWD/usr/bin"
+}
+
+wrap() {
+
+ cd "$APPDIR" || exit
+ # quite same in appimageTools
+ export APPIMAGE_SILENT_INSTALL=1
+
+ if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then
+ exec "$APPIMAGE_DEBUG_EXEC"
+ fi
+
+ exec ./AppRun "$@"
+}
+
+usage() {
+ cat <<EOF
+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)
+
+[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.
+
+EOF
+ exit 1
+}
+
+while getopts "x:w: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
+ ;;
+ *) usage
+ ;;
+ esac
+done
+shift "$((OPTIND-1))"
+
+if [ -n "$wrap_opt" ] && [ -d "$APPDIR" ]; then
+ wrap "$@"
+ exit
+else
+ APPIMAGE="$(realpath "$1")" || usage
+ shift
+fi
+
+if [ -n "$unpack_opt" ] && [ -f "$APPIMAGE" ]; then
+ unpack "$APPIMAGE" "$APPDIR"
+ exit
+fi
+
+if [ -n "$apprun_opt" ] && [ -f "$APPIMAGE" ]; then
+ apprun
+ wrap "$@"
+ exit
+fi
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/appimage/default.nix b/infra/libkookie/nixpkgs/pkgs/build-support/appimage/default.nix
new file mode 100644
index 000000000000..e6014e35aef9
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/appimage/default.nix
@@ -0,0 +1,190 @@
+{ stdenv
+, bash
+, binutils-unwrapped
+, coreutils
+, gawk
+, libarchive
+, pv
+, squashfsTools
+, buildFHSUserEnv
+, pkgs
+}:
+
+rec {
+ appimage-exec = pkgs.substituteAll {
+ src = ./appimage-exec.sh;
+ isExecutable = true;
+ dir = "bin";
+ path = with pkgs; stdenv.lib.makeBinPath [
+ bash
+ binutils-unwrapped
+ coreutils
+ gawk
+ libarchive
+ pv
+ squashfsTools
+ ];
+ };
+
+ extract = { name, src }: pkgs.runCommand "${name}-extracted" {
+ buildInputs = [ appimage-exec ];
+ } ''
+ appimage-exec.sh -x $out ${src}
+ '';
+
+ # for compatibility, deprecated
+ extractType1 = extract;
+ extractType2 = extract;
+ wrapType1 = wrapType2;
+
+ wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv
+ (defaultFhsEnvArgs // {
+ inherit name;
+
+ targetPkgs = pkgs: [ appimage-exec ]
+ ++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs;
+
+ runScript = "appimage-exec.sh -w ${src}";
+ } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage))));
+
+ wrapType2 = args@{ name, src, extraPkgs ? pkgs: [ ], ... }: wrapAppImage
+ (args // {
+ inherit name extraPkgs;
+ src = extract { inherit name src; };
+ });
+
+ defaultFhsEnvArgs = {
+ name = "appimage-env";
+
+ # Most of the packages were taken from the Steam chroot
+ targetPkgs = pkgs: with pkgs; [
+ gtk3
+ bashInteractive
+ gnome3.zenity
+ python2
+ xorg.xrandr
+ which
+ perl
+ xdg_utils
+ iana-etc
+ krb5
+ ];
+
+ # list of libraries expected in an appimage environment:
+ # https://github.com/AppImage/pkg2appimage/blob/master/excludelist
+ multiPkgs = pkgs: with pkgs; [
+ desktop-file-utils
+ xorg.libXcomposite
+ xorg.libXtst
+ xorg.libXrandr
+ xorg.libXext
+ xorg.libX11
+ xorg.libXfixes
+ libGL
+
+ gst_all_1.gstreamer
+ gst_all_1.gst-plugins-ugly
+ gst_all_1.gst-plugins-base
+ libdrm
+ xorg.xkeyboardconfig
+ xorg.libpciaccess
+
+ glib
+ gtk2
+ bzip2
+ zlib
+ gdk-pixbuf
+
+ xorg.libXinerama
+ xorg.libXdamage
+ xorg.libXcursor
+ xorg.libXrender
+ xorg.libXScrnSaver
+ xorg.libXxf86vm
+ xorg.libXi
+ xorg.libSM
+ xorg.libICE
+ gnome2.GConf
+ freetype
+ (curl.override { gnutlsSupport = true; sslSupport = false; })
+ nspr
+ nss
+ fontconfig
+ cairo
+ pango
+ expat
+ dbus
+ cups
+ libcap
+ SDL2
+ libusb1
+ udev
+ dbus-glib
+ libav
+ atk
+ at-spi2-atk
+ libudev0-shim
+ networkmanager098
+
+ xorg.libXt
+ xorg.libXmu
+ xorg.libxcb
+ xorg.xcbutil
+ xorg.xcbutilwm
+ xorg.xcbutilimage
+ xorg.xcbutilkeysyms
+ xorg.xcbutilrenderutil
+ libGLU
+ libuuid
+ libogg
+ libvorbis
+ SDL
+ SDL2_image
+ glew110
+ openssl
+ libidn
+ tbb
+ wayland
+ mesa
+ libxkbcommon
+
+ flac
+ freeglut
+ libjpeg
+ libpng12
+ libsamplerate
+ libmikmod
+ libtheora
+ libtiff
+ pixman
+ speex
+ SDL_image
+ SDL_ttf
+ SDL_mixer
+ SDL2_ttf
+ SDL2_mixer
+ libappindicator-gtk2
+ libcaca
+ libcanberra
+ libgcrypt
+ libvpx
+ librsvg
+ xorg.libXft
+ libvdpau
+ alsaLib
+
+ harfbuzz
+ e2fsprogs
+ libgpgerror
+ keyutils.lib
+ libjack2
+ fribidi
+ p11-kit
+
+ # libraries not on the upstream include list, but nevertheless expected
+ # by at least one appimage
+ libtool.lib # for Synfigstudio
+ at-spi2-core
+ ];
+ };
+}