148
flake.nix
148
flake.nix
@@ -33,82 +33,84 @@
|
||||
});
|
||||
in
|
||||
{
|
||||
bundlers.proot-bundler =
|
||||
drv:
|
||||
let
|
||||
ci = pkgs.closureInfo {
|
||||
rootPaths = [
|
||||
drv
|
||||
prootPatched
|
||||
bundlers = rec {
|
||||
proot-bundler =
|
||||
drv:
|
||||
let
|
||||
ci = pkgs.closureInfo {
|
||||
rootPaths = [
|
||||
drv
|
||||
prootPatched
|
||||
];
|
||||
};
|
||||
# resolve these now so we can hardcode into the runner
|
||||
appBinGuess = "${drv}/bin";
|
||||
prootBin = "${prootPatched}/bin/proot";
|
||||
PROOT_REL = "/nix/store/${builtins.baseNameOf (builtins.dirOf prootBin)}/bin/proot";
|
||||
in
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "myApp.run";
|
||||
nativeBuildInputs = [
|
||||
pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnutar
|
||||
pkgs.gzip
|
||||
];
|
||||
buildCommand = ''
|
||||
set -euo pipefail
|
||||
PAY="$PWD/payload"
|
||||
mkdir -p "$PAY/nix/store"
|
||||
|
||||
# copy closure paths from closureInfo (no nix calls here)
|
||||
while IFS= read -r p; do
|
||||
cp -a --no-preserve=ownership "$p" "$PAY/nix/store/"
|
||||
done < ${ci}/store-paths
|
||||
|
||||
# pick an app binary
|
||||
APP_BIN=$(find ${appBinGuess} -maxdepth 1 -type f -perm -111 | head -n1)
|
||||
if [ -z "''${APP_BIN:-}" ]; then
|
||||
echo "no executable found in ${appBinGuess}" >&2
|
||||
exit 1
|
||||
fi
|
||||
APP_REL="/nix/store/$(basename "$(dirname "$APP_BIN")")/$(basename "$APP_BIN")"
|
||||
|
||||
( cd "$PAY" && tar -czf "$PWD/payload.tar.gz" . )
|
||||
|
||||
cat > $out <<'SH'
|
||||
#!/bin/sh
|
||||
set -euf
|
||||
: "''${TMPDIR:=/tmp}"
|
||||
EXTRACT_DIR="$(mktemp -d "''${TMPDIR%/}/nxbdl.XXXXXX")"
|
||||
cleanup() { [ -n "''${KEEP_BUNDLE:-}" ] || rm -rf "$EXTRACT_DIR"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
ARCHIVE_LINE=$(awk '/^__ARCHIVE_BELOW__/ {print NR+1; exit 0}' "$0")
|
||||
tail -n +"$ARCHIVE_LINE" "$0" | tar -xzf - -C "$EXTRACT_DIR"
|
||||
|
||||
cd "$EXTRACT_DIR"
|
||||
APP_REL='__APP_REL__'
|
||||
PROOT_REL='__PROOT_REL__'
|
||||
|
||||
BUNDLE_PWD="''${BUNDLE_PWD:-$PWD}"
|
||||
exec ".${PROOT_REL}" \
|
||||
-b ./nix:nix \
|
||||
-R / \
|
||||
-w "$BUNDLE_PWD" \
|
||||
".$APP_REL" "$@"
|
||||
|
||||
__ARCHIVE_BELOW__
|
||||
SH
|
||||
sed -i \
|
||||
-e "s|__APP_REL__|$APP_REL|g" \
|
||||
-e "s|__PROOT_REL__|${PROOT_REL}|g" \
|
||||
$out
|
||||
chmod +x $out
|
||||
cat payload.tar.gz >> $out
|
||||
'';
|
||||
};
|
||||
# resolve these now so we can hardcode into the runner
|
||||
appBinGuess = "${drv}/bin";
|
||||
prootBin = "${prootPatched}/bin/proot";
|
||||
PROOT_REL = "/nix/store/${builtins.baseNameOf (builtins.dirOf prootBin)}/bin/proot";
|
||||
in
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "myApp.run";
|
||||
nativeBuildInputs = [
|
||||
pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnutar
|
||||
pkgs.gzip
|
||||
];
|
||||
buildCommand = ''
|
||||
set -euo pipefail
|
||||
PAY="$PWD/payload"
|
||||
mkdir -p "$PAY/nix/store"
|
||||
|
||||
# copy closure paths from closureInfo (no nix calls here)
|
||||
while IFS= read -r p; do
|
||||
cp -a --no-preserve=ownership "$p" "$PAY/nix/store/"
|
||||
done < ${ci}/store-paths
|
||||
|
||||
# pick an app binary
|
||||
APP_BIN=$(find ${appBinGuess} -maxdepth 1 -type f -perm -111 | head -n1)
|
||||
if [ -z "''${APP_BIN:-}" ]; then
|
||||
echo "no executable found in ${appBinGuess}" >&2
|
||||
exit 1
|
||||
fi
|
||||
APP_REL="/nix/store/$(basename "$(dirname "$APP_BIN")")/$(basename "$APP_BIN")"
|
||||
|
||||
( cd "$PAY" && tar -czf "$PWD/payload.tar.gz" . )
|
||||
|
||||
cat > $out <<'SH'
|
||||
#!/bin/sh
|
||||
set -euf
|
||||
: "''${TMPDIR:=/tmp}"
|
||||
EXTRACT_DIR="$(mktemp -d "''${TMPDIR%/}/nxbdl.XXXXXX")"
|
||||
cleanup() { [ -n "''${KEEP_BUNDLE:-}" ] || rm -rf "$EXTRACT_DIR"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
ARCHIVE_LINE=$(awk '/^__ARCHIVE_BELOW__/ {print NR+1; exit 0}' "$0")
|
||||
tail -n +"$ARCHIVE_LINE" "$0" | tar -xzf - -C "$EXTRACT_DIR"
|
||||
|
||||
cd "$EXTRACT_DIR"
|
||||
APP_REL='__APP_REL__'
|
||||
PROOT_REL='__PROOT_REL__'
|
||||
|
||||
BUNDLE_PWD="''${BUNDLE_PWD:-$PWD}"
|
||||
exec ".${PROOT_REL}" \
|
||||
-b ./nix:nix \
|
||||
-R / \
|
||||
-w "$BUNDLE_PWD" \
|
||||
".$APP_REL" "$@"
|
||||
|
||||
__ARCHIVE_BELOW__
|
||||
SH
|
||||
sed -i \
|
||||
-e "s|__APP_REL__|$APP_REL|g" \
|
||||
-e "s|__PROOT_REL__|${PROOT_REL}|g" \
|
||||
$out
|
||||
chmod +x $out
|
||||
cat payload.tar.gz >> $out
|
||||
'';
|
||||
};
|
||||
|
||||
default = self.bundlers.${system}.proot-bundler;
|
||||
default = proot-bundler;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user