NixOS-WSL icon indicating copy to clipboard operation
NixOS-WSL copied to clipboard

Systemctl with user flag don't work

Open aikooo7 opened this issue 1 year ago • 14 comments

Bug description

Using any commands of systemctl with the --user flag like systemctl list-unit-files --user --state=enabled with systemd native support activate gives the error: Failed to connect to bus: No such file or directory

To Reproduce

Steps to reproduce the behavior:

  1. Activate native systemd adding wsl.nativeSystemd = true; to /etc/nixos/configuration.nix
  2. Run systemctl list-unit-files --user --state=enabled

Expected behavior

The command execute without errors.

In the example command it should display all units.

Logs

Similar to #165 doing systemctl list-unit-files --user --state=enabled with native systemd support turned off works perfectly:

UNIT FILE                STATE   PRESET
emacs.service            enabled enabled
nixos-activation.service enabled enabled
dbus.socket              enabled enabled
gpg-agent-ssh.socket     enabled enabled
gpg-agent.socket         enabled enabled

5 unit files listed.

While with native systemd support turned off errors:

Failed to connect to bus: No such file or directory

aikooo7 avatar Dec 30 '23 13:12 aikooo7

Are you using WSL2?

SuperSandro2000 avatar Dec 31 '23 02:12 SuperSandro2000

I am

aikooo7 avatar Dec 31 '23 11:12 aikooo7

This is a bug/missing feature in WSL. My Ubuntu distro with systemd enabled for example behaves exactly the same. syschdemd included a workaround that made this work, but Microsoft's systemd implementation (which we call native) does not have that

nzbr avatar Jan 05 '24 22:01 nzbr

I'll leave this open, because I do in fact consider this a bug, but in WSL, not here. There might be possible workarounds, but I'd much rather see Microsoft fix it

nzbr avatar Jan 05 '24 22:01 nzbr

This is a bug/missing feature in WSL. My Ubuntu distro with systemd enabled for example behaves exactly the same. syschdemd included a workaround that made this work, but Microsoft's systemd implementation (which we call native) does not have that

Alright I will make a issue in wsl repo and keep you/this issue updated

aikooo7 avatar Jan 06 '24 17:01 aikooo7

The issue isn't always present. Right now I do not have the issue, whereas some days ago I was encountering it.

It's worth noting though that services and stuff takes a bit of time to start up (at least for me, even nix-daemon), so by trying to reproduce the issue directly after the shell is available, you'll 100% encounter the issue. Check the startup is actually finished by using htop or similar before attempting to reproduce, you should see a bunch of stuff starting.

wyndon avatar Aug 07 '24 18:08 wyndon

Experiencing this, programs.ssh.startAgent wasn't working for me, using nativeSystemd = false; solves the issue, but really isn't ideal...

$ wsl --version WSL version: 2.2.4.0 Kernel version: 5.15.153.1-2 WSLg version: 1.0.61 MSRDC version: 1.2.5326 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.26091.1-240325-1447.ge-release Windows version: 10.0.22631.4037

Is there an active issue for this on the WSL(g?) repo?

paperdev-code avatar Aug 14 '24 19:08 paperdev-code

Issue for me as well with, e.g., ssh-agent from home-manager. The user systemd unit is not enabled/working/ with native systemd enabled.

systemctl --user
# Failed to connect to bus: No such file or directory
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.19045.4651

nialov avatar Aug 16 '24 11:08 nialov