summaryrefslogtreecommitdiffstats
path: root/usecases/desktop/graphical/sway.nix
blob: 73e9aa40ff0a58fa0811cb9c18ee61e89594dccd (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
inputs:

{ config, lib, pkgs, system, ... }:
let
  globalConfig = config;
in
{
  services.greetd = {
    enable = true;
    settings.default_session.command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd sway";
  };

  home-manager.users.minijackson = { config, ... }: {
    wayland.windowManager.sway = {
      enable = true;

      extraSessionCommands = ''
        # https://github.com/emersion/xdg-desktop-portal-wlr/issues/20
        export XDG_CURRENT_DESKTOP=sway
        # https://github.com/emersion/xdg-desktop-portal-wlr/pull/11
        export XDG_SESSION_TYPE=wayland

        export SDL_VIDEODRIVER=wayland

        export QT_QPA_PLATFORM=wayland
        export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
      '';

      # Implemented below in startup, due to global import-environment failing
      # when not specifying variables.
      #
      # TODO: make PR
      systemdIntegration = false;
      wrapperFeatures.gtk = true;

      config = {
        # Using waybar
        bars = [ ];

        colors = with globalConfig.theme.colors; {
          focused = {
            border = lightBackground;
            background = lightBackground;
            text = foreground;
            indicator = dominant;
            childBorder = dominant;
          };

          focusedInactive = {
            border = background;
            background = background;
            text = dimForeground;
            indicator = dominant;
            childBorder = background;
          };

          unfocused = {
            border = background;
            background = background;
            text = dimForeground;
            indicator = dominant;
            childBorder = background;
          };

          urgent = {
            border = brightRed;
            background = brightRed;
            text = foreground;
            indicator = brightRed;
            childBorder = brightRed;
          };

          placeholder = {
            border = background0;
            background = background0;
            text = foreground;
            indicator = background0;
            childBorder = background0;
          };
        };

        floating.criteria = [
          { title = "Steam - News"; }
        ];

        input = {
          "1:1:AT_Translated_Set_2_keyboard" = {
            xkb_layout = "fr";
            xkb_variant = "oss";
            xkb_options = "compose:caps";
            xkb_numlock = "enabled";
          };

          "1452:514:Alps_Electric_M2452" = {
            xkb_layout = "fr";
            xkb_variant = "oss";
            xkb_options = "compose:caps,lv3:rwin_switch";
            xkb_numlock = "enabled";
          };

          "7764:8240:TypeMatrix.com_USB_Keyboard" = {
            xkb_layout = "dvorak";
            xkb_options = "eurosign:e,compose:caps";
            xkb_numlock = "enabled";
          };


          "1133:49948:Logitech_USB_Keyboard" = {
            xkb_layout = "fr";
            xkb_variant = "oss";
            xkb_options = "eurosign:e,compose:caps";
            xkb_numlock = "enabled";
          };

          "1102:4639:DELL0817:00_044E:121F_Mouse" = {
            scroll_method = "on_button_down";
            scroll_button = "button2";
          };
        };

        keybindings =
          let
            modifier = config.wayland.windowManager.sway.config.modifier;
          in
          lib.mkOptionDefault {
            "${modifier}+ampersand" = "workspace 1";
            "${modifier}+eacute" = "workspace 2";
            "${modifier}+quotedbl" = "workspace 3";
            "${modifier}+apostrophe" = "workspace 4";
            "${modifier}+parenleft" = "workspace 5";
            "${modifier}+minus" = "workspace 6";
            "${modifier}+egrave" = "workspace 7";
            "${modifier}+underscore" = "workspace 8";
            "${modifier}+ccedilla" = "workspace 9";
            "${modifier}+agrave" = "workspace 10";

            "${modifier}+Shift+ampersand" = "move container to workspace 1";
            "${modifier}+Shift+eacute" = "move container to workspace 2";
            "${modifier}+Shift+quotedbl" = "move container to workspace 3";
            "${modifier}+Shift+apostrophe" = "move container to workspace 4";
            "${modifier}+Shift+parenleft" = "move container to workspace 5";
            "${modifier}+Shift+minus" = "move container to workspace 6";
            "${modifier}+Shift+egrave" = "move container to workspace 7";
            "${modifier}+Shift+underscore" = "move container to workspace 8";
            "${modifier}+Shift+ccedilla" = "move container to workspace 9";
            "${modifier}+Shift+agrave" = "move container to workspace 10";

            "${modifier}+m" = "exec ${pkgs.swaylock}/bin/swaylock";

            "XF86AudioRaiseVolume" = "exec ${pkgs.pamixer}/bin/pamixer -i 5";
            "XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer -d 5";
            "XF86AudioMute" = "exec ${pkgs.pamixer}/bin/pamixer -t";
          };

        menu = ''
          ${pkgs.rofi}/bin/rofi -show drun -terminal ${pkgs.alacritty}/bin/alacritty
        '';

        modifier = "Mod4";

        output."*".bg =
          "${../../../res/wallpapers/wallpaper-1920x1080-kernel-card-black.png} fill";

        startup = [
          { command = "${pkgs.mako}/bin/mako"; always = true; }
          {
            command = "\"systemctl --user import-environment ${
              builtins.toString (lib.unique config.xsession.importedVariables)
            }; systemctl --user start sway-session.target\"";
          }
          { command = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1"; }
        ];

        terminal = "${pkgs.alacritty}/bin/alacritty";

        window = {
          border = 2;
          hideEdgeBorders = "smart";
        };
      };
    };

    services.wlsunset = {
      enable = true;
      latitude = "48.864716";
      longitude = "2.349014";
      # Reduce blue light anyways
      temperature = {
        day = 4000;
        night = 2500;
      };
      systemdTarget = "sway-session.target";
    };

    # TODO: upstream a PR to beautify this
    xdg.configFile."swaylock/config".text = with globalConfig.theme.colors; ''
      ignore-empty-password
      image=${../../../res/wallpapers/wallpaper-1920x1080-install-gentoo.png}

      font=monospace

      inside-color=${lib.removePrefix "#" dominant}dd
      inside-clear-color=${lib.removePrefix "#" neutralOrange}dd
      inside-ver-color=${lib.removePrefix "#" neutralOrange}dd
      inside-wrong-color=${lib.removePrefix "#" neutralRed}dd

      key-hl-color=${lib.removePrefix "#" brightGreen}ee
      bs-hl-color=${lib.removePrefix "#" neutralRed}ee

      line-color=${lib.removePrefix "#" background}ee
      line-clear-color=${lib.removePrefix "#" background}ee
      line-ver-color=${lib.removePrefix "#" background}ee
      line-wrong-color=${lib.removePrefix "#" background}ee

      ring-color=${lib.removePrefix "#" dominant}ee
      ring-clear-color=${lib.removePrefix "#" brightOrange}ee
      ring-ver-color=${lib.removePrefix "#" brightOrange}ee
      ring-wrong-color=${lib.removePrefix "#" brightRed}ee

      separator-color=${lib.removePrefix "#" background}ee

      text-color=${lib.removePrefix "#" background}ff
      text-clear-color=${lib.removePrefix "#" background}ff
      text-ver-color=${lib.removePrefix "#" background}ff
      text-wrong-color=${lib.removePrefix "#" background}ff

      indicator-radius=75
      indicator-thickness=10
    '';

    xsession.importedVariables = [
      "DBUS_SESSION_BUS_ADDRESS"
      "DISPLAY"
      "SSH_AUTH_SOCK"
      "XAUTHORITY"
      "XDG_DATA_DIRS"
      "XDG_RUNTIME_DIR"
      "XDG_SESSION_ID"

      "WAYLAND_DISPLAY"
      "SWAYSOCK"
      "I3SOCK"

      "XDG_CURRENT_DESKTOP"
      "XDG_SESSION_TYPE"
    ];

    systemd.user.targets.sway-session = {
      Unit = {
        Description = "sway compositor session";
        Documentation = [ "man:systemd.special(7)" ];
        BindsTo = [ "graphical-session.target" ];
        Wants = [ "graphical-session-pre.target" ];
        After = [ "graphical-session-pre.target" ];
      };
    };
  };

  # TODO: polkit gnome

  environment.systemPackages = with pkgs; [
    grim
    qt5.qtwayland
    slurp
    wl-clipboard
  ];

  programs.xwayland.enable = true;
  security.pam.services.swaylock = { };

  xdg.portal.extraPortals = with pkgs; [
    unstable.xdg-desktop-portal-wlr
  ];
}