mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 11:36:07 +01:00
remove fakedroid
This commit is contained in:
parent
d7c432bad3
commit
6ef3f8ff07
6 changed files with 5 additions and 220 deletions
32
README.md
32
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
|
||||
|
||||
|
|
|
|||
10
flake.nix
10
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
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
"<nix-on-droid/tests/on-device/.run.sh>")" "$@"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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}" \
|
||||
''
|
||||
|
|
@ -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" "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue