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
{pkgs, lib, config, ...}:

let
  cfg = config.profpatsch.user.profpatsch.xserver.windowManager.xmonad;


in {
  options = {
    profpatsch.user.profpatsch.xserver.windowManager.xmonad = {
      enable = lib.mkEnableOption "xmonad";

      package = lib.mkOption {
        default = pkgs.haskellPackages.xmonad;
        type = lib.types.package;
        description = ''
          Xmonad binary/package to use.
        '';
      };

      xmonadCliArgs = lib.mkOption {
        default = [];
        type = with lib.types; listOf str;
        description = ''
          Command line arguments passed to the xmonad binary.
        '';
      };

      updateSessionEnvironment = lib.mkOption {
        default = true;
        type = lib.types.bool;
        description = ''
          Whether to run dbus-update-activation-environment and systemctl import-environment before session start.
          Required for xdg portals to function properly.
        '';
      };

    };
  };
  config = lib.mkIf cfg.enable {
    services.xserver.windowManager = {
      session = [{
        name = "xmonad";
        start = ''
           ${lib.optionalString cfg.updateSessionEnvironment ''
              ${pkgs.systemd}/bin/systemctl --user import-environment PATH DISPLAY XAUTHORITY DESKTOP_SESSION XDG_CONFIG_DIRS XDG_DATA_DIRS XDG_RUNTIME_DIR XDG_SESSION_ID DBUS_SESSION_BUS_ADDRESS
              ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd --all
           ''}
           systemd-cat -t xmonad -- ${cfg.package}/bin/xmonad ${lib.escapeShellArgs cfg.xmonadCliArgs} &
           waitPID=$!
        '';
      }];
    };

    environment.systemPackages = [ cfg.package ];
  };
}