sh
set -e -C
usage="usage: pack.sh app.scm target.run"
test -z "$1" && (echo $usage; exit 1;)
test -z "$2" && (echo $usage; exit 1;)
guild compile $1 -o app/app.scm.go
cp $(guix pack -f tarball -RR guile -S /bin=bin) guile.tar.gz
chmod +w guile.tar.gz
tar czf app.tar.gz app/
cat - guile.tar.gz app.tar.gz <<'EOF'>$2
#!/bin/sh
set -e -C
offset=8
dir=$(mktemp -d)
trap 'chmod -R o+w "$dir"; rm -rf "$dir"; trap - EXIT; exit' EXIT INT HUP
tail -n +$offset $0 | tar izxf - -C $dir && cd $dir; exec ./bin/guile -c '(load-compiled "app/app.scm.go")'
# append "guix pack" archive here.
EOF
chmod +x $2