I succeeded in running Nix on Android (now without Termux!)

I like the usability and discoverability of Termux (unprivileged Linux distro targeting Android), but the idea of painfully recreating a distro with Android toolchain / bionic sounds horrible. I felt like the flexibility of Nix would save the day the best way ever, and yesterday I finally bought an aarch64 tablet to give it a go.

Sorry if this is common knowledge, but I couldn’t find a guide or a script anywhere and cobbled my own one.

Limitations: requires Termux, relies on proot pseudo-bind-mounts, only works on aarch64 (and maybe x86).

Pros: does not require root, user namespaces or disabling SELinux. Also, it frigging works!


UPDATE 1: I’ve started something even better, a separate app bringing Nix to your device without relying on Termux the distro. Test builds here: https://nix-on-droid.unboiled.info



Can we use nix-env in nixpkgs.bashInteractive ? It seems to hang for me. I got “No such file or directory” error after a couple of seconds.

Yeah, it should work and works for me. Weird. =/

Was it a clean Termux install? Were there any problems during the installation? Does nix work? nix run nixpkgs.hello?

Sorry, I forgot to reply to your last post.

Are you still working on this project?

It’s kinda in the ‘works for me’ stage. If you have something you want me to fix, I’ll be happy to look into it.


I tried again and it seems to work with nix-on-droid-install.

I installed a couple of applications with home-manager but I don’t seem to run some of them. I installed tealdeer (tldr) and exa and I get ‘command not found’ when I try to run them.

Where should I report problems? https://github.com/t184256/nix-on-droid-app doesn’t seem to have an issue tracker.

1 Like

Report them against https://github.com/t184256/nix-on-droid-bootstrap and I’ll definitely take a look this week.

1 Like

I’m not really familiar with the android development ecosystem; how can I install your tool?

(backstory: I’m trying to do some Bluetooth stuff by forwarding USB Bluetooth into a VirtualBox vm for android-x86 (https://www.android-x86.org/) (How to use android emulator for testing bluetooth application? - Stack Overflow), but I’m running into some problems, so I want to install some stuff to see if I can figure something out.)

The link was in the first message:

Oh, does that work for all architectures? I kind of assumed it doesn’t because of the -aarch in the bootstrap folder, but I should have just tried it!

It tells me it failed to install the bootstrap package.

Oh, wow, an x86 request. Nix-on-Droid doesn’t have a x86 bootstrap zip yet, and while it’s not that difficult to create one, I kinda doubt that it’s useful for your particular setup.

You see, most of the magic is there to make it work under regular android app restrictions. Your use case sounds like you don’t care about this at all, you have root and you want to run nix-managed stuff as root, which is possible, but difficult. For you it’s probably better to just try and install nix directly on top of Android, unpacking a Nix tarball into / and executing nix from there, like this person did with guix: Guix on Android! — 2018 — Blog — GNU Guix

The repository you are looking for is https://github.com/t184256/nix-on-droid-bootstrap, the other one is just the terminal emulator for it.

1 Like

Sweet, thanks for the fast reply! I’ll give it a shot.

Sooo…has anyone gotten the installer linked from NixOS - NixOS Linux working on android?

edit: accidentally some words

I don’t suppose there’s some android equivalent of sudo that would make your style of things easy? I don’t know why running nix manager stuff as root on android would be difficult. It’s probably easier for me to use your thing rebuilt for x86 than to figure out how this all works (though that might be inevitable anyway…)

I’m not aware of anything other than Android’s su. You can run su in a fallback session, and then run /…/usr/bin/login as root. But I don’t know any way to become root from within Nix-on-Droid env. If you solve it, let me know in https://github.com/t184256/nix-on-droid-bootstrap/issues/3

Would you be able to create an x86 build real quick?

I can try to do that today or tomorrow. 32 bit or 64 bit? Can you tell me more precisely what Android x86 image do you run and how?

EDIT: trying to build it now, it’s not as trivial as I thought =(

I’ve built an untested i686 bootstrap, you’re welcome to test it.

1 Like

Hey, thanks! I tried running the apk but it says could not open or something like that. I’ve too much on my plate to work on this today, just leaving a note in case it’s not my fault.

Edit: Oh, running the app that seems to be some sort of installer, worked, results in something like “process exited error code 1”.

I’m on the androidx86 image.

Sorry for being vague, will try to get back to you properly later.

I literally signed up here because of your post. I’m -needless to say- interested in reading/hearing anything or Anything you feel comfortable sharing about your journey to get to this (non-Termux environment), along with any advice for someone JUST LIKE YOURSELF, with similar goals.
YOU can also reach me at zefon@zefdroid.com, my admin email address.