From 6ef3f8ff071a6ca843f87b430a2cc856c52313ad Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sat, 15 Jun 2024 19:32:36 +0200 Subject: [PATCH] remove fakedroid --- README.md | 32 ++------- flake.nix | 10 --- nix-on-droid/nix-on-droid.sh | 10 +-- pkgs/default.nix | 5 -- tests/default.nix | 41 ----------- tests/fakedroid.sh | 127 ----------------------------------- 6 files changed, 5 insertions(+), 220 deletions(-) delete mode 100644 tests/default.nix delete mode 100644 tests/fakedroid.sh diff --git a/README.md b/README.md index 2e4b0e1..2f3077a 100644 --- a/README.md +++ b/README.md @@ -215,44 +215,20 @@ will expand to `.#nixOnDroidConfigurations.device`). If you run `nix-on-droid sw 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. +of [bats](https://github.com/bats-core/bats-core) tests +that can be executed on a real or emulated android device. -To run the tests (on device or in fakedroid), run +To run the tests, execute ```sh nix-on-droid on-device-test ``` **Note:** This currently requires a channel setup and should only be executed on -clean installations. +clean, disposable installations. ## Tips diff --git a/flake.nix b/flake.nix index b0a2365..ce327b6 100644 --- a/flake.nix +++ b/flake.nix @@ -65,11 +65,6 @@ type = "app"; program = toString (import ./scripts/deploy.nix { inherit nixpkgs system; }); }; - - fakedroid = { - type = "app"; - program = toString self.packages.${system}.fakedroid; - }; }); checks = forEachSystem (system: { @@ -126,11 +121,6 @@ }; in { - fakedroid = import ./tests { - inherit system; - nixpkgs = nixpkgs-for-bootstrap; - }; - nix-on-droid = nixpkgs.legacyPackages.${system}.callPackage ./nix-on-droid { }; } // nixOnDroidPkgs.customPkgs diff --git a/nix-on-droid/nix-on-droid.sh b/nix-on-droid/nix-on-droid.sh index d519ab8..6b8bd2c 100644 --- a/nix-on-droid/nix-on-droid.sh +++ b/nix-on-droid/nix-on-droid.sh @@ -87,15 +87,7 @@ function doHelp() { } function doOnDeviceTest() { - # This is for maintainer convenience only, see tests/on-device/.run.sh - - # /n-o-d/unpacked is available in fakedroid environment - if [[ -d "/n-o-d/unpacked" ]]; then - export NIX_PATH="nix-on-droid=/n-o-d/unpacked:$NIX_PATH" - else - nix-channel --update nix-on-droid - fi - + nix-channel --update nix-on-droid exec "$(nix-instantiate --eval --expr \ "")" "$@" } diff --git a/pkgs/default.nix b/pkgs/default.nix index d7e7744..0f9a891 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -65,11 +65,6 @@ let bootstrapZip = callPackage ./bootstrap-zip.nix { }; prootTermux = callPackage ./cross-compiling/proot-termux.nix { }; tallocStatic = callPackage ./cross-compiling/talloc-static.nix { }; - prootTermuxTest = callPackage ./proot-termux { - inherit (pkgs) stdenv; - static = false; - outputBinaryName = "proot"; - }; }; in diff --git a/tests/default.nix b/tests/default.nix deleted file mode 100644 index bb4d4ce..0000000 --- a/tests/default.nix +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ nixpkgs, system }: - -let - bootstrap = import ../pkgs { - inherit nixpkgs system; - nixOnDroidChannelURL = "file:///n-o-d/archive.tar.gz"; - nixOnDroidFlakeURL = "/n-o-d/unpacked"; - }; - - pkgs = nixpkgs.legacyPackages.${system}; - - runtimePackages = with pkgs; [ - coreutils - git - gnutar - gzip - unzip - wget - zip - ]; -in - -pkgs.runCommand - "fakedroid" -{ - preferLocalBuild = true; - allowSubstitutes = false; -} - '' - install -D -m755 ${./fakedroid.sh} $out - - substituteInPlace $out \ - --subst-var-by bash "${pkgs.bash}" \ - --subst-var-by path "${pkgs.lib.makeBinPath runtimePackages}" \ - --subst-var-by bootstrapZip "${bootstrap.customPkgs.bootstrapZip}" \ - --subst-var-by prootTest "${bootstrap.customPkgs.prootTermuxTest}" \ - --subst-var-by installationDir "${bootstrap.config.build.installationDir}" \ - --subst-var-by homeDir "${bootstrap.config.user.home}" \ - '' diff --git a/tests/fakedroid.sh b/tests/fakedroid.sh deleted file mode 100644 index c85c328..0000000 --- a/tests/fakedroid.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!@bash@/bin/bash - -# This is a script to run "on-device" tests in CI, without the device. -# Takes the bootstrap aarch64 zipball, unpacks, proots into it. -# This won't catch all bugs, of course, but that's something. - -# Set up envvars, prepare directories: - -set -ueo pipefail - -PATH=@path@ - -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" - -QEMU_URL="https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static" -QEMU="$INJ_DIR/qemu-aarch64" - -INSTALLATION_DIR="@installationDir@" -TARGET_HOME="@homeDir@" - -mkdir -p "$INJ_DIR" -mkdir -p "$ENV_DIR/"{"$INSTALLATION_DIR","$TARGET_HOME",n-o-d} - -export PROOT_TMP_DIR="$ENV_DIR/$INSTALLATION_DIR/proot/tmp" -export PROOT_L2S_DIR="$ENV_DIR/$INSTALLATION_DIR/proot/l2s" -mkdir -p "$PROOT_TMP_DIR" "$PROOT_L2S_DIR" - -PASSTHROUGH_VARS=( - "PROOT_TMP_DIR=$PROOT_TMP_DIR" - "PROOT_L2S_DIR=$PROOT_L2S_DIR" - "TERM=$TERM" - "HOME=$TARGET_HOME" - "USER=$USER" - "USE_FLAKE=$USE_FLAKE" -) - -[[ -n "${CACHIX_SIGNING_KEY:-}" ]] && \ - PASSTHROUGH_VARS+=("CACHIX_SIGNING_KEY=$CACHIX_SIGNING_KEY") - -PROOT_ARGS=( - "-r" "$ENV_DIR" - "-q" "$QEMU" - "-w" "$TARGET_HOME" - "-b" "$ENV_DIR/$INSTALLATION_DIR/nix:/nix" - "-b" "$ENV_DIR/$INSTALLATION_DIR/bin:/bin" - "-b" "$ENV_DIR/$INSTALLATION_DIR/etc:/etc" - "-b" "$ENV_DIR/$INSTALLATION_DIR/tmp:/tmp" - "-b" "$ENV_DIR/$INSTALLATION_DIR/usr:/usr" - "-b" "/dev" - "-b" "/proc" - "-b" "/sys" -) - - -# Procure a static QEMU for user emulation and a proot with our patches: - -[[ -e "$QEMU" ]] || wget "$QEMU_URL" -O "$QEMU" -chmod +x "$QEMU" - -PROOT="@prootTest@/bin/proot" - - -# Do the first install if not installed yet: - -if [[ ! -e "$ENV_DIR/$INSTALLATION_DIR/etc" || - -e "$ENV_DIR/$INSTALLATION_DIR/etc/UNINITIALIZED" ]]; then - # Build a zipball: - ZIPBALL="@bootstrapZip@/bootstrap-aarch64.zip" - # Unpack the zipball the way the Android app does it: - pushd "$ENV_DIR/$INSTALLATION_DIR" - unzip "$ZIPBALL" - chmod -R u+rw . # unzip results in -r-xr-xr-x files and directories - while read -r e; do - SYM_TGT="${e%%←*}" - SYM_SRC="${e##*←}" - ln -sf "$SYM_TGT" "$SYM_SRC" - done < SYMLINKS.txt - while read -r e; do - chmod +x "$e" - done < EXECUTABLES.txt - rm SYMLINKS.txt EXECUTABLES.txt - popd -fi - - -# Inject Nix-on-Droid version under test into the environment. -# Uncommitted chages won't be picked up, just HEAD. -# /n-o-d/archive.tar.gz is used as a channel, /n-o-d/unpacked --- as a flake. - -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" -gzip "$ENV_DIR/n-o-d/archive.tar" - - -# The 'first boot' proot invocation: - -SH="$(readlink "$ENV_DIR/$INSTALLATION_DIR/bin/sh")" - -# 'first boot' execs interactive bash unconditionally; -# makes sense on device, requires us to work around it here though -env -i "${PASSTHROUGH_VARS[@]}" "$PROOT" "${PROOT_ARGS[@]}" \ - "$INSTALLATION_DIR/$SH" "${INSTALLATION_DIR}/usr/lib/login-inner" <<<'echo OK' - -# this is usually done by login on 'first reboot' -[[ -e "$ENV_DIR/$INSTALLATION_DIR/usr/lib/.login-inner.new" ]] && - mv "$ENV_DIR/$INSTALLATION_DIR/usr/lib/.login-inner.new" \ - "$ENV_DIR/${INSTALLATION_DIR}/usr/lib/login-inner" - - -# Actually execute something inside that fakedroid environment: - -env -i "${PASSTHROUGH_VARS[@]}" "$PROOT" "${PROOT_ARGS[@]}" \ - "$INSTALLATION_DIR/$SH" "$INSTALLATION_DIR/usr/lib/login-inner" "$@"