nix-community / nix-on-droid

Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli]
https://nix-on-droid.unboiled.info
MIT License
1.23k stars 65 forks source link

Remove hardcoded paths in .login-inner and fixed links in /bin/sh and /usr/bin/env #10

Closed Gerschtli closed 4 years ago

Gerschtli commented 4 years ago

Hello,

first of all I have to thank you for this great project!

I am using nix-on-droid a while now and ran nix-collect-garbage.. This resulted in dead links for /bin/sh and /usr/bin/env. Also the hardcoded paths in /bin/.login-inner were not present anymore.

I fixed it manually, but I think it would be much better, if these binaries are linked to ~/.nix-profile/bin on nix-on-droid-install. I would love to provide a PR for this, but unfortunately the instructions are not complete on how to convert the zip file to an installable apk.

Additionally I have two other questions (if these should be separate issues, I will move them out of here):

t184256 commented 4 years ago

I am using nix-on-droid a while now and ran nix-collect-garbage.. This resulted in dead links for /bin/sh and /usr/bin/env. Also the hardcoded paths in /bin/.login-inner were not present anymore.

facepalm

OK, I don't know how exactly to address that and still support installations without nix-on-droid-install, but it's definitely a big problem. Thanks for uncovering it, I'll try to come up with something.

Is there any way to make /proc/stat readable?

Not any that I know of.

Is there any way to set the login shell?

I assume that it's simply picked up from /etc/passwd, try editing it.

Gerschtli commented 4 years ago

facepalm

No problem ;)

I assume that it's simply picked up from /etc/passwd, try editing it.

Great idea, thank you. I will try this

t184256 commented 4 years ago

the instructions are not complete on how to convert the zip file to an installable apk.

It's way worse than this. You'll have to put it somewhere on the web, change the url in https://github.com/t184256/nix-on-droid-app, compile that one into an apk, install it and let it download the archive. I know, I know, I'm open to suggestions, preferably ones that don't require me to learn Android programming.

See comments below, it's now much easier.

Gerschtli commented 4 years ago

If you could provide more information about the build process, I would love to help improving the setup and contributing to that project!

t184256 commented 4 years ago

You're so right, I should've done that months ago.

Update to the new apk, and follow https://github.com/t184256/nix-on-droid-bootstrap/commit/873b9063e0f05b6be8bd2f89ccb1bbaad2b8ba05.

Have fun!

Gerschtli commented 4 years ago

Awesome, I will try the instruction set next week!

Gerschtli commented 4 years ago

I don't really understand neither how exactly the nix-on-droid-app is built nor where to download the prebuilt one.. And where exactly should I specify the "parent directory URL"?

t184256 commented 4 years ago

Me neither, I just open it in android studio and press 'build'. https://nix-on-droid.unboiled.info/app-debug.apk is the pre-built one.

When you start the app for the first time, or clean the app data in Android and restart it, the bootstrap zip all is downloaded and unpacked. The new version of the app will show a dialog box where you can specify something other than https://nix-on-droid.unboiled.info/bootstrap/

Does this answer your questions?

Gerschtli commented 4 years ago

Yes, this works for me!

I'm thinking on how to fix this issue.. My options so far:

  1. Patching home-manager so you can manage the files in $PREFIX/{bin,etc,usr/bin} via a dedicated home-manager module.
  2. Pointing the symlinks in $PREFIX/bin/sh and $PREFIX/usr/bin/env to $HOME/.nix-profile which may cause problems on initial startup.

Option 1 seems the most reasonable approach. Additionally I would love to refactor the big shell script to a nix expression as you are essentially building a zip ball of derivation.

What are your thoughts? Are there any other files or settings/options that could be added to a potential new home-manager module?

t184256 commented 4 years ago

I like what I hear.

2 needs investigation and maintenance, and I'm currently not sure how succesful would that be.

1 is ideal and your goal of building th ezipball with nix is a wonderfully noble goal. Feel free to open extra issues for them.

Also, I can envision two stopgap variants:

3) have two scripts, initial startup one and the one for when everything is under home-manager

4) autodetecting between the two variants in 3

Less elegant, but these are faster to implement, faster to fix this particular issue, and they are small steps towards the right direction.

As for other stuff that has to be generated, DNS configuration and /etc/passwd bug me the most.

Gerschtli commented 4 years ago

Seems like a good iterative approach. Just to clarify: What exactly is executed if I open the app/open a new terminal? /bin/login $USER, right?

What confuses me the most is the user name.. Sometimes it is nix-on-droid and sometimes it is u0_a271.. For example I have both directories: /nix/var/nix/profiles/nix-on-droid and /nix/var/nix/profiles/u0_a271 and both contain valid symlinks. Do you know the cause for this? And perhaps a solution to this?

t184256 commented 4 years ago

What exactly is executed if I open the app/open a new terminal?

/data/data/com.termux.nix/files/usr/bin/login. Which, in turn, executes /data/data.com.termux.nix/files/usr/bin/login.inner in proot with whoami output as a parameter. No, I don't have hard feelings about it, feel free to modify that if you wish.

What confuses me the most is the user name.. Sometimes it is nix-on-droid and sometimes it is u0_a271.. Do you know the cause for this? And perhaps a solution to this?

Yes. I foolishly thought that specifying it as nix-on-droid in /data/data/com.termux.nix/files/usr/etc/passwd will bring consistency. It didn't. Maybe it's just easier to give up and always use the android-issued username.

Gerschtli commented 4 years ago

I think for the sake of simplicity, we should unify the username situation. I would prefer the username nix-on-droid or even a custom username instead of the android generated one, but this could be another issue. (Same case with the hostname, should be configurable by the user as well.)

t184256 commented 4 years ago

I've put my 'stable' device through a 19.03 -> 19.09 update that also pulled in new nix. Expiring all previous home-manager generations, removing previous environments and garbage-collecting didn't break the installation, even though the old nix is not in store anymore.

And it means that you did it.