From d7efa68f7c66fe17bd3cefe2bd46337cc6285963 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Thu, 13 Jul 2023 20:24:56 +0200 Subject: [PATCH] Add possibility to use fakedroid from outside the repo --- README.md | 6 ++++++ tests/default.nix | 1 + tests/fakedroid.sh | 15 ++++++--------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f05343b..a012c98 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,12 @@ with the command as arguments: nix run --impure ".#fakedroid" -- ls -l ``` +To override the default state directory of fakedroid (`$PWD/.fakedroid`), call it with `STATE_DIR`: + +```sh +STATE_DIR=path/to/local/dir nix run --impure github:t184256/nix-on-droid#fakedroid +``` + ## Testing In the [./tests/on-device](./tests/on-device) directory, there is small set diff --git a/tests/default.nix b/tests/default.nix index bb4d4ce..b397e81 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -38,4 +38,5 @@ pkgs.runCommand --subst-var-by prootTest "${bootstrap.customPkgs.prootTermuxTest}" \ --subst-var-by installationDir "${bootstrap.config.build.installationDir}" \ --subst-var-by homeDir "${bootstrap.config.user.home}" \ + --subst-var-by flakeRootDir "${toString ../.}" '' diff --git a/tests/fakedroid.sh b/tests/fakedroid.sh index f509034..1e68c0f 100644 --- a/tests/fakedroid.sh +++ b/tests/fakedroid.sh @@ -9,6 +9,8 @@ set -ueo pipefail PATH=@path@ +FLAKE_ROOT_DIR=@flakeRootDir@ +STATE_DIR="${STATE_DIR:-"$(pwd)/.fakedroid"}" USE_FLAKE="${USE_FLAKE:-0}" if [[ ! "$USE_FLAKE" =~ ^[01]$ ]]; then @@ -16,11 +18,8 @@ if [[ ! "$USE_FLAKE" =~ ^[01]$ ]]; then exit 1 fi -# this allows to run this script from every place in this git repo -REPO_DIR="$(git rev-parse --show-toplevel)" - -INJ_DIR="$REPO_DIR/.fakedroid/inj" -ENV_DIR="$REPO_DIR/.fakedroid/env/$USE_FLAKE" +INJ_DIR="$STATE_DIR/inj" +ENV_DIR="$STATE_DIR/env/$USE_FLAKE" QEMU_URL="https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static" QEMU="$INJ_DIR/qemu-aarch64" @@ -100,10 +99,8 @@ fi rm -rf "$ENV_DIR/n-o-d" mkdir -p "$ENV_DIR/n-o-d/unpacked" -git -C "$REPO_DIR" archive --format=tar --prefix n-o-d/ HEAD \ - > "$ENV_DIR/n-o-d/archive.tar" -tar --strip-components=1 -xf \ - "$ENV_DIR/n-o-d/archive.tar" -C "$ENV_DIR/n-o-d/unpacked" +tar -cf "$ENV_DIR/n-o-d/archive.tar" --mode='u+w' -C "$FLAKE_ROOT_DIR" --transform 's,^,n-o-d/,' . +tar --strip-components=1 -xf "$ENV_DIR/n-o-d/archive.tar" -C "$ENV_DIR/n-o-d/unpacked" gzip "$ENV_DIR/n-o-d/archive.tar"