Skip to content

Commit 6f38e94

Browse files
author
Shelvacu
committed
Grab proot from bootstrap zip rather than including its nix path directly.
This means that the cachix substituter (or already having the package in your nix store somehow) is no longer required to build. This required reworking the deploy script. As a bonus you can now omit the second argument and it will tell you what it would have copied instead of copying anything. This is fixes one source of impurity, but for now flake builds will still require the --impure flag
1 parent 248cc08 commit 6f38e94

File tree

8 files changed

+92
-28
lines changed

8 files changed

+92
-28
lines changed

modules/environment/login/default.nix

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ in
3737

3838
prootStatic = mkOption {
3939
type = types.package;
40-
readOnly = true;
40+
# not readOnly, this needs to be overridden when building bootstrap zip
4141
internal = true;
4242
description = "<literal>proot-static</literal> package.";
4343
};
@@ -84,14 +84,25 @@ in
8484
environment.files = {
8585
inherit login loginInner;
8686

87-
prootStatic =
88-
let
89-
crossCompiledPaths = {
90-
aarch64-linux = "/nix/store/7qd99m1w65x2vgqg453nd70y60sm3kay-proot-termux-static-aarch64-unknown-linux-android-unstable-2024-05-04";
91-
x86_64-linux = "/nix/store/pakj3svvw84rhkzdc6211yhc2cgvc21f-proot-termux-static-x86_64-unknown-linux-android-unstable-2024-05-04";
92-
};
93-
in
94-
"${crossCompiledPaths.${targetSystem}}";
87+
# Ideally this would build the static proot binary, but doing that on aarch64 is HARD so instead pull it from the bootstrap tarball
88+
prootStatic = let
89+
attrs = (import ./proot-attrs).${targetSystem};
90+
prootFile = pkgs.fetchurl {
91+
name = "proot-static-file";
92+
inherit (attrs) url hash;
93+
94+
downloadToTemp = true;
95+
executable = true;
96+
postFetch = ''
97+
${pkgs.unzip}/bin/unzip -u $downloadedFile bin/proot-static
98+
echo $PWD >&2
99+
mv bin/proot-static $out
100+
'';
101+
};
102+
in pkgs.runCommand "proot-static" {} ''
103+
mkdir -p $out/bin
104+
cp ${prootFile} $out/bin/proot-static
105+
'';
95106
};
96107

97108
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# WARNING: This file is autogenerated by the deploy script. Any changes will be overridden
2+
{
3+
url = "file:///data/local/tmp/n-o-d/bootstrap-aarch64.zip";
4+
hash = "sha256-fZyqldmHWbv2e6543mwb5UPcKxcODRg+PDvZNcjVyUU=";
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
x86_64-linux = import ./x86_64.nix;
3+
aarch64-linux = import ./aarch64.nix;
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# WARNING: This file is autogenerated by the deploy script. Any changes will be overridden
2+
{
3+
url = "file:///data/local/tmp/n-o-d/bootstrap-x86_64.zip";
4+
hash = "sha256-1WZBmFNEmZucOwuzDAFO+Sl+b2XO7Lp1aQr/4egl4wU=";
5+
}

pkgs/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ let
4242
# Fix invoking bash after initial build.
4343
user.shell = "${initialPackageInfo.bash}/bin/bash";
4444

45+
environment.files.prootStatic = pkgs.lib.mkForce customPkgs.prootTermux;
46+
4547
build = {
4648
channel = {
4749
nixpkgs = urlOptionValue nixpkgsChannelURL "NIXPKGS_CHANNEL_URL";

scripts/deploy.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let
77

88
runtimePackages = with pkgs; [
99
coreutils
10+
diffutils
1011
git
1112
gnugrep
1213
gnused

scripts/deploy.sh

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ set -euo pipefail
33

44
PATH=@path@
55

6-
if [[ $# -ne 2 ]]; then
6+
if [[ $# -ne 2 ]] && [[ $# -ne 1 ]]; then
77
cat >&2 <<EOF
88
9-
USAGE: nix run .#deploy -- <public_url> <rsync_target>
9+
USAGE: nix run .#deploy -- <public_url> [rsync_target]
1010
1111
Builds bootstrap zip ball and source code tar ball (for usage as a channel or
12-
flake) and uploads it to the directory specified in <rsync_target>. The
13-
contents of this directory should be reachable by the android device with
14-
<public_url>.
12+
flake). If rsync_target is specified, uploads it to the directory specified
13+
in rsync_target. The contents of this directory should be reachable by the
14+
android device with public_url.
1515
1616
Examples:
1717
$ nix run .#deploy -- 'https://example.com/bootstrap/source.tar.gz' 'user@host:/path/to/bootstrap'
@@ -22,7 +22,11 @@ EOF
2222
fi
2323

2424
PUBLIC_URL="$1"
25-
RSYNC_TARGET="$2"
25+
if [[ $# == 2 ]]; then
26+
RSYNC_TARGET="$2"
27+
else
28+
RSYNC_TARGET=""
29+
fi
2630
: ${ARCHES:=aarch64 x86_64}
2731

2832
# this allows to run this script from every place in this git repo
@@ -51,27 +55,45 @@ if [[ "$PUBLIC_URL" =~ ^file:///(.*)/archive.tar.gz ]]; then
5155
else
5256
export NIX_ON_DROID_FLAKE_URL="$PUBLIC_URL"
5357
fi
58+
export NIX_ON_DROID_BASE_URL="${PUBLIC_URL%/*}"
59+
5460
log "NIX_ON_DROID_CHANNEL_URL=$NIX_ON_DROID_CHANNEL_URL"
5561
log "NIX_ON_DROID_FLAKE_URL=$NIX_ON_DROID_FLAKE_URL"
62+
log "NIX_ON_DROID_BASE_URL=$NIX_ON_DROID_BASE_URL"
5663

57-
58-
PROOT_HASH_FILE="modules/environment/login/default.nix"
5964
UPLOADS=()
6065
for arch in $ARCHES; do
6166
log "building $arch proot..."
6267
proot="$(nix build --no-link --print-out-paths ".#prootTermux-${arch}")"
68+
proot_hash="$(nix-hash --type sha256 --sri "$proot"/bin/proot-static)"
69+
attrs_file="modules/environment/login/proot-attrs/$arch.nix"
70+
new_attrs_file="$(mktemp)"
71+
72+
cat >$new_attrs_file <<EOF
73+
# WARNING: This file is autogenerated by the deploy script. Any changes will be overridden
74+
{
75+
url = "$NIX_ON_DROID_BASE_URL/bootstrap-$arch.zip";
76+
hash = "$proot_hash";
77+
}
78+
EOF
6379

64-
if grep -q "$arch-linux = \"$proot\";" "$PROOT_HASH_FILE"; then
65-
log "keeping $arch proot path in $PROOT_HASH_FILE"
66-
elif grep -q "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE"; then
67-
log "patching $arch proot path in $PROOT_HASH_FILE..."
68-
grep "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE"
69-
sed -i "s|$arch-linux = \"/nix/store/.*\";|$arch-linux = \"$proot\";|" "$PROOT_HASH_FILE"
70-
log " ->"
71-
grep "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE"
80+
if [[ ! -f $attrs_file ]]; then
81+
log "warn: $attrs_file not present; creating"
82+
mv $new_attrs_file $attrs_file
83+
log "adding $attrs_file to git index"
84+
git add $attrs_file
85+
elif diff $attrs_file $new_attrs_file >/dev/null; then
86+
log "no changes needed to $attrs_file"
7287
else
73-
log "no $arch proot hash found in $PROOT_HASH_FILE!"
74-
exit 1
88+
log "updating contents of $attrs_file"
89+
echo "<<<<<<"
90+
cat $attrs_file
91+
echo "======"
92+
mv $new_attrs_file $attrs_file
93+
cat $attrs_file
94+
echo ">>>>>>"
95+
log "adding $attrs_file to git index"
96+
git add $attrs_file
7597
fi
7698

7799
log "building $arch bootstrapZip..."
@@ -86,4 +108,8 @@ UPLOADS+=($SOURCE_FILE)
86108

87109

88110
log "uploading artifacts..."
89-
rsync --progress "${UPLOADS[@]}" "$RSYNC_TARGET"
111+
if [[ -n "$RSYNC_TARGET" ]]; then
112+
rsync --progress "${UPLOADS[@]}" "$RSYNC_TARGET"
113+
else
114+
echo "Would have uploaded ${UPLOADS[@]}"
115+
fi

scripts/local-deploy.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -xevo pipefail
3+
tmp=`mktemp -d`/n-o-d
4+
mkdir $tmp
5+
cd "$(dirname "$0")"/..
6+
git -C . archive --format=tar.gz --prefix n-o-d/ HEAD > $tmp/archive.tar.gz
7+
ARCHES=x86_64 nix run .#deploy -- file:///data/local/tmp/n-o-d/archive.tar.gz $tmp/
8+
adb shell 'rm -rf /data/local/tmp/n-o-d'
9+
adb push $tmp /data/local/tmp/
10+
adb shell 'cd /data/local/tmp/n-o-d && tar xzof archive.tar.gz && mv n-o-d unpacked'

0 commit comments

Comments
 (0)