1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.sway;
7 swayPackage = pkgs.sway;
8
9 swayWrapped = pkgs.writeShellScriptBin "sway" ''
10 if [[ "$#" -ge 1 ]]; then
11 exec sway-setcap "$@"
12 else
13 ${cfg.extraSessionCommands}
14 exec ${pkgs.dbus.dbus-launch} --exit-with-session sway-setcap
15 fi
16 '';
17 swayJoined = pkgs.symlinkJoin {
18 name = "sway-joined";
19 paths = [ swayWrapped swayPackage ];
20 };
21in {
22 options.programs.sway = {
23 enable = mkEnableOption ''
24 the tiling Wayland compositor Sway. After adding yourself to the "sway"
25 group you can manually launch Sway by executing "sway" from a terminal.
26 If you call "sway" with any parameters the extraSessionCommands won't be
27 executed and Sway won't be launched with dbus-launch'';
28
29 extraSessionCommands = mkOption {
30 type = types.lines;
31 default = "";
32 example = ''
33 # Define a keymap (US QWERTY is the default)
34 export XKB_DEFAULT_LAYOUT=de,us
35 export XKB_DEFAULT_VARIANT=nodeadkeys
36 export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle,caps:escape
37 # Change the Keyboard repeat delay and rate
38 export WLC_REPEAT_DELAY=660
39 export WLC_REPEAT_RATE=25
40 '';
41 description = ''
42 Shell commands executed just before Sway is started.
43 '';
44 };
45
46 extraPackages = mkOption {
47 type = with types; listOf package;
48 default = with pkgs; [
49 i3status xwayland rxvt_unicode dmenu
50 ];
51 defaultText = literalExample ''
52 with pkgs; [ i3status xwayland rxvt_unicode dmenu ];
53 '';
54 example = literalExample ''
55 with pkgs; [
56 i3lock light termite
57 ]
58 '';
59 description = ''
60 Extra packages to be installed system wide.
61 '';
62 };
63 };
64
65 config = mkIf cfg.enable {
66 environment.systemPackages = [ swayJoined ] ++ cfg.extraPackages;
67 security.wrappers.sway = {
68 program = "sway-setcap";
69 source = "${swayPackage}/bin/sway";
70 capabilities = "cap_sys_ptrace,cap_sys_tty_config=eip";
71 owner = "root";
72 group = "sway";
73 permissions = "u+rx,g+rx";
74 };
75
76 users.groups.sway = {};
77 security.pam.services.swaylock = {};
78
79 hardware.opengl.enable = mkDefault true;
80 fonts.enableDefaultFonts = mkDefault true;
81 programs.dconf.enable = mkDefault true;
82 };
83
84 meta.maintainers = with lib.maintainers; [ gnidorah primeos ];
85}