Multiple Discord instances for multiple accounts

I’ve been running NixOS 24.05 for a couple of months. I have working installs on a laptop and a desktop, and I’m managing things with home-manager as a NixOS module. So far I have Sway setup and a few tools installed.

I’d like to find some way of running two instances of the Discord messenger app simultaneously so that I can have a different user account logged in for each instance. I’m aware that the Discord app has a built-in feature for switching between multiple accounts, but this isn’t great because you can only have one account active at a time. While one is active you don’t see notifications, messages, etc from the other account. I’d like some way of running the app twice, but different config, account state, etc.

Is this something that I can do in some way with Nix and NixOS? Possibly with overlays or some other trick?

I can see some similar questions about installing multiple versions of native Linux software like Emacs or tools like the jdk. I suspect Discord will be more complicated because it’s an Electron app that isn’t compiled from source? From what I can tell the Nix pkg is pulling the compiled Linux binary from the Discord website. Maybe the closest comparison is this unanswered question about VS Code and Codium?

I should clarify, I don’t care so much about installing two different versions of Discord. I care more about having each the two Discord instance run simultaneously but with different config, session data, etc.

I don’t think multiple Nix user environments would help me, as from what I can tell, they’re more for multiple users each having their own set of package installs/versions, not one user having multiple installs of the same package.

Perhaps what I need is to override one of Discord instances to run with completely different values for the XDG_*_HOME environment variables, so that instance behaves as though it has a completely different home directory to itself? Is that something I could/should do with a Nix overlay? Or does it make more sense to do with some wrapper script, since this is more “runtime” configuration rather than package/build configuration?


Some other solutions I’ve already considered and would prefer to avoid:

Just use Discord from a web browser for one account: I’d really like to use the native app for both so I can reliably keep Discord windows to a specific workspace. Sway has some issues with assigning Firefox windows to a workspace purely by window title, because Firefox doesn’t set the window title immediately.

Create a separate system user account for the other Discord account: I don’t know if I can easily have apps from two different user accounts running in the same Wayland desktop? I’d expect something funky to happen with permissions and interprocess communications, but maybe I’m wrong there?

Use a third party Discord client: I’m a bit concerned about third-party clients triggering a ToS violation with Discord, but also I don’t know if any third-party Discord clients support multiple (simultaneous) user accounts as a feature?

Just as an update: I tried making a second user account. I started up my Sway desktop with my primary user account, then opened a terminal emulator and ran:

sudo -i --preserve-env=DISPLAY,WAYLAND_DISPLAY,NIXOS_OZONE_WL -u otheruser

This gave me a shell session as otheruser, but running discord gave me:

error: XDG_RUNTIME_DIR is invalid or not set in the environment.

…followed by some errors from ozone_platform_wayland.cc and then a segfault.

If I add XDG_RUNTIME_DIR to the sudo --preserve-env list, I instead get an error from wayland_connection.cc:

Failed to connect to Wayland display: Permission denied (13)

I assume this is as I expected: the second user account can’t open a window on the desktop environment started by my primary user, as it doesn’t have permission to access the special files in $XDG_RUNTIME_DIR (/run/user/1000) used for interprocess communication, etc.

Hey Natasha,

You can pass in a command line parameter to Discord to allow multiple instances to open:

--multi-instance

So something like

flatpak run com.discordapp.Discord --multi-instance

That does seem to work. Thank you so much!

Awesome, glad that fixed the issue for you!

Just for clarity to anyone else that may come across this post:

The reason the sudo command wasn’t working is that you have to grant permission to another user to use your graphical interface.

You can do so with a command like this. It is important to isolate it to who you want to connect as blanket access (just a + is insecure)

xhost +si:localuser:userB

And you can remove access like this:

xhost -si:localuser:userB

You very likely will run into possible other permission issues (e.g passing along input from Microphones/pulseaudio, folder permissions, etc).

Ah, I wasn’t sure if xhost would help me here. I assumed it was just for X-related uses, and I’m using Wayland.