Skip to content

Instantly share code, notes, and snippets.

@jakobrs
Created March 21, 2020 08:00
Show Gist options
  • Save jakobrs/271251298309c299d0fdb037a392f260 to your computer and use it in GitHub Desktop.
Save jakobrs/271251298309c299d0fdb037a392f260 to your computer and use it in GitHub Desktop.
#!/usr/bin/env nix-shell
#! nix-shell -p -i bash
# Usage
if [ $# -ne 1 ] || [ "$1" = "--help" ]; then
echo "Usage: $0 <path/to/appimage>" >&2
exit 1
fi
appimage=$(realpath $1)
cat >builder.sh <<'EOF'
#!/bin/sh
export PATH="$coreutils/bin:$findutils/bin:$gnused/bin:$patchelf/bin"
ld="$glibc/lib/ld-linux-x86-64.so.2"
patchelf --set-interpreter "$ld" \
--set-rpath "$glibc/lib:$zlib/lib" \
$appimage
$appimage --appimage-extract
mv squashfs-root $out
echo "IMPORTANT IMFORMATION: $glibc/lib"
cp $glibc/lib/* $out/ # Appimages expect glibc to already exist
for file in $(find $out -perm -100 -type f); do
echo "Patching file $file" >&2
patchelf --set-interpreter "$ld" "$file"
done
sed -i "1s|/bin/bash|/usr/bin/env bash|" $out/AppRun
EOF
chmod +x builder.sh
res=$(nix-build --no-out-link --expr -) <<EOF
{ glibc, zlib, coreutils, findutils, gnused, patchelf }:
derivation {
name = "appimage-inst-0.0";
system = "x86_64-linux";
builder = ./builder.sh;
appimage = $appimage;
inherit glibc zlib coreutils findutils gnused patchelf;
}
EOF
echo "$res/AppRun"
# vim: syntax=bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment