nix-on-droid
nix-on-droid copied to clipboard
Broken environment, how to rescue?
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
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.
/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.
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.
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) ?
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.
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…
@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?
So for anyone who wants to recover from this fully on-device, this worked for me using only cat and cd:
- Open app in failsafe (hold icon > failsafe).
- cd to
/data/data/com.termux.nix/files/usr/usr/lib/
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:
cat login-inner- Copy the content and paste it into your (Android) text editor of choice.
- Remove anything below the path string (
"/data/data/com.termux.nix/files...) and writeexec -l bash. - Copy the edited text to your clipboard.
cat > login-inner- Paste the edited text from your clipboard.
ctrl + D
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:
- Open
~/.config/zellij/config.kdl, or create it first if it does not exist. - Add
default_shell "fish".
Keep in mind that the old docs are still using YAML.