nix-community / NixOS-WSL

NixOS on WSL(2) [maintainer=@nzbr]
Apache License 2.0
1.75k stars 114 forks source link

Activating native systemd support breaks shell #486

Open aikooo7 opened 3 months ago

aikooo7 commented 3 months ago

Bug description

When enabling native systemd support and rebuild, switch and restart system you will be unable to log in to your system unless you use the recovery shell or use the shell binary directly instead of the wrapper.

Note: While trying to find what was the cause of the issue I rebuilt my home-manager and got Failed to connect to bus: No such file or directory so maybe #375 is related.

To Reproduce

Steps to reproduce the behavior: Add wsl.nativeSystemd = true; Run sudo nixos-rebuild switch Run wsl --shutdown in cmd. Run wsl -d NixOS in cmd. NixOS should be your nixos distro's name in wsl.

Logs

thread 'main' panicked at src/shell_wrapper.rs:105:10:
called `Result::unwrap()` on an `Err` value: When initializing journal logger

Caused by:
    No such file or directory (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

WSL version

2.0.9.0

WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.4170
nzbr commented 3 months ago

It looks like systemd hasn't started properly. That should obviously not crash the shell though, I'll fix that

nzbr commented 3 months ago

As for the underlying problem: Can you send me the output of dmesg executed in another distro right after this happens. To reduce the size of the output, it probably makes sense to shut down WSL with wsl --shutdown before that

polybluez commented 1 month ago

Is this the same error?

C:\Users\Admin>wsl
when trying to exec the wrapped shell

Caused by:
    No such file or directory (os error 2)
polybluez commented 1 month ago

There is a workaround: first fire up WSL with a recovery shell wsl -d NixOS --system --user root -- /mnt/wslg/distro/bin/nixos-wsl-recovery and then enter WSL as usual

nzbr commented 1 month ago

@polybluez no, that is a diffferent error. I suspect that the one @aikooo7 experienced was a race condition, because the shell wrapper tried to connect to journald before that was started. That one should be fixed now, because it does not result in a crash anymore. Your error looks like the wrapper tries to start your shell, but the shell's binary just does not exist for some reason. The same probably would have happened without the wrapper

leonbreedt commented 6 days ago

This occurs for me as well, I basically have to revert to wsl.nativeSystemd = false; , or I cannot use NixOS-WSL at all.

Data point: My NixOS-WSL is built using a flake, using a user created by the flake (and not the nixos user). As soon as I have run the flake built, it is broken. Tried with a completely fresh install of the latest build (which has https://github.com/nix-community/NixOS-WSL/pull/496 merged), followed by my flake build.

After the flake build, I cannot start up the distribution due to this error.