nix-community / nix-on-droid

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

Broken environment, how to rescue? #284

Open quantenzitrone opened 10 months ago

quantenzitrone commented 10 months ago

I set pkgs.fish as user.shell and now i can't get into a working environment, because /nix/store/<hash>-fish-<version>/ is a directory, and user.shell apparently needs the direct executable. How can I use an old nix profile to fix the config error and rebuild a new profile? The rescue shell doesn't really work, because i only have some android command line utils and i can't use the executables in the nix-store apparently, because they are not linked correctly.

As a last resort, I could just delete the app data of nix-on-droid and rebuild from new, but I'd prefer a better solution.

I found this on recovering in Termux, but it didn't work in Nix: https://wiki.termux.com/wiki/Recover_a_broken_environment

Gerschtli commented 10 months ago

You can open /data/data/com.termux.nix/files/usr/usr/lib/login-inner and below the line

. "/data/data/com.termux.nix/files/home/.nix-profile/etc/profile.d/nix-on-droid-session-init.sh"

write exec -l bash.

Then save and open the app again.

We should probably add some kind of checks to prevent these issues.

t184256 commented 10 months ago

/data/data/com.termux.nix/files/usr/bin/login $your_command. E.g., /data/data/com.termux.nix/files/usr/bin/login bash and restore using regular means.

quantenzitrone commented 10 months ago

It worked :+1: I think a more general fix for problems like this would be a way of selecting which configuration generation to use independently of already being in a working environment. Like with grub or systemd-boot on NixOS.

573 commented 10 months ago

Just to make sure that would be the login invocation with flakes-based fakedroid (?):

$ STATE_DIR=/tmp/fakedroid USE_FLAKE=1 nix run --impure github:t184256/nix-on-droid/add-support-for-fakedroid-usage'#fakedroid' -- /data/data/com.termux.nix/files/usr/bin/login bash
Welcome to Nix-on-Droid!
If nothing works, open an issue at https://github.com/t184256/nix-on-droid/issues or try the rescue shell.

Variation I tried:

$ STATE_DIR=/tmp/fakedroid USE_FLAKE=1 nix shell --impure github:t184256/nix-on-droid/add-supp
ort-for-fakedroid-usage'#fakedroid' --command /data/data/com.termux.nix/files/usr/bin/login bash --noprofile --norc
error: unable to execute '/data/data/com.termux.nix/files/usr/bin/login': No such file or directory

Also: With nix-on-droid and an error that doesn't let me start the failsafe-session, where would I apply the command line (...login bash) ?

573 commented 10 months ago

Regarding my last post, see https://github.com/t184256/nix-on-droid/pull/57#issuecomment-675689786.

I can use the "failsafe" session of the nix-on-droid app to run i. e. ../usr/bin/login bash --norc --noprofile meaning a non-broken "failsafe" is the bare minimum needed.

How this relates to fakedroid is another topic.

montchr commented 9 months ago

The same thing happened to me just now, as I was accustomed to the user shell options from NixOS and nix-darwin, which accept a derivation…

gelerum commented 8 months ago

@t184256, what should i do if i get this message error: creating directory '/data/local/tmp/nix-build-login-inner.drv-0': Permission denied when i try to switch my broken configuration after i entered bash from failsafe?

te-lang-wakker commented 6 months ago

So for anyone who wants to recover from this fully on-device, this worked for me using only cat and cd:

It's more convenient to cd to the folder first, as you probably won't have a text editor available, and you don't want the next commands to be too cumbersome:

Now you can just end whatever sessions you may have running and start the app as normal. If you made exactly the same mistake as OP and me, you should change the value of user.shell to "${pkgs.fish}/bin/fish"; and rebuild.

However, unlike regular NixOS, this will probably not change the default shell in your multiplexer of choice. For Zellij:

Keep in mind that the old docs are still using YAML.