From d70b064444ea3276f2eac13db872a052ed63b061 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sat, 24 Sep 2022 15:44:18 +0200 Subject: [PATCH] tests: refactor to support flake setup --- .github/workflows/fakedroid-odt.yml | 20 +++++++++++++++----- flake.nix | 15 +++++++++++---- pkgs/default.nix | 10 +++++++++- tests/default.nix | 26 ++++++++++++++++++++++++++ tests/fakedroid.sh | 16 +++++++--------- tests/proot-test.nix | 9 --------- 6 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 tests/default.nix mode change 100755 => 100644 tests/fakedroid.sh delete mode 100644 tests/proot-test.nix diff --git a/.github/workflows/fakedroid-odt.yml b/.github/workflows/fakedroid-odt.yml index 1e01dce..84281f1 100644 --- a/.github/workflows/fakedroid-odt.yml +++ b/.github/workflows/fakedroid-odt.yml @@ -21,15 +21,25 @@ 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 - run: tests/fakedroid.sh echo INIT + run: ./fakedroid echo INIT - name: Run tests run: | - tests/fakedroid.sh mkdir -p .cache/nix-on-droid-self-test - tests/fakedroid.sh touch .cache/nix-on-droid-self-test/confirmation-granted - tests/fakedroid.sh nix-on-droid on-device-test + ./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 - name: Push to cachix if: always() && github.event_name != 'pull_request' - run: tests/fakedroid.sh nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' + run: ./fakedroid nix-shell -p cachix --run 'nix --extra-experimental-features nix-command path-info --all | cachix push nix-on-droid' diff --git a/flake.nix b/flake.nix index 0331ebd..bdc5fb2 100644 --- a/flake.nix +++ b/flake.nix @@ -57,9 +57,16 @@ // flake-utils.lib.eachSystem [ "aarch64-linux" "i686-linux" "x86_64-darwin" "x86_64-linux" ] (system: { formatter = nixpkgs.legacyPackages.${system}.nixpkgs-fmt; - packages = import ./pkgs { - inherit system; - nixpkgs = nixpkgs-for-bootstrap; - }; + packages = + (import ./pkgs { + inherit system; + nixpkgs = nixpkgs-for-bootstrap; + }).customPkgs + // { + fakedroid = import ./tests { + inherit system; + nixpkgs = nixpkgs-for-bootstrap; + }; + }; }); } diff --git a/pkgs/default.nix b/pkgs/default.nix index 822f0b4..9a58d7b 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -51,7 +51,15 @@ 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 -customPkgs +{ + inherit (modules) config; + inherit customPkgs; +} diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..b55d66e --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,26 @@ +# 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"; + }; +in + +nixpkgs.legacyPackages.${system}.runCommand + "fakedroid" +{ + preferLocalBuild = true; + allowSubstitutes = false; +} + '' + install -D -m755 ${./fakedroid.sh} $out + + substituteInPlace $out \ + --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 old mode 100755 new mode 100644 index 41e6970..48f70a6 --- a/tests/fakedroid.sh +++ b/tests/fakedroid.sh @@ -8,15 +8,17 @@ set -ueo pipefail -REPO_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")" +# 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" QEMU_URL="https://github.com/multiarch/qemu-user-static/releases/download/v6.1.0-8/qemu-aarch64-static" QEMU="$INJ_DIR/qemu-aarch64" -INSTALLATION_DIR="/data/data/com.termux.nix/files/usr" -TARGET_HOME="/data/data/com.termux.nix/files/home" +INSTALLATION_DIR="@installationDir@" +TARGET_HOME="@homeDir@" mkdir -p "$INJ_DIR" mkdir -p "$ENV_DIR/"{"$INSTALLATION_DIR","$TARGET_HOME",n-o-d} @@ -57,7 +59,7 @@ PROOT_ARGS=( [[ -e "$QEMU" ]] || wget "$QEMU_URL" -O "$QEMU" chmod +x "$QEMU" -PROOT="$(nix-build --no-out-link tests/proot-test.nix)/bin/proot" +PROOT="@prootTest@/bin/proot" # Do the first install if not installed yet: @@ -65,11 +67,7 @@ PROOT="$(nix-build --no-out-link tests/proot-test.nix)/bin/proot" if [[ ! -e "$ENV_DIR/$INSTALLATION_DIR/etc" || -e "$ENV_DIR/$INSTALLATION_DIR/etc/UNINITIALIZED" ]]; then # Build a zipball: - nix build --show-trace -f pkgs \ - --argstr arch aarch64 \ - --argstr nixOnDroidChannelURL file:///n-o-d/archive.tar.gz \ - bootstrapZip -o "$INJ_DIR/nix-on-droid-aarch64" - ZIPBALL="$(realpath "$INJ_DIR/nix-on-droid-aarch64/bootstrap-aarch64.zip")" + ZIPBALL="@bootstrapZip@/bootstrap-aarch64.zip" # Unpack the zipball the way the Android app does it: pushd "$ENV_DIR/$INSTALLATION_DIR" unzip "$ZIPBALL" diff --git a/tests/proot-test.nix b/tests/proot-test.nix deleted file mode 100644 index d2f9438..0000000 --- a/tests/proot-test.nix +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ pkgs ? (import ../pkgs/lib/load-nixpkgs.nix { }) }: - -pkgs.callPackage ../pkgs/proot-termux { - inherit (pkgs) stdenv; - static = false; - outputBinaryName = "proot"; -}