-
Notifications
You must be signed in to change notification settings - Fork 67
Rich Presence in WSL
tldr;
- Rich Presence in WSL 1 is supported but with some manual setup (see setup instructions)
- Rich Presence in WSL 2 is not supported (see explanation)
In short, presence.nvim achieves Discord Rich Presence by communicating with Discord from your Neovim instance(s) through a dedicated IPC socket supplied by Discord on your computer (discord-ipc-0
), a unix domain socket in macOS and Linux or a named pipe in Windows.
Since WSL (Windows Subsystem for Linux) involves running a Linux environment on Windows, updating your Neovim activity in WSL on Discord in Windows would require communicating from unix domain sockets in the Linux subsystem (Neovim) to named pipes in Windows (Discord). In other words, we would need Windows/WSL Interop with AF_UNIX to establish your Rich Presence from WSL.
WSL 1 is supported! ✅
Rich Presence in WSL 1 is supported with the use of socat
and npiperelay
, both of which needs to be installed, set up, and run prior to using Neovim in WSL.
Note: Just a heads up, the following setup process is kinda hefty! Though it may be possible to have a more "out-of-the-box" experience here by simply opening a port and using an ad-hoc TCP socket at runtime, that would open potential attack vectors for malicious code on your machine as any user would be able to connect to the socket. Having an explicit relay connection limits access to privileged users, making it a more secure method of communicating to Windows from WSL (in other words: it's worth it!)
The following steps are based on Ubuntu on WSL. You may need to tweak the commands for other Linux distributions.
- Install
socat
sudo apt-get install socat
- Setup the relay (based on this README section)
- Install the latest
<version>
of Gosudo wget https://storage.googleapis.com/golang/go<version>.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go<version>.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin
- Build the npiperelay Windows executable for your
<windows-username>
go get -d github.com/jstarks/npiperelay mkdir -p /mnt/c/Users/<windows-username>/go/bin GOOS=windows go build -o /mnt/c/Users/<windows-username>/go/bin/npiperelay.exe github.com/jstarks/npiperelay sudo ln -s /mnt/c/Users/<windows-username>/go/bin/npiperelay.exe /usr/local/bin/npiperelay.exe
- Install the latest
- Create and add your
<username>
to adiscord
user groupsudo groupadd discord sudo usermod -a -G discord <username>
- Create a
discord-relay.sh
script and execute it under sudo in an elevated WSL session:#!/bin/sh exec socat UNIX-LISTEN:/var/run/discord-ipc-0,fork,group=discord,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/discord-ipc-0",nofork
- This configures the relay to create a
/var/run/discord-ipc-0
socket that presence.nvim will use to communicate to the//./pipe/discord-ipc-0
named pipe in Windows, allowing access to users only in thediscord
group (see the sample npiperelay scripts for more reference examples) - This relay script will need to be run prior to using Neovim to enable Rich Presence (look into starting the command automatically in WSL on startup for convenience)
- This configures the relay to create a
- Do your thing in
nvim
and (hopefully) you'll see your WSL Neovim activity in Discord Rich Presence in Windows! 🎉
WSL 2 is not supported :( ❌
WSL 2 is different from WSL 1 in various ways, but the difference pertinent to Rich Presence support is in accessing Discord from Linux. Whereas WSL 1 uses a translation layer and makes direct use of the host file system (via DrvFs), WSL 2 virtualizes the Linux environment and thus blocks the relay connection that would otherwise work in WSL 1 (or at least renders the pipe closed as observed during testing).
Microsoft unfortunately hasn't been exactly forthcoming regarding the state of AF_UNIX
in WSL 2, so there are only a couple related issues on their GitHub repo to go off on:
If you have any ideas on a solution or a workaround, please feel free to create an issue or pull request or message droob#1322 on Discord!
Edit: According to @takase1121 in this issue using the instructions for WSL 1 may work for WSL 2, but, as this has not been thoroughly tested, WSL 2 support is still not yet explicitly supported. If presence.nvim works for you on WSL 2 and you'd like to help out, message droob#1322 on Discord!