Open mangkoran opened 8 months ago
Can confirm with:
WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3155
NAME="Fedora Linux"
VERSION="39 (Container Image)"
ID=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
Exactly what @mangkoran mentioned by creating a oneshot systemd service.
Many thanks, @mangkoran, for the details and the service script. Had the same issue with WSL 2.1.5 and Fedora 39 and the workaround fixed it.
Here is another workaround according to this post. Create /etc/systemd/system/user-runtime-dir@.service.d/override.conf
and add:
[Service]
ExecStart = sh -c "ln -fs /mnt/wslg/runtime-dir/* /run/user/"%i
This will link everything in /mnt/wslg/runtime-dir
to /run/user/$UID
. The reason why I don't mount /mnt/wslg/runtime-dir
at /run/user/$UID
like what the original post does is that it will cause user@UID.service
's failure due to /run/user/$UID
's incorrect owner
sorry for asking this novice question but @mangkoran how do we enable this service. Thanks for the help
@king-11 It should be the following.
systemctl --user enable symlink-wayland-socket.service
I will add this to my top post.
PS: A quick Google search should help you faster 😉
Although this issue is about Wayland, for anyone who found this becaus X apps don’t work either (like me), if you want to use X11 apps, too, you will also have to symlink /mnt/wslg/.X11-unix/X0
to /tmp/.X11-unix/X0
.
For me, X11 apps work but Wayland doesn't.
WSL info:
> wsl --version
WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.3593
Ubuntu info:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
$ uname -a
Linux *** 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
and systemd is enabled.
tried:
$ echo "hello" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.
As I fear the provided workaround may break my system(?) I didn't test it.
@arf1372 You could try the symlink command first (not the systemd service) and see if solves the issue on your machine.
ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1000/
This command is harmless as it just symlinks and not removing any files. If anything goes wrong, you could restart WSL and everything will be reverted.
For me, X11 apps work but Wayland doesn't.
WSL info:
> wsl --version WSL version: 2.1.5.0 Kernel version: 5.15.146.1-2 WSLg version: 1.0.60 MSRDC version: 1.2.5105 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22631.3593
Ubuntu info:
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 24.04 LTS Release: 24.04 Codename: noble $ uname -a Linux *** 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
and systemd is enabled.
tried:
$ echo "hello" | wl-copy Failed to connect to a Wayland server: No such file or directory Note: WAYLAND_DISPLAY is set to wayland-0 Note: XDG_RUNTIME_DIR is set to /run/user/1000/ Please check whether /run/user/1000//wayland-0 socket exists and is accessible.
As I fear the provided workaround may break my system(?) I didn't test it.
Hey @arf1372 , could you tell how you configured X11?
Ubuntu-24.04 set these files differently than Ubuntu-22.04:
I don't think I ever faced this issue on Ubuntu 22.04. On 24.04, I can't even run ls
on /mnt/wslg/runtime-dir/
without sudo, whereas 22.04 doesn't require it all.
I don't think I ever faced this issue on Ubuntu 22.04. On 24.04, I can't even run
ls
on/mnt/wslg/runtime-dir/
without sudo, whereas 22.04 doesn't require it all.
To make it work under Ubuntu 24.04 I had to set rx
permissions or change owner on runtime-dir
, then I could create the simlink.
sudo chmod +rx /mnt/wslg/runtime-dir (or) chown 1002:1002 /mnt/wslg/runtime-dir
ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1002/
(where 1002 is the current user.)
So, this may not be a satisfying work-around for everyone, but this poblem was bowing up my Neovim session, because WAYLAND_DISPLAY was set, causing Neovim to assume that wl-copy was in play and working properly.
I added this awful bodge to my .zshrc that may help someone so I am including it here. If WSL is detected, we unset WAYLAND_DISPLAY but also add a 'wway' alias to put it back if we actually WANT to run a GUI app :)
# Under WSL, we KINDA have Wayland, but not really, and that blows up Neovim. Ungh. :)
# Add an alias so if we actually WANT the pseudo wayland, we can haz.
if [[ $(uname -r | grep "microsoft") ]] then
unset WAYLAND_DISPLAY
alias wway='export WAYLAND_DISPLAY=wayland-0'
fi
Yay! My neovim works again :)
Thank you @mangkoran
This is an issue for me on Ubuntu 24.04.1 LTS running on WSL2
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
So, this was also blowing up my copying while using Neovim (nvim) after my X410 trial ended:
$ echo abc | /usr/bin/wl-copy.orig
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.
My issue was not pasting into WSL, but copying from WSL and pasting into Windows, especially from nvim.
Unless you have disabled it, you should be able to run Windows binaries from within WSL 2. The workaround for clipboard access I have implemented is to wrapper Microsoft's bundled c:\Windows\system32\clip.exe binary in a script to copy:
#!/bin/bash
# the pbcopy script
tee <&0 | clip.exe
exit 0
For pasting, I opted to wrapper PowerShell and strip the extraneous appended carriage return or null:
#!/bin/bash
# the pbpaste script
powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'
exit 0
Put these scripts in /usr/bin
as /usr/bin/pbcopy
and /usr/bin/pbpaste
. Then rename wl-copy and wl-paste and symlink the pb scripts:
$ sudo mv /usr/bin/wl-copy{,.orig}
$ sudo mv /usr/bin/wl-paste{,.orig}
$ sudo ln -s /usr/bin/pbcopy /usr/bin/wl-copy
$ sudo ln -s /usr/bin/pbpaste /usr/bin/wl-paste
If you want to test this in nvim, go into visual mode, select some text, and press <Ctrl-R>"+y
to yank the selection to the system clipboard. Then try pasting it in a Windows app.
Yes, you could just name the scripts wl-copy and wl-paste, but I use symlinks to avoid confusing myself six months from now.
The other benefit of symlinking is being able to use the pbcopy
and pbpaste
commands like I would in macOS. 😄
NOTE: This approach assumes you only want to copy/paste text. Unlike wl-copy/paste the MIME type is stripped/ignored.
Thanks for reporting @mangkoran . I've got the same issue here with Fedora 40 under WSL2.
Doing the symlink command above fixed it for me for now.
Windows Version
10.0.19044.4046
WSL Version
2.0.14.0
Are you using WSL 1 or WSL 2?
Kernel Version
5.15.133.1-1
Distro Version
Arch
Other Software
Repro Steps
wl-clipboard
->sudo pacman -S wl-clipboard
echo "foobar" | wl-copy
Expected Behavior
foobar
is copied to Windows clipboard through WaylandActual Behavior
Diagnostic Logs
Not applicable
Additional Note
I couldn't open any GUI apps and any Wayland-related tools such as
wl-copy
.The following are the content of
/run/user/1000/
Based on that it seems
wayland-0
socket is missing inXDG_RUNTIME_DIR
. Hmm pretty weird I think as I don't disableguiApplications
in.wslconfig
.Then I found https://github.com/microsoft/wslg/issues/1187. I proceed to check
/mnt/wslg/runtime-dir/
.And yep there it is. So Wayland socket is currently not in
XDG_RUNTIME_DIR
. It seems the Wayland socket was previously symlinked inXDG_RUNTIME_DIR
as in https://github.com/microsoft/WSL/issues/10205. Then I tried to link the Wayland socket.Although it works as intended, I think this isn't the default behavior/a regression.
Workaround
As a workaround, I created a simple systemd user oneshot service/unit.
Enable it using the following command.