1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.programs.dwl;
9in
10{
11 options.programs.dwl = {
12 enable = lib.mkEnableOption ''
13 Dwl is a compact, hackable compositor for Wayland based on wlroots.
14 You can manually launch Dwl by executing "exec dwl" on a TTY.
15 '';
16
17 package = lib.mkPackageOption pkgs "dwl" {
18 example = ''
19 # Lets apply bar patch from:
20 # https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/bar
21 (pkgs.dwl.override {
22 configH = ./dwl-config.h;
23 }).overrideAttrs (oldAttrs: {
24 buildInputs =
25 oldAttrs.buildInputs or []
26 ++ [
27 pkgs.libdrm
28 pkgs.fcft
29 ];
30 patches = oldAttrs.patches or [] ++ [
31 ./bar-0.7.patch
32 ];
33 });
34 '';
35 };
36
37 extraSessionCommands = lib.mkOption {
38 default = "";
39 type = lib.types.lines;
40 description = ''
41 Shell commands executed just before dwl is started.
42 '';
43 };
44 };
45
46 config = lib.mkIf cfg.enable {
47 environment.systemPackages = [ cfg.package ];
48
49 # Create systemd target for dwl session
50 systemd.user.targets.dwl-session = {
51 description = "dwl compositor session";
52 documentation = [ "man:systemd.special(7)" ];
53 bindsTo = [ "graphical-session.target" ];
54 wants = [ "graphical-session-pre.target" ];
55 after = [ "graphical-session-pre.target" ];
56 };
57
58 # Create wrapper script for dwl
59 environment.etc."xdg/dwl-session" = {
60 text = ''
61 #!${pkgs.runtimeShell}
62 # Import environment variables
63 ${cfg.extraSessionCommands}
64 # Setup systemd user environment
65 systemctl --user import-environment DISPLAY WAYLAND_DISPLAY
66 systemctl --user start dwl-session.target
67 # Start dwl
68 exec ${lib.getExe cfg.package}
69 '';
70 mode = "0755"; # Make it executable
71 };
72
73 # Create desktop entry for display managers
74 services.displayManager.sessionPackages =
75 let
76 dwlDesktopFile = pkgs.writeTextFile {
77 name = "dwl-desktop-entry";
78 destination = "/share/wayland-sessions/dwl.desktop";
79 text = ''
80 [Desktop Entry]
81 Name=dwl
82 Comment=Dynamic window manager for Wayland
83 Exec=/etc/xdg/dwl-session
84 Type=Application
85 '';
86 };
87
88 dwlSession = pkgs.symlinkJoin {
89 name = "dwl-session";
90 paths = [ dwlDesktopFile ];
91 passthru.providedSessions = [ "dwl" ];
92 };
93 in
94 [ dwlSession ];
95
96 # Configure XDG portal for dwl (minimal configuration)
97 xdg.portal.config.dwl.default = lib.mkDefault [
98 "wlr"
99 "gtk"
100 ];
101 };
102
103 meta.maintainers = with lib.maintainers; [ gurjaka ];
104}