Build proot with Nix

This commit is contained in:
Alexander Sosedkin 2019-04-14 21:17:48 +07:00
parent f9c53aa84d
commit bd7335afa7
6 changed files with 144 additions and 15 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
bootstrap-aarch64.zip
bootstrap
nix-*-aarch64-linux.tar.bz2
proot-host
proot-tgt
qemu-aarch64

View file

@ -1,7 +1,7 @@
# Nix-on-Droid
Nix on Android, in a single-click installable package.
It's kind of a mess for now, but hey, it works!
It's a bit of a mess for now, but hey, it works!
This script installs Nix package manager on Android.
It does not require root, user namespaces support or disabling SELinux,
@ -19,6 +19,7 @@ and it's probably not an easy feat to pull off.
This repository contains the script
that is responsible for the initial bootstrap zipball generation.
## Try it out
Prebuilt stuff resides at https://nix-on-droid.unboiled.info

BIN
proot-tgt

Binary file not shown.

View file

@ -1,13 +0,0 @@
When I build it reproducibly with Nix, I get signal 7 during execution.
At the moment the proot binary was built directly on-device in Termux.
Sorry about that mess.
Outline:
* Download and compile libtalloc
* Collect .o files into an .a static library
* Compile proot with termux patches with:
* LDFLAGS += -L ../../talloc-2.1.14/
* LDFLAGS += -Wl,-Bstatic -ltalloc -Wl,-Bdynamic
I'd be grateful if somebody could help me fix it

132
proot.nix Normal file
View file

@ -0,0 +1,132 @@
let
pinnedPkgs = builtins.fetchTarball {
name = "nixos-unstable-2019-04-14";
url = https://github.com/nixos/nixpkgs/archive/acbdaa569f4ee387386ebe1b9e60b9f95b4ab21b.tar.gz;
sha256 = "0xzyghyxk3hwhicgdbi8yv8b8ijy1rgdsj5wb26y5j322v96zlpz";
};
overlay-openjdk8-linux5-fix = self: super: {
openjdk8 = super.openjdk8.overrideAttrs (oa: {
DISABLE_HOTSPOT_OS_VERSION_CHECK = "true";
});
};
overlay-jpeg-no-static = self: super: {
libjpeg = buildPkgs.libjpeg;
};
buildPkgs = import pinnedPkgs {
overlays = [
overlay-openjdk8-linux5-fix
];
};
crossPkgs = import pinnedPkgs {
crossSystem = (import "${pinnedPkgs}/lib").systems.examples.aarch64-android-prebuilt;
overlays = [
overlay-openjdk8-linux5-fix
];
};
crossStaticPkgs = import pinnedPkgs {
crossSystem = (import "${pinnedPkgs}/lib").systems.examples.aarch64-android-prebuilt;
overlays = [
overlay-openjdk8-linux5-fix
];
crossOverlays = [
(import "${pinnedPkgs}/pkgs/top-level/static.nix")
overlay-jpeg-no-static
overlay-openjdk8-linux5-fix
];
};
talloc = crossPkgs.stdenv.mkDerivation rec {
name = "talloc-2.1.14";
src = crossPkgs.fetchurl {
url = "mirror://samba/talloc/${name}.tar.gz";
sha256 = "1kk76dyav41ip7ddbbf04yfydb4jvywzi2ps0z2vla56aqkn11di";
};
depsBuildBuild = [ buildPkgs.python2 buildPkgs.zlib ];
buildDeps = [ crossPkgs.zlib ];
configurePhase = ''
substituteInPlace buildtools/bin/waf \
--replace "/usr/bin/env python" "${buildPkgs.python2}/bin/python"
./configure --prefix=$out \
--disable-rpath \
--disable-python \
--cross-compile \
--cross-answers=cross-answers.txt
'';
buildPhase = ''
make
'';
installPhase = ''
mkdir -p $out/lib
make install
${crossPkgs.stdenv.cc.targetPrefix}ar q $out/lib/libtalloc.a bin/default/talloc_[0-9]*.o
'';
fixupPhase = "";
prePatch = ''
cat <<EOF > cross-answers.txt
Checking uname sysname type: "Linux"
Checking uname machine type: "dontcare"
Checking uname release type: "dontcare"
Checking uname version type: "dontcare"
Checking simple C program: OK
building library support: OK
Checking for large file support: OK
Checking for -D_FILE_OFFSET_BITS=64: OK
Checking for WORDS_BIGENDIAN: OK
Checking for C99 vsnprintf: OK
Checking for HAVE_SECURE_MKSTEMP: OK
rpath library support: OK
-Wl,--version-script support: FAIL
Checking correct behavior of strtoll: OK
Checking correct behavior of strptime: OK
Checking for HAVE_IFACE_GETIFADDRS: OK
Checking for HAVE_IFACE_IFCONF: OK
Checking for HAVE_IFACE_IFREQ: OK
Checking getconf LFS_CFLAGS: OK
Checking for large file support without additional flags: OK
Checking for working strptime: OK
Checking for HAVE_SHARED_MMAP: OK
Checking for HAVE_MREMAP: OK
Checking for HAVE_INCOHERENT_MMAP: OK
Checking getconf large file support flags work: OK
EOF
'';
};
proot = crossStaticPkgs.stdenv.mkDerivation rec {
name = "proot-termux-${version}";
version = "2019-03-19";
src = crossStaticPkgs.fetchFromGitHub {
repo = "proot";
owner = "termux";
rev = "2a78bab91d01c723ecb7ce08069a096f6ff654c5";
sha256 = "1091si4i07349y7x7sx1r904gg3c9a3m39xkv24fakjlirpi3lpy";
};
buildInputs = [ talloc ];
makeFlags = [ "-Csrc CFLAGS=-D__ANDROID__" ];
installPhase = ''
mkdir -p $out/bin
cp src/proot $out/bin/
'';
};
in proot

5
script
View file

@ -28,6 +28,9 @@ export PROOT_NO_SECCOMP=1 # see https://github.com/proot-me/PRoot/issues/106
rm -rf ./bootstrap
mkdir -p bootstrap
echo "building proot-tgt (this may take a lot of time...)"
nix build -f proot.nix -o proot-tgt
wget https://github.com/proot-me/proot-static-build/blob/master/static/proot-x86_64?raw=true -O proot-host
chmod +x proot-host
@ -74,7 +77,7 @@ $PROOT_CMD "$TGT_NIX/bin/nix-store" --load-db < bootstrap/nix-installer/.reginfo
echo "injecting proot..."
mkdir -p bootstrap/bin
cp proot-tgt bootstrap/bin/proot
cp proot-tgt/bin/proot bootstrap/bin/proot
echo "making up some resolv.conf..."
mkdir -p bootstrap/etc