robotnix icon indicating copy to clipboard operation
robotnix copied to clipboard

Install Nix

Open Atemu opened this issue 3 years ago • 8 comments

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.

Atemu avatar Jan 23 '22 13:01 Atemu

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/

hmenke avatar Jan 23 '22 14:01 hmenke

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

Atemu avatar Jan 23 '22 15:01 Atemu

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

MagicRB avatar Feb 03 '22 16:02 MagicRB

install nix on any rom sudo

Yeah, I don't think so.

hmenke avatar Feb 03 '22 16:02 hmenke

Well im assuming you have it rooted

MagicRB avatar Feb 03 '22 16:02 MagicRB

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.

Atemu avatar Feb 04 '22 08:02 Atemu

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

MagicRB avatar Feb 04 '22 09:02 MagicRB