sway
sway is the de facto standard Wayland compositor, and a direct replacement for the i3 window manager.
Installation
Under Arch Linux
sway can be installed using the sway
package:
sudo pacman -S sway
For sway to work, it needs privileged access to your "seat".
Note
A seat just refers to all the physical devices required to run a desktop environment. Things like your mouse, keyboard, display, etc.
See the Wikipedia page on Multiseat configuration for more info.
If you have polkit
installed, then sway will be able to pick up on that and launch automatically.
If polkit is not installed, sway will come bundled with seatd
as a dependency of wlroots
. To get seatd
working, add yourself to the seat
group and enable the seatd.service
:
# Add yourself to the "seat" group - again ONLY for no polkit.
sudo usermod -aG seat $(whoami)
# Enable the service
sudo systemctl enable seatd.service
To run sway from TTY, it's just:
# Start sway.
sway
Under NixOS
It's generally recommended that you run sway under Home Manager.
To set it up, first enable polkit
:
# configuration.nix
security.polkit.enable = true;
Then you can set wayland.windowManager.sway
in your home config:
# home.nix
wayland.windowManager.sway = {
enable = true;
# This is defaulted to on, anyway.
xwayland = true;
};
If you are using a login manager, you'll need to add the sway nixpkg into its session packages. Here's sddm as an example:
services.xserver.displayManager = {
sddm = {
enable = true;
wayland.enable = true;
};
sessionPackages = [pkgs.sway];
};
If you're on a system that changes output regularly, like a laptop, then it's recommended to install some kind of external output configuration, like kanshi
:
# Copied from https://nixos.wiki/wiki/Sway#Systemd_services
systemd.user.services.kanshi = {
description = "kanshi daemon";
serviceConfig = {
Type = "simple";
ExecStart = ''${pkgs.kanshi}/bin/kanshi -c kanshi_config_file'';
};
};
Configuration
Under Arch Linux
Configuration is located under ~/.config/sway/config
, and is a superset of i3 configuration. If you've got an existing i3 config, copy-pasting it should work.
To begin configuring, start by copying over the default config:
# Make sure the folder exists first
mkdir -p ~/.config/sway
# Copy the default config over
cp /etc/sway/config ~/.config/sway/config
# Start editing :)
nvim ~/.config/sway/config
Under NixOS
This section will only cover sway installed under Home Manager.
Config is done under the wayland.windowManager.sway.config
option:
{ pkgs, ... }: {
wayland.windowManager.sway = {
enable = true;
xwayland = true;
config = {
# SUPER key
modifier = "Mod4";
};
}
}
Like elsewhere in Nix, pkgs
can be used directly in your sway config without polluting your system, and without knowing specific paths:
# pkgs are here, I swear
wayland.windowManager.sway.config = {
menu = "${pkgs.rofi}/bin/rofi -show drun";
terminal = "${pkgs.foot}/bin/foot";
# Auto start
startup = [
{
command = "${pkgs.stylish}/bin/styli.sh -y";
always = true;
}
];
};
Bars and services
To configure a status bar like waybar, you can configure it as a startup User Service:
wayland.windowManager.sway.config = {
startup = [
{
command = "systemctl --user restart waybar";
always = true;
}
];
bars = [];
};
programs.waybar = {
enable = true;
systemd.enable = true;
}
Note
wayland.windowManager.sway.config.bars = [];
is not optional! Not including this will make sway also show its default bar.
Note
You can configure this differently, but in the case of waybar it will not pick up new configs without configuring it like this.
Keybindings
Keybindings are configured under wayland.windowManager.sway.config.keybindings
.
let..in
syntax is probably preferable to have access to special values like your modifier:
wayland.windowManager.sway.config.keybindings = let
cfg = config.wayland.windowManager.sway.config;
# Get the modifier key from the remaining config
modifier = cfg.modifier;
in {
# SUPER+Space = open the configured menu
"${modifier}+Space" = "exec ${cfg.menu}";
}