nix-community / robotnix

Build Android (AOSP) using Nix [maintainer=@danielfullmer,@Atemu]
594 stars 65 forks source link

Install Nix #158

Open Atemu opened 2 years ago

Atemu commented 2 years ago

We obviously build the image with Nix and all but, after that, we "only" have a regular Android image.

Wouldn't it be cool if we could install the Nix package manager to the image? Android has a Linux kernel, filesystem and a shell which is basically all that's required to use Nix.
There are ways of using Nix on Android (nix-on-droid) but they're very limited and more "proper" solutions would require root access.

If we had /nix/ and a nix-daemon, that'd be so useful.

Not only would such an option allow you to use Nix on your phone, it'd allow Nix to become your phone, similar to NixOS. In a future where modular builds are possible, parts of the OS could be interchanged just like an updated package on NixOS. This could allow for OS upgrades with no flashing from the recovery.

hmenke commented 2 years ago

Related: Nix-on-Droid

It runs in Termux and I think it uses proot. No idea whether it bundles a nix-daemon.

GitHub: https://github.com/t184256/nix-on-droid Prebuilt APKs: https://nix-on-droid.unboiled.info/ F-Droid: https://f-droid.org/en/packages/com.termux.nix/

Atemu commented 2 years ago

There are ways of using Nix on Android (nix-on-droid) but they're very limited (...)

MagicRB commented 2 years ago

You can install nix on any rom with

 unset LD_PRELOAD
 export USER=$(id -un) HOME=$PWD GROUP=$(id -g)

 sudo mount -o remount,rw /
 # do the same for /etc but the specifics vary, mines on tmpfs but only from android 11 and up

 sudo mkdir /nix /data/nix
 sudo mount -o bind /data/nix /nix
 sudo chown $(id -u):$(id -g) -R /nix

 # create /etc/resolv.conf however you want, i recommend
 su
 echo "nameserver 8.8.8.8" > /etc/resolv.conf
 exit

 # remount all back to ro

 curl -L https://nixos.org/nix/install | sh

 # then to get into the default nix profile
 . nix-profile/etc/profile.d/nix.sh

 # also the environment variable edits must be done before sourcing nix.sh or it will silently do nothing
should be all. from here install home manager as normal
hmenke commented 2 years ago

install nix on any rom sudo

Yeah, I don't think so.

MagicRB commented 2 years ago

Well im assuming you have it rooted

Atemu commented 2 years ago

I'm aware that it's possible to modify the OS imperatively to include Nix but this is about baking Nix into the Android image declaratively.

MagicRB commented 2 years ago

I realize that, but given that, that script works it's proof that it's possible and it may help someone

CyberShadow commented 4 months ago

Let's define the problem a little more:

That gives us the following picture:

What does this give us?

Open questions: