about summary refs log tree commit diff
path: root/nixos/modules/programs/sway.nix
blob: 98257846d02f89eaff7745f182f928f1b8581aa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.programs.sway;
  sway = pkgs.sway;

  swayWrapped = pkgs.writeShellScriptBin "sway" ''
    if [ "$1" != "" ]; then
      sway-setcap "$@"
      exit
    fi
    ${cfg.extraSessionCommands}
    exec ${pkgs.dbus.dbus-launch} --exit-with-session sway-setcap
  '';
  swayJoined = pkgs.symlinkJoin {
    name = "sway-wrapped";
    paths = [ swayWrapped sway ];
  };
in
{
  options.programs.sway = {
    enable = mkEnableOption "sway";

    extraSessionCommands = mkOption {
      default     = "";
      type        = types.lines;
      example = ''
        export XKB_DEFAULT_LAYOUT=us,de
        export XKB_DEFAULT_VARIANT=,nodeadkeys
        export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle,
      '';
      description = ''
        Shell commands executed just before sway is started.
      '';
    };

    extraPackages = mkOption {
      type = with types; listOf package;
      default = with pkgs; [
        i3status xwayland rxvt_unicode dmenu
      ];
      example = literalExample ''
        with pkgs; [
          i3status xwayland rxvt_unicode dmenu
        ]
      '';
      description = ''
        Extra packages to be installed system wide.
      '';
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ swayJoined ] ++ cfg.extraPackages;
    security.wrappers.sway = {
      program = "sway-setcap";
      source = "${sway}/bin/sway";
      capabilities = "cap_sys_ptrace,cap_sys_tty_config=eip";
      owner = "root";
      group = "sway";
      permissions = "u+rx,g+rx";
    };

    users.extraGroups.sway = {};
    security.pam.services.swaylock = {};

    hardware.opengl.enable = mkDefault true;
    fonts.enableDefaultFonts = mkDefault true;
    programs.dconf.enable = mkDefault true;
  };
}