aboutsummaryrefslogtreecommitdiffstats
path: root/modules/desktop/niri/default.nix
blob: 918a3dc4ed1a994160760ea32f93adfa40e09be9 (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
# Niri scrollable-tiling Wayland compositor and desktop essentials
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.desktop;
  base16Colors = import ../../colors/base16 { inherit config lib pkgs; };
in
{
  imports = [
    ./keybindings.nix
    ./assertions.nix
  ];

  options.desktop = {
    niri = lib.mkOption {
      type = lib.types.submodule {
        options = {
          package = lib.mkOption {
            type = lib.types.package;
            readOnly = true;
            default = config.wayland.windowManager.niri.package;
            description = "The niri package to use.";
          };
        };
      };
      default = { };
      description = "Niri window manager configuration.";
    };
    hardware.gpu = {
      nvidia = lib.mkOption {
        type = lib.types.submodule {
          options = {
            enable = lib.mkEnableOption "Nvidia GPU Wayland optimizations";
          };
        };
        default = { };
        description = "NVIDIA GPU configuration.";
      };
      amd = lib.mkOption {
        type = lib.types.submodule {
          options = {
            enable = lib.mkEnableOption "AMD GPU Wayland optimizations";
          };
        };
        default = { };
        description = "AMD GPU configuration.";
      };
    };
  };

  config = lib.mkIf cfg.enable {
    home.sessionVariables = lib.mkMerge [
      {
        NIXOS_OZONE_WL = "1";
        QT_QPA_PLATFORM = "wayland;xcb";
        SDL_VIDEODRIVER = "wayland";
        CLUTTER_BACKEND = "wayland";
        GDK_SCALE = "1";
        QT_SCALE_FACTOR = "1";
      }

      (lib.mkIf cfg.hardware.gpu.nvidia.enable {
        LIBVA_DRIVER_NAME = "nvidia";
        __GLX_VENDOR_LIBRARY_NAME = "nvidia";
        GBM_BACKEND = "nvidia-drm";
        __GL_YIELD = "USLEEP";
        __GL_VRR_ALLOWED = "0";
      })

      (lib.mkIf cfg.hardware.gpu.amd.enable {
        AMD_VULKAN_ICD = "RADV";
        MESA_VK_DEVICE_SELECT = "1002:";
      })
    ];

    wayland.windowManager.niri = {
      enable = true;
      systemd.enable = true;
      # Don't let Niri register its own portal. We will use xdg.portal for the
      # configuration of portal
      portalPackage = null;
    };

    # For setting the desktop wallpaper
    home.packages = [ pkgs.swaybg ];

    home.pointerCursor = {
      enable = true;
      package = pkgs.vimix-cursors;
      name = "Vimix-cursors";
      size = 20;
      gtk.enable = true;
      x11.enable = true;
    };

    wayland.windowManager.niri.settings = with base16Colors.colorsWithHashPrefix; {
      hotkey-overlay = {
        skip-at-startup = { };
      };
      input = {
        keyboard.xkb.layout = "us";
        touchpad = {
          natural-scroll = { };
          tap = { };
          dwt = { };
          click-method = "clickfinger";
          accel-speed = 0.5;
        };
      };
      layer-rule._children = [
        { "match namespace=\"^wallpaper$\"" = { }; }
        { place-within-backdrop = true; }
      ];
      layout = {
        gaps = 5;
        struts = {
          right = 60;
        };
        center-focused-column = "on-overflow";
        default-column-width = {
          proportion = 1.0;
        };
        background-color = "transparent";
        focus-ring = {
          width = 1;
          active-color = base07;
          inactive-color = base03;
        };
        border.off = { };
        shadow.off = { };
        preset-column-widths._children = [
          { proportion = 0.5; }
          { proportion = 1.0; }
        ];
      };
      prefer-no-csd = true;
      screenshot-path = "~/Pictures/Screenshots/Screenshot from %Y-%m-%d %H-%M-%S.png";
      animations.on = { };
      spawn-at-startup = [
        "${lib.getExe pkgs.swaybg}"
        "-i"
        "${../../../assets/sapling.png}"
        "-m"
        "fill"
      ];
    };

    desktop.rofi.action.actions = [
      {
        name = "Poweroff Monitors";
        command = "${lib.getExe cfg.niri.package} msg action power-off-monitors";
        icon = "network-vpn-symbolic";
      }
    ];
  };
}