Skip to content

Install on vanilla termux#442

Open
izelnakri wants to merge 5 commits into
nix-community:masterfrom
izelnakri:install-on-vanilla-termux
Open

Install on vanilla termux#442
izelnakri wants to merge 5 commits into
nix-community:masterfrom
izelnakri:install-on-vanilla-termux

Conversation

@izelnakri
Copy link
Copy Markdown

@izelnakri izelnakri commented Feb 16, 2025

This PR is incomplete, instead we should create another bootstrap zip for termux specifically so we can continue to respect existing nix-on-droid-app code contract. This new bootstrap zip should be hosted on the http file server so people dont need to cross-compile and automate the process by simply executing a bash script on their Termux device.

I created a PR here to show you @t184256 the only working bootstrap zip for termux, after 2+ hours of manual cross-compilation from my machine to scp it and set it up on the android device:

[pc:~/nix-on-droid]$ NIX_ON_DROID_CHANNEL_URL=https://github.com/KoviRobi/nix-on-droid/archive/refs/heads/install-on-vanilla-termux.tar.gz \
                     NIX_ON_DROID_FLAKE_URL=github:KoviRobi/nix-on-droid/install-on-vanilla-termux \
                     nix build ".#bootstrapZip-aarch64" --impure
[android:~]$ scp pc:nix-on-droid/result/bootstrap-aarch64.tar.gz .
[android:~]$ mkdir ../nix/
[android:~]$ tar xf ~/bootstrap-aarch64.tar.gz -C ../nix/
[android:~]$ chmod +w -R ../nix/
[android:~]$ ../nix/bin/login

It supports symlinks (yay)
The error

    /data/data/com.termux/files/nix/bin/sh: error while loading shared libraries: /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/libc.so: invalid ELF header

it seems to happen  because of

    LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so

which doesn't support the .so file being a linker script

    .../files/nix $ cat ./nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/libc.so
    /* GNU ld script
       Use the shared library, but some functions are only in
       the static library, so try that secondarily.  */
    OUTPUT_FORMAT(elf64-littleaarch64)
    GROUP ( /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/libc.so.6 /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/libc_nonshared.a  AS_NEEDED ( /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/ld-linux-aarch64.so.1 ) )
Flake lock file updates:

• Updated input 'home-manager':
    'github:nix-community/home-manager/4de84265d7ec7634a69ba75028696d74de9a44a7?narHash=sha256-DVv6nd9FQBbMWbOmhq0KVqmlc3y3FMSYl49UXmMcO%2B0%3D' (2024-03-03)
  → 'github:nix-community/home-manager/a9953635d7f34e7358d5189751110f87e3ac17da?narHash=sha256-GUffLwzawz5WRVfWaWCg78n/HrBJrOG7QadFY6rtV8A%3D' (2024-11-24)
• Updated input 'nix-formatter-pack':
    'github:Gerschtli/nix-formatter-pack/2de39dedd79aab14c01b9e2934842051a160ffa5?narHash=sha256-HgSTREh7VoXjGgNDwKQUYcYo13rPkltW7IitHrTPA5c%3D' (2024-01-14)
  → 'github:Gerschtli/nix-formatter-pack/9f4bcf647cad2edafda7e1143071e0daf37cbc41?narHash=sha256-TxJ7RZLlBkKWZos1ai3eWIH0fBq1G6SVE%2Bq3dW%2B0qRU%3D' (2024-10-20)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/5d874ac46894c896119bce68e758e9e80bdb28f1?narHash=sha256-3M94oln0b61m3dUmLyECCA9hYAHXZEszM4saE3CmQO4%3D' (2024-02-17)
  → 'github:NixOS/nixpkgs/69661586d1c9d85e859887d95285f6fc92521657?narHash=sha256-BWzlDJpfcE7DgxtAkeXHnU69Iz6cU64yCgE6b%2Bhqds8%3D' (2024-11-26)
• Updated input 'nixpkgs-docs':
    'github:NixOS/nixpkgs/9a333eaa80901efe01df07eade2c16d183761fa3?narHash=sha256-Q8LJaVZGJ9wo33wBafvZSzapYsjOaNjP/pOnSiKVGHY%3D' (2024-01-22)
  → follows 'nixpkgs'
@t184256
Copy link
Copy Markdown
Collaborator

t184256 commented Feb 16, 2025 via email

@izelnakri
Copy link
Copy Markdown
Author

Hi @t184256 , I explained the reasons here: #257 (comment)

Today it is VERY difficult to install nix on termux and it is manual/not automated, so we need to have this bootstrap zip hosted on the web server with the current release pipeline. Then one can even package the installation up as a Termux package: $ pkg install nix-on-droid

@t184256
Copy link
Copy Markdown
Collaborator

t184256 commented Feb 17, 2025 via email

@izelnakri
Copy link
Copy Markdown
Author

izelnakri commented Feb 17, 2025

HI again @t184256 ,

I'm aware half of the development is proper communication & I try. Probably the best methodology/result is actually providing the changes that will make it more clear what specific changes I want.

My first 4 points explain the reasons why nix on termux instead of nix-on-droid a better idea:

a - Nix-on-droid app uses a fork of Termux which backtracks new features, changes & fixes to current Termux, if it ever gets these changes.
b - Nix-on-droid app doesn't support Termux addons which are essential if you want to run scripts/binaries in your shell environment on device boot (Termux:Boot) or service management(like previously discussed supervisord, runit or systemd: Termux:Services)
c - Nix-on-droid app doesn't support Termux RUN_COMMAND Intent interface which is required if you want to run a binary installed on users system from users another android app via Android Intent RPC framework.
d - Nix-on-droid repo targets com.termux.nix not com.termux, installing nix-on-droid on Termux is NOT trivial currently, whereas it could. Currently, manually compiling fork with very specific changes & build instructions for boostrap zip took me several hours to get a successful result after many different failed trials.

@t184256
Copy link
Copy Markdown
Collaborator

t184256 commented Feb 17, 2025

Yeah, something seems broken with our communication here, but that's fine =) Let me try again:

You seem to be answering "why would one want to forego nix-on-droid Termux fork app and use Termux with Nix installed inside it".
You provide great, compelling reasons detailing how the regular Termux app user experience is better than my fork's. I respect that.
In fact, my first attempt to run Nix on my very first 64-bit Android device, a cute ~50 SLOC script called nix-in-termux employed exactly the approach you're detailing here. It took Nix and installed it under Termux, using proot to keep Nix store at /nix/store and avoid expensive recompilation. Could've also used root, but I digress.

Later on I've decided I don't use Termux other than for installing Nix and started a different project, nix-on-droid, that skips right past the Termux part and bootstraps from my entirely Nix-built zipball. Would be cool if Termux app allowed me to specify an url and do a couple more things differently wrt discovering the entry point. It didn't, so I forked it under nix-on-droid-app. Without me using it, nix-in-termux got archived.

Six years later, you send a pull request to nix-on-droid, a project that's now easily 10x the size of nix-in-termux, that (to the best of my understanding, sorry if I understood something wrong here) does a very roundabout thing: uses this monstrosity, effectively, as an archive with Nix inside it, so that you can unpack it into your Termux environment and enjoy using Nix from there.

As I said, a valid goal in itself, except there's one thing I totally do not understand. There already exists an archive with Nix and all the required dependencies inside it that one can unpack and use, an official Nix release tarball. A tarball that nix-on-droid uses as a starting point for its zipball. A tarball that nix-in-termux downloads and unpacks. Half of the script is downloading it and unpacking it. Half of the script is prooting into the resulting environment. That's literally all to it. You can just do the same, maybe fork my nix-in-termux repo, update the urls/hashes and maintain it in its 50 SLOC glory. Unless I'm missing something?

Instead you file a pull request to nix-on-droid, a much larger project with an established userbase, to make it suit your needs, one that'd render their installs broken. With no tests, no upgrade paths, no nothing. To do what a much simpler nix-in-termux did?

Hope that clarifies my confusion about your request: I'm not asking "why would one prefer to go the nix-in-termux way'. I'm asking "why this PR to nix-on-droid instead of reviving nix-in-termux"?

Or doing that thing you've proposed with packaging nix as part of Termux. That sounds neat.

@izelnakri
Copy link
Copy Markdown
Author

izelnakri commented Feb 18, 2025

@t184256 Thanks for the very good explanation! This PR is not finished as you correctly pointed out it doesnt even include any tests or finished solution also I certainly appreciate & respect your solution when it comes installing nix on android devices.

In fact, my first attempt to run Nix on my very first 64-bit Android device, a cute ~50 SLOC script called nix-in-termux employed exactly the approach you're detailing here. It took Nix and installed it under Termux, using proot to keep Nix store at /nix/store and avoid expensive recompilation. Could've also used root, but I digress.

I tried the 50LOC script and it didnt work for me yesterday, dont remember the specific error unfortunately but I really tried building this with that script, with my fork with changes etc. Only these changes worked.

You can just do the same, maybe fork my nix-in-termux repo, update the urls/hashes and maintain it in its 50 SLOC glory. Unless I'm missing something?

I did precisely that, it didn't work. So I had to manually compile the bootstrap zip myself and wait hours of compilation and unpack it to my android device. Thus I suggest streamlining this process by adding a termux zip/tar to the release/web server pipeline.

"why this PR to nix-on-droid instead of reviving nix-in-termux"?

I also suggest removal of the nix-on-droid android app/simplifying/removing a lot of code here. I come from Ruby background where we had tons of ways to solve a problem, later in my life I realized its is MUCH better solution to remove code from a system whenever possible and support the best solution more and potentially remove the curse of choice for others. Thus I also suggest that we endorse "nix-in-termux" approach more, but thats of course up to you.

I know PR is still incomplete, let me know if you'd like me to have a look for the right needed changes. I'll probably get back to this PR but it might take few days/weeks.

Thanks again for this awesome solution! I just think it can be better 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants