summaryrefslogtreecommitdiff
path: root/common/modules/dwm/default.nix
blob: 8141dbfc75919acc7df0ab8505900f6210253bdc (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
{
  homeManager,
  inputs,
  moduleNameSpace,
  ...
}:
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.${moduleNameSpace}.dwm;
in
{
  imports = lib.optionals homeManager [ ./picom.nix ];

  options.${moduleNameSpace}.dwm = {
    enable = lib.mkEnableOption "dwm setup";
    picom = {
      enable = lib.mkEnableOption "enable picom compositor";
      animations = lib.mkEnableOption "enable animations";
      shadow = lib.mkEnableOption "enable shadows";
      window = {
        opacity = {
          active = lib.mkOption {
            type = lib.types.float;
            default = 1.0;
          };
          inactive = lib.mkOption {
            type = lib.types.float;
            default = 1.0;
          };
        };
        blur = {
          enable = lib.mkEnableOption "Enable window blur";
          strength = lib.mkOption {
            type = lib.types.int;
            default = 1;
          };
          size = lib.mkOption {
            type = lib.types.int;
            default = 10;
          };
        };
      };
    };
  };

  config = lib.mkIf cfg.enable (
    if !homeManager then
      {
        services.xserver = {
          enable = true;
          autoRepeatDelay = 300;
          autoRepeatInterval = 20;
          excludePackages = with pkgs; [ xterm ];
          displayManager.sessionCommands = ''
            ${pkgs.systemd}/bin/systemctl --user import-environment DISPLAY XAUTHORITY XDG_SESSION_TYPE
            ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY XAUTHORITY XDG_SESSION_TYPE
          '';
          windowManager.dwm = {
            enable = true;
            package = inputs.mydwm.packages.${pkgs.stdenv.hostPlatform.system}.default;
          };
        };

        programs.ssh.askPassword = "";

        security.pam.services.betterlockscreen = { };
        security.pam.services.i3lock = { };

        programs.i3lock = {
          enable = true;
          package = pkgs.i3lock-color;
        };
      }
    else
      {
        xdg.dataFile."dwm/autostart.sh" = {
          executable = true;
          text = ''
            #!${pkgs.bash}/bin/bash

            gnome-keyring-daemon --start --components=secrets,ssh,pkcs11 &
            ${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1 &

            feh --no-fehbg --bg-fill "$(rg wallpaper ~/.config/beeSettings | cut -d"=" -f2)"
            [ -f ~/.Xresources ] && xrdb -merge ~/.Xresources

            dunst &
            clipcatd &
            slstatus &
            ${lib.optionalString (!cfg.picom.enable) ''
              xrandr --output eDP --set TearFree on
            ''}
            ${lib.optionalString (cfg.picom.enable) ''
              systemctl --user restart picom.service
            ''}

            systemctl --user restart xidlehook.service xautolock-session.service xss-lock.service clipcat.service
            ${lib.optionalString (config.beeMods.mango.waybar) ''
              systemctl --user stop waybar.service
            ''}
            ${lib.optionalString (config.beeMods.mango.enable) ''
              systemctl --user stop swayidle.service
            ''}
          '';
        };

        services.clipcat = {
          enable = true;
          daemonSettings = {
            daemonize = false;
            max_history = 50;
            desktop_notification = {
              enable = false;
            };
          };
          menuSettings = {
            server_endpoint = "/run/user/1000/clipcat/grpc.sock";
            finder = "rofi";

            rofi = {
              menu_length = 10;
              line_length = 100;
              menu_prompt = "Clipboard";
              extra_arguments = [ ];
            };
          };
        };

        services.screen-locker = {
          enable = true;
          inactiveInterval = 5;
          lockCmd = "${pkgs.betterlockscreen}/bin/betterlockscreen -l";

          xss-lock.extraOptions = [
            "-n"
            "--transfer-sleep-lock"
          ];
        };

        services.xidlehook = {
          enable = true;
          timers = [
            {
              delay = 270;
              command = "${pkgs.brightnessctl}/bin/brightnessctl g > /tmp/brightness_prev && ${pkgs.brightnessctl}/bin/brightnessctl set 10%";
              canceller = "${pkgs.brightnessctl}/bin/brightnessctl set $(${pkgs.coreutils}/bin/cat /tmp/brightness_prev 2>/dev/null || echo 100%)";
            }
            {
              delay = 900;
              command = "systemctl suspend";
              canceller = "";
            }
          ];
        };

        systemd.user.services.clipcat = {
          Unit = {
            ConditionEnvironment = [ "XDG_SESSION_TYPE=x11" ];
          };

        };
        systemd.user.services.xidlehook = {
          Unit = {
            ConditionEnvironment = [ "XDG_SESSION_TYPE=x11" ];
          };
        };

        systemd.user.services.xautolock-session = {
          Unit = {
            ConditionEnvironment = [ "XDG_SESSION_TYPE=x11" ];
          };
        };

        systemd.user.services.xss-lock = {
          Unit = {
            ConditionEnvironment = [ "XDG_SESSION_TYPE=x11" ];
          };
        };

        xresources.extraConfig = lib.mkIf config.beeMods.matugen.enable ''
          #include "${config.xdg.configHome}/x11/matugen.Xresources"
        '';
        xresources.properties = {
          "Xft.dpi" = 96;
          "Xft.autohint" = 0;
          "Xft.antialias" = true;
          "Xft.hinting" = true;
          "Xft.lcdfilter" = "lcddefault";
          "Xft.hintstyle" = "hintfull";
          "Xft.rgba" = "rgb";
          "st.font" =
            "${config.beeMods.terminal.font.family}:size=${toString config.beeMods.terminal.font.size}:antialias=true:autohint=true";
          "st.borderpx" = 5;
        };
      }
  );
}