Hey everyone,
I have been using sway window manager on nixos for nearly a year and a half now, and the experience has been pretty good. There are a few rough edges though, and I wanted to start a discussion about them, because 1. I want to fix them, but don’t have the skills and 2. we are very close to having pretty much everything sway related just working out of the box. First, let me just write down what I think is a sane default configuration for all things sway related:
{ config, pkgs, lib, ... }:
let
# bash script to let dbus know about important env variables and propogate them to relevent services
# run at the end of sway config
# see https://github.com/emersion/xdg-desktop-portal-wlr/wiki/"It-doesn't-work"-Troubleshooting-Checklist
dbus-sway-environment = pkgs.writeTextFile {
name = "dbus-sway-environment";
destination = "/bin/dbus-sway-environment";
executable = true;
text = ''
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
'';
};
in
{
environment.systemPackages = with pkgs; [
alacritty
dbus-sway-environment
chromium
];
services.dbus.enable = true;
xdg.portal = {
enable = true;
wlr.enable = true;
# gtk portal needed to make firefox happy
extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
gtkUsePortal = true;
};
programs.sway = {
enable = true;
wrapperFeatures.gtk = true;
extraPackages = with pkgs; [
swaylock
swayidle
grim # screenshot functionality
slurp # screenshot functionality
wl-clipboard
# make sure the default gnome icons are avaliable
# to gtk applications
gnome3.adwaita-icon-theme
];
};
services.pipewire = {
enable = true;
alsa.enable = true;
pulse.enable = true;
};
}
I think the main thing which is working now that didn’t in the past is pipewire with xdg-desktop-portal-wlr
which allows for screen sharing in webRTC apps like google meet (and to a lesser extent, zoom, but lets not get into that). Now the main issues as I seem them are as follows.
- It is very difficult to get sway working well as a user space systemd service. I think the main issue here is to do with environment variables not being shared between user environments and service environments. For example, if you follow the instructions for the nix wiki to create a sway service, it gets run with a different
DBUS_SESSION_BUS_ADDRESS
, which breaks things likexdg-desktop-portal-wlr
since they are running with the default userDBUS_SESSION_BUS_ADDRESS
. - It is difficult to get GTK and sway working well together. This is a know issue on the sway side, and there are official sway docs on how to deal with it, but they don’t seem to work well on nixos, so it seems like something we need to fix in nixpkgs directly.
- related to the above issues, the sway wiki is somewhat out of date. It does discuss these issues, but the proposed solutions don’t seem to work. I feel like they need to be solved directly in nixpkgs rather than at the configuration level.
I am probably going to start digging into the relevant parts of nixpkgs soon to try and figure out how the stuff works, but presumably there are a lot of people floating around who understand the infrastructure better than I do, and I would appreciate any thoughts or comments.
EDIT: I just found sway: Optimal NixOS integration · Issue #57602 · NixOS/nixpkgs · GitHub, which seems to be the issue tracking this kind of stuff.
EDIT 2: It seems that running sway as a systemd user service is not recommended: Systemd integration · swaywm/sway Wiki · GitHub and Include a systemd.service file · Issue #5160 · swaywm/sway · GitHub