From 0a3b09df75c78e66c69140a6bb75b8b5a81e9616 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Fri, 28 Oct 2022 19:57:03 +0200 Subject: [PATCH] tests: add fakedroid as flake app --- .github/workflows/fakedroid-odt.yml | 34 ++++++------------------- README.md | 39 +++++++++++++++++++++++++++++ flake.nix | 5 ++++ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/.github/workflows/fakedroid-odt.yml b/.github/workflows/fakedroid-odt.yml index 3c5522f..4a4ec90 100644 --- a/.github/workflows/fakedroid-odt.yml +++ b/.github/workflows/fakedroid-odt.yml @@ -19,28 +19,18 @@ jobs: name: nix-on-droid signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" - - name: Build fakedroid script - run: | - nix \ - --log-format bar-with-logs \ - --option keep-going true \ - --show-trace \ - build .#fakedroid \ - --impure \ - --out-link fakedroid - - name: Initialize fakedroid for channel setup - run: ./fakedroid echo INIT + run: nix run --impure .#fakedroid -- echo INIT - name: Run tests run: | - ./fakedroid mkdir -p .cache/nix-on-droid-self-test - ./fakedroid touch .cache/nix-on-droid-self-test/confirmation-granted - ./fakedroid nix-on-droid on-device-test + nix run --impure .#fakedroid -- mkdir -p .cache/nix-on-droid-self-test + nix run --impure .#fakedroid -- touch .cache/nix-on-droid-self-test/confirmation-granted + nix run --impure .#fakedroid -- nix-on-droid on-device-test - name: Push to cachix if: always() && github.event_name != 'pull_request' - run: ./fakedroid nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' + run: nix run --impure .#fakedroid -- nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' fakedroid-flakes: @@ -59,19 +49,9 @@ jobs: name: nix-on-droid signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" - - name: Build fakedroid script - run: | - nix \ - --log-format bar-with-logs \ - --option keep-going true \ - --show-trace \ - build .#fakedroid \ - --impure \ - --out-link fakedroid - - name: Initialize fakedroid for flake setup - run: USE_FLAKE=1 ./fakedroid echo INIT + run: USE_FLAKE=1 nix run --impure .#fakedroid -- echo INIT - name: Push to cachix if: always() && github.event_name != 'pull_request' - run: ./fakedroid nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' + run: nix run --impure .#fakedroid -- nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' diff --git a/README.md b/README.md index 9ebe633..4510edb 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,45 @@ Use `nix-on-droid switch --flake .#device` to build and activate your configurat Therefore, every evaluation of a flake configuration will be executed with `--impure` flag. (This behaviour will be dropped as soon as the default setup does not require it anymore.) +## Emulate `nix-on-droid`-like environment with `fakedroid` + +For easier debugging and testing, there is a so-called `fakedroid` environment which +emulates the on-device environment including proot as good as possible. + +You can enter this emulated environment with + +```sh +nix run --impure ".#fakedroid" +``` + +This will install nix-on-droid with initial channel setup and save the state of +this session in the `.fakedroid` directory in the project directory. To enter this +environment with initial flake setup, set `USE_FLAKE=1` as environment variable. +Channel and flake setups can co-exist in the `.fakedroid` state directory. To +rebuild/re-test the bootstrap process, remove the `.fakedroid` directory. + +To only run a command in fakedroid and not enter an interactive shell, just call it +with the command as arguments: + +```sh +nix run --impure ".#fakedroid" -- ls -l +``` + +## Testing + +In the [./tests/on-device](./tests/on-device) directory, there is small set +of [bats](https://github.com/bats-core/bats-core) tests that can be executed on the +android device or run in the `fakedroid` environment. + +To run the tests (on device or in fakedroid), run + +```sh +nix-on-droid on-device-test +``` + +**Note:** This currently requires a channel setup and should only be executed on +clean installations. + ## Tips * To grant the app access to the storage, use the toggle in the app settings diff --git a/flake.nix b/flake.nix index ccc30ea..311106d 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,11 @@ type = "app"; program = "${self.packages.${system}.nix-on-droid}/bin/nix-on-droid"; }; + + fakedroid = { + type = "app"; + program = toString self.packages.${system}.fakedroid; + }; }); checks = forEachSystem (system: {