WSL, WSLg, and systemd hacks

Since I know a lot of folks here use snapd under WSL using either my genie or a different systemd-enabling hack, a word of warning/advice:

  • If you’re using genie, make sure you’ve updated to 1.38 for WSLg compatibility
  • If you aren’t, here’s what breaks and needs fixing:
    • You will need to ensure that the new environment variables are passed through: DISPLAY, WAYLAND_DISPLAY, and PULSE_SERVER .
    • By default, systemd runs systemd-tmpfiles when “booting”, which cleans up various directories and temporary files. This includes /tmp/.X11-unix, which wipes out the link to the socket WSLg’s X server is accessed through, thus ensuring that X applications won’t work either inside or outside the systemd namespace. You need to put this link back after systemd initializes to make X work again; genie does this simply by bind-mounting /mnt/wslg/.X11-unix on top of /tmp/.X11-unix after systemd is up.

Hope this is of use.


Or there is my systemd work that handles everything for you, and supports GUI Snaps.

1 Like

Hm. That does look like a better approach to the X11 socket issue. Think I’ll have to steal imitate that for 1.39.

(Did you need to do something special to support GUI snaps? I meant to inquire after seeing your post the other day, because they seem to have been working all along for me once snaps were up and running.)

…actually, while I’m here, have you had any thoughts on how best to coerce GUI apps and snaps launched from the new turn-.desktop-files-into-Start-Menu-shortcuts facilities to launch in the systemd area?

1 Like

The enabling of GUI snaps was handled with the following:

  • this file copied to /etc/systemd/system/user-runtime-dir@.service.d/override.conf
  • this file and this file copied to /etc/systemd/system/

The first mounts /mnt/wslg/runtime-dir at /run/user/$UID to ensure that the pulseaudio and wayland sockets are accessible by snaps. The second re-enables the /tmp/.X11-unix socket when systemd mounts /tmp as a new tmpfs mount in the systemd mount namespace.


Ah, specifically for WSLg. Gotcha.


1 Like

I suspect that systemd-socket-proxyd used like this may cause problems with any extensions that rely on file descriptor passing. DRI3 is the main one here, although I suspect that’s not the only barrier to getting accelerated graphics working. Snaps would also need to have access to the correct driver libraries too.

I had that issue with the wayland socket, but the X11 socket seems ok from quick testing… I might have not created the right situation to highlight it tho.

As I said, I think DRI3 is the only common user of the feature. And if you don’t have the matching 3D driver available in the sandbox, it may never even attempt to do any fd passing.

1 Like