Skip to content

Commit

Permalink
Add possibility to use fakedroid from outside the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerschtli committed Jul 13, 2023
1 parent 2301e01 commit d7efa68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../.}"
''
15 changes: 6 additions & 9 deletions tests/fakedroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
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
echo "USE_FLAKE environment variable needs to be either 0 or 1, got '$USE_FLAKE'."
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"
Expand Down Expand Up @@ -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"


Expand Down

0 comments on commit d7efa68

Please sign in to comment.