-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Systemctl with user flag don't work #375
Comments
Are you using WSL2? |
I am |
This is a bug/missing feature in WSL. My Ubuntu distro with systemd enabled for example behaves exactly the same. |
I'll leave this open, because I do in fact consider this a bug, but in WSL, not here. |
Alright I will make a issue in wsl repo and keep you/this issue updated |
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 |
Experiencing this, programs.ssh.startAgent wasn't working for me, using nativeSystemd = false; solves the issue, but really isn't ideal...
Is there an active issue for this on the WSL(g?) repo? |
Issue for me as well with, e.g., systemctl --user
# Failed to connect to bus: No such file or directory
|
My workaround is to set this as the shell command in my terminal (run as root): /run/current-system/sw/bin/zsh -c \
"until [ -S /run/dbus/system_bus_socket ]; \
do sleep 1; \
done; \
systemctl restart user@1000; \
export DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1000/bus'; \
exec sudo --preserve-env=DBUS_SESSION_BUS_ADDRESS --user xieve zsh" It should be possible to incorporate a similar workaround into NixOS-WSL, if that is deemed appropriate. I also tried using |
Is this still relevant? I just performed a fresh installation of NixOS-WSL with all the default settings (in particular the native systemd integration), and user scope is working without issues: $ systemctl list-unit-files --user --state=enabled
UNIT FILE STATE PRESET
nixos-activation.service enabled enabled
ssh-agent.service enabled enabled
dbus.socket enabled enabled $ systemctl status --user ssh-agent.service
● ssh-agent.service - SSH Agent
Loaded: loaded (/etc/systemd/user/ssh-agent.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-09-13 13:31:15 UTC; 5min ago
Process: 288 ExecStartPre=/nix/store/k71apxkm38m3g34k01sb6zhysi0y7gph-coreutils-9.5/bin/rm -f /run/user/1000/ssh-agent (code=exited, status=0/SUCCESS)
Process: 290 ExecStart=/nix/store/78mv13w9mgh0s0rd7rnr6ff4d7a39bpd-openssh-9.7p1/bin/ssh-agent -a /run/user/1000/ssh-agent (code=exited, status=0/SUCCESS)
Main PID: 297 (ssh-agent)
CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/ssh-agent.service
└─297 /nix/store/78mv13w9mgh0s0rd7rnr6ff4d7a39bpd-openssh-9.7p1/bin/ssh-agent -a /run/user/1000/ssh-agent
Sep 13 13:31:15 calavera systemd[272]: Starting SSH Agent...
Sep 13 13:31:15 calavera systemd[272]: Started SSH Agent. > 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.4112 |
Yes, this is still relevant (see open issues on WSL). This is a race condition that depends on how long systemd takes to fully start up, which is less for fast and light systems. |
nix-community/NixOS-WSL#375 present in upstream wsl when start wsl and immediately dropping into a shell - sudo doesn't work - systemctl --user doesn't work possibly more. these are "fixed"
Thank you for this. guess when I updated wsl this was the root of the problem I've been running into. Was 95% of the way there of restoring my environment and this was the missing link! Was annoying to have to A little annoying to have to run those 3 commands every time I fire up wsl, but it's better than the alternative of disrupting my overall workflow. 🙏 Now if only could resolve this ------- edit: I've resorted to disabling |
I also face the same issue on WSL. My wsl version:
xieve workaround works for me except that it slows down the startup from wsl waiting for the system dbus socket to be created and checking if it is there. It takes as long as the disabled native systemd support.
Another way to somehow workaround the issue is to enable native systemd and also enable user systemd lingering mode for the user by doing so in the NixOS machine configuration:
Then when I login quickly as the user. The user's systemd services are not started, but if I wait a couple of seconds more the user systemd eventually starts.
Edit1:
It is because the symlink /run/wrappers/bin which is in the PATH links to a directory that is not yet created... |
Thanks to everyone for the investigation efforts. I too encountered the mentioned issue:
Just wanted to share my TL;DR, which is to |
Same here |
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:
wsl.nativeSystemd = true;
to /etc/nixos/configuration.nixsystemctl 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:While with native systemd support turned off errors:
The text was updated successfully, but these errors were encountered: