Sway: Difference between revisions
→Using greeter: fixing package path + formatting |
|||
(21 intermediate revisions by 12 users not shown) | |||
Line 2: | Line 2: | ||
[https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide] | [https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide] | ||
== | == Setup == | ||
You can install Sway by enabling it in NixOS directly, or by using [[Home Manager]], or both. | You can install Sway by enabling it in NixOS directly, or by using [[Home Manager]], or both. | ||
Line 21: | Line 21: | ||
services.gnome.gnome-keyring.enable = true; | services.gnome.gnome-keyring.enable = true; | ||
# enable | # enable Sway window manager | ||
programs.sway = { | programs.sway = { | ||
enable = true; | enable = true; | ||
Line 27: | Line 27: | ||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight>By default, the Sway module in NixOS comes with a set of extra packages, including the <code>foot</code> terminal, <code>swayidle</code>, <code>swaylock</code>, and <code>wmenu</code>, which can be configured under <code>[https://search.nixos.org/options?show=programs.sway.extraPackages programs.sway.extraPackages]</code> option. You may also want to include <code>wl-clipboard</code> for clipboard functionality and <code>slurp</code> for screenshot region selection. Additionally, for a more customizable bar implementation than <code>sway-bar</code>, <code>waybar</code> can be enabled with <code>programs.waybar.enable</code>. | ||
The default Sway configuration is symlinked to <code>/etc/sway/config</code> and <code>/etc/sway/config.d/nixos.conf</code>. The latter file contains dbus and systemd configuration that is critical to using apps that depend on XDG desktop portals with Sway, and should be included in any custom configuration files. | |||
A few general comments: | A few general comments: | ||
* There is some friction between GTK theming and | * There is some friction between GTK theming and Sway. Currently the Sway developers suggest using gsettings to set gtk theme attributes as described here [https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland]. There is currently a plan to allow GTK theme attributes to be set directly in the Sway config. | ||
* Running | * Running Sway as a systemd user service is not recommended [https://github.com/swaywm/sway/wiki/Systemd-integration#running-sway-itself-as-a---user-service] [https://github.com/swaywm/sway/issues/5160] | ||
=== Using Home Manager === | === Using Home Manager === | ||
To set up Sway using [[Home Manager]], first you must enable [[Polkit]] in your | To set up Sway using [[Home Manager]], first you must enable [[Polkit]] in your NixOS configuration: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
security.polkit.enable = true; | security.polkit.enable = true; | ||
Line 43: | Line 45: | ||
wayland.windowManager.sway = { | wayland.windowManager.sway = { | ||
enable = true; | enable = true; | ||
wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps | |||
config = rec { | config = rec { | ||
modifier = "Mod4"; | modifier = "Mod4"; | ||
Line 59: | Line 62: | ||
You might need to active dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service] | You might need to active dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service] | ||
{{Note| | |||
It's recommended to enable a [[Secret Service]] provider, like GNOME Keyring: | |||
{{file| | {{file|home.nix|nix|<nowiki> | ||
services.gnome-keyring.enable = true; | |||
</nowiki>}} | </nowiki>}} | ||
}} | }} | ||
=== Systemd services === | === Systemd services === | ||
Kanshi is an output configuration daemon. As explained above, we don't run | Kanshi is an output configuration daemon. As explained above, we don't run Sway itself as a systemd service. There are auxiliary daemons that we do want to run as systemd services, for example Kanshi [https://sr.ht/~emersion/kanshi/], which implements monitor hot swapping. It would be enabled as follows: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
# kanshi systemd service | # kanshi systemd service | ||
systemd.user.services.kanshi = { | systemd.user.services.kanshi = { | ||
description = "kanshi daemon"; | description = "kanshi daemon"; | ||
environment = { | |||
WAYLAND_DISPLAY="wayland-1"; | |||
DISPLAY = ":0"; | |||
}; | |||
serviceConfig = { | serviceConfig = { | ||
Type = "simple"; | Type = "simple"; | ||
Line 93: | Line 87: | ||
{{file|sway config|bash| | {{file|sway config|bash| | ||
# give | # give Sway a little time to startup before starting kanshi. | ||
exec sleep 5; systemctl --user start kanshi.service | exec sleep 5; systemctl --user start kanshi.service | ||
}} | }} | ||
When you launch | When you launch Sway, the systemd service is started. | ||
=== Using greeter === | === Using greeter === | ||
Line 103: | Line 97: | ||
Tuigreet does not even need a separate compositor to launch. | Tuigreet does not even need a separate compositor to launch. | ||
{{file| | {{file|||<nowiki> | ||
services.greetd = { | services.greetd = { | ||
enable = true; | enable = true; | ||
settings = { | settings = { | ||
default_session = { | default_session = { | ||
command = "${pkgs | command = "${pkgs.tuigreet}/bin/tuigreet --time --cmd sway"; | ||
user = "greeter"; | user = "greeter"; | ||
}; | }; | ||
}; | }; | ||
}; | }; | ||
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | |||
=== Automatic startup on boot === | |||
The snippet below will start Sway immediately on startup, without a greeter and '''without login prompt'''. Only consider using this in conjunction with [[Full Disk Encryption]]! | |||
<syntaxhighlight lang="nix"> | |||
services.getty = { | |||
autologinUser = "your_username"; | |||
autologinOnce = true; | |||
}; | |||
environment.loginShellInit = '' | |||
[[ "$(tty)" == /dev/tty1 ]] && sway | |||
''; | |||
</syntaxhighlight> | |||
== Configuration == | |||
Sway can be configured for specific users using Home-Manager or manually through configuration files. Default is <code>/etc/sway/config</code> and custom user configuration in <code>~/.config/sway/config</code>. | |||
=== Keyboard layout === | |||
Changing layout for all keyboards to German (de):<syntaxhighlight lang="console"> | |||
input * xkb_layout "de" | |||
</syntaxhighlight>The same thing accomplished in Home Manager:<syntaxhighlight lang="nix"> | |||
wayland.windowManager.sway.input."*".xkb_layout = "de"; | |||
</syntaxhighlight> | |||
=== High-DPI scaling === | |||
Changing scale for all screens to factor 1.5:<syntaxhighlight lang="console"> | |||
output * scale 1.5 | |||
</syntaxhighlight> | |||
=== Brightness and volume === | |||
You can set up brightness and volume function keys as follows by binding the key codes to their corresponding commands in your sway config. The following configurations accomplish this using <code>light</code> and <code>pulseaudio</code>: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
users.users.yourusername.extraGroups = [ "video" ]; | |||
programs.light.enable = true; | |||
environment.systemPackages = [ pkgs.pulseaudio ]; | |||
</nowiki>}} | </nowiki>}} | ||
{{file|sway config|bash| | |||
# Brightness | |||
bindsym XF86MonBrightnessDown exec light -U 10 | |||
bindsym XF86MonBrightnessUp exec light -A 10 | |||
# Volume | |||
bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +1%' | |||
bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -1%' | |||
bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' | |||
}} | |||
== Troubleshooting == | |||
=== Cursor is missing icons or too tiny on HiDPI displays === | |||
Using [[Home Manager]] try configuring a general mouse cursor size and theme. The reason that your cursor might be missing in some applications, is because <code>XCURSOR_THEME</code>is missing, which will cause applications relying on <code>XWAYLAND</code> to misbehave. Setting <code>sway.enable = true</code>, combined with the <code>name</code>, <code>package</code> and size will set the correct environment variables, which sway will then use. | |||
<syntaxhighlight lang="nix">home-manager.users.myUser = { | |||
home.pointerCursor = { | home.pointerCursor = { | ||
name = "Adwaita"; | name = "Adwaita"; | ||
package = pkgs | package = pkgs.adwaita-icon-theme; | ||
size = 24; | size = 24; | ||
x11 = { | x11 = { | ||
Line 133: | Line 172: | ||
defaultCursor = "Adwaita"; | defaultCursor = "Adwaita"; | ||
}; | }; | ||
sway.enable = true; | |||
}; | }; | ||
};</syntaxhighlight> | |||
}; | |||
</syntaxhighlight> | |||
Replace <code>myUser</code> with your user running the graphical environment. | Replace <code>myUser</code> with your user running the graphical environment. | ||
Line 186: | Line 224: | ||
Enabling this option allows any program run by the "users" group to request real-time priority. | Enabling this option allows any program run by the "users" group to request real-time priority. | ||
=== WLR Error when trying to launch | === WLR Error when trying to launch Sway === | ||
When this happens on a new nixos system, enabling opengl in configuration.nix may fix this issue. | When this happens on a new nixos system, enabling opengl in configuration.nix may fix this issue. | ||
{{Note|<code>hardware.opengl</code> was renamed to <code>hardware.graphics</code> in NixOS 24.11.}} | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
hardware. | hardware.graphics.enable = true; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Touchscreen input bound to the wrong monitor in multi-monitor setups === | === Touchscreen input bound to the wrong monitor in multi-monitor setups === | ||
Using [[Home Manager]] | |||
See this [https://github.com/swaywm/sway/issues/6590#issue-1021207180 GitHub issue for Sway] and the solution give in [https://github.com/swaywm/sway/issues/6590#issuecomment-938724355 this response]. | |||
Using [[Home Manager]] add the following to your Sway configuration: | |||
<syntaxhighlight lang="nix"> | |||
wayland.windowManager.sway = { | wayland.windowManager.sway = { | ||
[...] | |||
config = { | config = { | ||
[...] | [...] | ||
Line 208: | Line 253: | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight> | |||
=== GTK apps take an exceptionally long time to start === | |||
This occurs because GTK apps make blocking calls to freedesktop portals to be displayed. If Sway is not integrated with dbus and systemd, it will not be able to communicate via the <code>org.freedesktop.portal.Desktop</code> portal. To fix this, see the [[Sway#Using NixOS|description]] of default Sway configurations earlier. Adding the following to your sway configuration, if it is not already present, may resolve the issue: | |||
include /etc/sway/config.d/* | |||
== Tips and tricks == | == Tips and tricks == |