tests: refactor to support flake setup

This commit is contained in:
Tobias Happ 2022-09-24 15:44:18 +02:00
parent 004faf1835
commit 5d9e3c3dd1
6 changed files with 68 additions and 28 deletions

26
tests/default.nix Normal file
View file

@ -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}" \
''

16
tests/fakedroid.sh Executable file → Normal file
View file

@ -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"

View file

@ -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";
}