Skip to content

Running Sway without systemd

Patrick Collins edited this page Mar 20, 2019 · 3 revisions

Note: This page applies to Sway-1.0 with wlroots and does not apply to 0.15

Sway makes use of systemd's logind to handle sessions and allows sway to run without elevated privileges. This is the recommended way to use Sway.

However, we understand that not everybody is using a systemd-based distro, so sway has alternate ways to handle this.

Please note the non-logind way of using sway sees considerably less developer attention that using logind and you're more likely to run into issues. Please mention if you're not using logind in any support requests.

elogind

elogind is a project to take systemd's logind and separate it into an external program that can be run without the rest of systemd. This is the recommended way for users not using systemd.

To use elogind, wlroots should be compiled with -Dlogind-provider=elogind, or it will try to use libsystemd instead.

For example:

meson build -Dbuildtype=debugoptimized -Dlogind=enabled -Dlogind-provider=elogind
ninja -C build
sudo ninja -C build install

Make sure elogind is running and configured correctly before starting sway. Refer to your distribution's documentation for details.

Direct via setuid

Note: Attempting to run sway this way without this being configured correctly will probably leave your computer in an unresponsive state, requiring a reboot

To have sway run as root in order to gain access to the resources you need, you must set the setuid bit on the sway executable:

chmod +s /usr/bin/sway

Sway will fork into a minimal slave process to keep these privileges, while dropping its own. As with any program, using setuid has serious security implications.

Direct via capabilities

Note: Attempting to run sway this way without this being configured correctly will probably leave your computer in an unresponsive state, requiring a reboot

Note: Sway won't drop capabilities, use setuid instead.

In order to use this, wlroots must be compiled with libcap support:

meson build -Dbuildtype=debugoptimized -Dlibcap=enabled
ninja -C build
sudo ninja -C build install

In order to run, sway needs permissions to open /dev/dri/card* and /dev/input/event*. Add the user you will be running sway as into the video and input groups.

Sway also requires the CAP_SYS_ADMIN capability in order to take control of your GPU correctly. You must add this capability to the sway executable:

setcap cap_sys_admin=eip /usr/bin/sway

Note: CAP_SYS_ADMIN is a very serious capability to give a process, and can be considered as powerful as root itself. See here for some more background.

Tips and Tricks

Archlinux without systemd/elogind

In order to automatically keep the extra privileges after a sway installation/upgrade, add the following pacman hook to /etc/pacman.d/hooks:

[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = sway
Target = sway-git

[Action]
Description = Applying setuid-bit to sway
When = PostTransaction
Exec = /usr/bin/chmod +s /usr/bin/sway
You can’t perform that action at this time.