2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.sway;
|
|
|
|
|
|
|
|
wrapperOptions = types.submodule {
|
|
|
|
options =
|
|
|
|
let
|
|
|
|
mkWrapperFeature = default: description: mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
inherit default;
|
|
|
|
example = !default;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to make use of the ${description}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
base = mkWrapperFeature true ''
|
|
|
|
base wrapper to execute extra session commands and prepend a
|
|
|
|
dbus-run-session to the sway command.
|
|
|
|
'';
|
|
|
|
gtk = mkWrapperFeature false ''
|
|
|
|
wrapGAppsHook wrapper to execute sway with required environment
|
|
|
|
variables for GTK applications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-09 11:40:11 +00:00
|
|
|
defaultSwayPackage = pkgs.sway.override {
|
2020-04-24 23:36:52 +00:00
|
|
|
extraSessionCommands = cfg.extraSessionCommands;
|
|
|
|
extraOptions = cfg.extraOptions;
|
|
|
|
withBaseWrapper = cfg.wrapperFeatures.base;
|
|
|
|
withGtkWrapper = cfg.wrapperFeatures.gtk;
|
2021-05-20 23:08:51 +00:00
|
|
|
isNixOS = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.programs.sway = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Sway, the i3-compatible tiling Wayland compositor. You can manually launch
|
|
|
|
Sway by executing "exec sway" on a TTY. Copy /etc/sway/config to
|
|
|
|
~/.config/sway/config to modify the default configuration. See
|
2022-09-09 14:08:57 +00:00
|
|
|
<https://github.com/swaywm/sway/wiki> and
|
|
|
|
"man 5 sway" for more information'');
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-09 11:40:11 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = with types; nullOr package;
|
|
|
|
default = defaultSwayPackage;
|
|
|
|
defaultText = literalExpression "pkgs.sway";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Sway package to use. Will override the options
|
|
|
|
'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'.
|
|
|
|
Set to <code>null</code> to not add any Sway package to your
|
|
|
|
path. This should be done if you want to use the Home Manager Sway
|
|
|
|
module to install Sway.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
wrapperFeatures = mkOption {
|
|
|
|
type = wrapperOptions;
|
|
|
|
default = { };
|
|
|
|
example = { gtk = true; };
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Attribute set of features to enable in the wrapper.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraSessionCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
2021-05-20 23:08:51 +00:00
|
|
|
# SDL:
|
2020-04-24 23:36:52 +00:00
|
|
|
export SDL_VIDEODRIVER=wayland
|
2021-05-20 23:08:51 +00:00
|
|
|
# QT (needs qt5.qtwayland in systemPackages):
|
|
|
|
export QT_QPA_PLATFORM=wayland-egl
|
2020-04-24 23:36:52 +00:00
|
|
|
export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
|
|
|
|
# Fix for some Java AWT applications (e.g. Android Studio),
|
|
|
|
# use this if they aren't displayed properly:
|
|
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 23:08:51 +00:00
|
|
|
Shell commands executed just before Sway is started. See
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/swaywm/sway/wiki/Running-programs-natively-under-wayland>
|
|
|
|
and <https://github.com/swaywm/wlroots/blob/master/docs/env_vars.md>
|
2021-05-20 23:08:51 +00:00
|
|
|
for some useful environment variables.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
"--verbose"
|
|
|
|
"--debug"
|
|
|
|
"--unsupported-gpu"
|
|
|
|
];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Command line arguments passed to launch Sway. Please DO NOT report
|
|
|
|
issues if you use an unsupported GPU (proprietary drivers).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = with pkgs; [
|
2022-01-25 03:21:06 +00:00
|
|
|
swaylock swayidle foot dmenu
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression ''
|
2022-01-25 03:21:06 +00:00
|
|
|
with pkgs; [ swaylock swayidle foot dmenu ];
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
with pkgs; [
|
|
|
|
i3status i3status-rust
|
|
|
|
termite rofi light
|
|
|
|
]
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 23:08:51 +00:00
|
|
|
Extra packages to be installed system wide. See
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway> and
|
|
|
|
<https://github.com/swaywm/sway/wiki/i3-Migration-Guide#common-x11-apps-used-on-i3-with-wayland-alternatives>
|
2021-05-20 23:08:51 +00:00
|
|
|
for a list of useful software.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base;
|
|
|
|
message = ''
|
|
|
|
The extraSessionCommands for Sway will not be run if
|
|
|
|
wrapperFeatures.base is disabled.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
environment = {
|
2023-02-09 11:40:11 +00:00
|
|
|
systemPackages = optional (cfg.package != null) cfg.package ++ cfg.extraPackages;
|
2021-12-06 16:07:01 +00:00
|
|
|
# Needed for the default wallpaper:
|
2023-02-09 11:40:11 +00:00
|
|
|
pathsToLink = optionals (cfg.package != null) [ "/share/backgrounds/sway" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
etc = {
|
2021-05-20 23:08:51 +00:00
|
|
|
"sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" ''
|
|
|
|
# Import the most important environment variables into the D-Bus and systemd
|
|
|
|
# user environments (e.g. required for screen sharing and Pinentry prompts):
|
|
|
|
exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP
|
|
|
|
'';
|
2023-02-09 11:40:11 +00:00
|
|
|
} // optionalAttrs (cfg.package != null) {
|
|
|
|
"sway/config".source = mkOptionDefault "${cfg.package}/etc/sway/config";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2022-03-05 16:20:37 +00:00
|
|
|
security.polkit.enable = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
security.pam.services.swaylock = {};
|
|
|
|
hardware.opengl.enable = mkDefault true;
|
|
|
|
fonts.enableDefaultFonts = mkDefault true;
|
|
|
|
programs.dconf.enable = mkDefault true;
|
|
|
|
# To make a Sway session available if a display manager like SDDM is enabled:
|
2023-02-09 11:40:11 +00:00
|
|
|
services.xserver.displayManager.sessionPackages = optionals (cfg.package != null) [ cfg.package ];
|
2020-10-07 09:15:18 +00:00
|
|
|
programs.xwayland.enable = mkDefault true;
|
2021-05-20 23:08:51 +00:00
|
|
|
# For screen sharing (this option only has an effect with xdg.portal.enable):
|
|
|
|
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ primeos colemickens ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|