1{
2 config,
3 lib,
4 pkgs,
5 utils,
6 ...
7}:
8
9with lib;
10
11let
12 cfg = config.services.xserver.desktopManager.xfce;
13 excludePackages = config.environment.xfce.excludePackages;
14
15in
16{
17 meta = {
18 maintainers = teams.xfce.members;
19 };
20
21 imports = [
22 # added 2019-08-18
23 # needed to preserve some semblance of UI familarity
24 # with original XFCE module
25 (mkRenamedOptionModule
26 [ "services" "xserver" "desktopManager" "xfce4-14" "extraSessionCommands" ]
27 [ "services" "xserver" "displayManager" "sessionCommands" ]
28 )
29
30 # added 2019-11-04
31 # xfce4-14 module removed and promoted to xfce.
32 # Needed for configs that used xfce4-14 module to migrate to this one.
33 (mkRenamedOptionModule
34 [ "services" "xserver" "desktopManager" "xfce4-14" "enable" ]
35 [ "services" "xserver" "desktopManager" "xfce" "enable" ]
36 )
37 (mkRenamedOptionModule
38 [ "services" "xserver" "desktopManager" "xfce4-14" "noDesktop" ]
39 [ "services" "xserver" "desktopManager" "xfce" "noDesktop" ]
40 )
41 (mkRenamedOptionModule
42 [ "services" "xserver" "desktopManager" "xfce4-14" "enableXfwm" ]
43 [ "services" "xserver" "desktopManager" "xfce" "enableXfwm" ]
44 )
45 (mkRenamedOptionModule
46 [ "services" "xserver" "desktopManager" "xfce" "extraSessionCommands" ]
47 [ "services" "xserver" "displayManager" "sessionCommands" ]
48 )
49 (mkRemovedOptionModule [ "services" "xserver" "desktopManager" "xfce" "screenLock" ] "")
50
51 # added 2022-06-26
52 # thunar has its own module
53 (mkRenamedOptionModule
54 [ "services" "xserver" "desktopManager" "xfce" "thunarPlugins" ]
55 [ "programs" "thunar" "plugins" ]
56 )
57 ];
58
59 options = {
60 services.xserver.desktopManager.xfce = {
61 enable = mkOption {
62 type = types.bool;
63 default = false;
64 description = "Enable the Xfce desktop environment.";
65 };
66
67 noDesktop = mkOption {
68 type = types.bool;
69 default = false;
70 description = "Don't install XFCE desktop components (xfdesktop and panel).";
71 };
72
73 enableXfwm = mkOption {
74 type = types.bool;
75 default = true;
76 description = "Enable the XFWM (default) window manager.";
77 };
78
79 enableScreensaver = mkOption {
80 type = types.bool;
81 default = true;
82 description = "Enable the XFCE screensaver.";
83 };
84
85 enableWaylandSession = mkEnableOption "the experimental Xfce Wayland session";
86
87 waylandSessionCompositor = mkOption {
88 type = lib.types.str;
89 default = "";
90 example = "wayfire";
91 description = ''
92 Command line to run a Wayland compositor, defaults to `labwc --startup`
93 if not specified. Note that `xfce4-session` will be passed to it as an
94 argument, see `startxfce4 --help` for details.
95
96 Some compositors do not have an option equivalent to labwc's `--startup`
97 and you might have to add xfce4-session somewhere in their configurations.
98 '';
99 };
100 };
101
102 environment.xfce.excludePackages = mkOption {
103 default = [ ];
104 example = literalExpression "[ pkgs.xfce.xfce4-volumed-pulse ]";
105 type = types.listOf types.package;
106 description = "Which packages XFCE should exclude from the default environment";
107 };
108 };
109
110 config = mkIf cfg.enable {
111 environment.systemPackages = utils.removePackagesByName (
112 with pkgs;
113 [
114 glib # for gsettings
115 gtk3.out # gtk-update-icon-cache
116
117 gnome-themes-extra
118 adwaita-icon-theme
119 hicolor-icon-theme
120 tango-icon-theme
121 xfce.xfce4-icon-theme
122
123 desktop-file-utils
124 shared-mime-info # for update-mime-database
125
126 # For a polkit authentication agent
127 polkit_gnome
128
129 # Needed by Xfce's xinitrc script
130 xdg-user-dirs # Update user dirs as described in https://freedesktop.org/wiki/Software/xdg-user-dirs/
131
132 xfce.exo
133 xfce.garcon
134 xfce.libxfce4ui
135
136 xfce.mousepad
137 xfce.parole
138 xfce.ristretto
139 xfce.xfce4-appfinder
140 xfce.xfce4-notifyd
141 xfce.xfce4-screenshooter
142 xfce.xfce4-session
143 xfce.xfce4-settings
144 xfce.xfce4-taskmanager
145 xfce.xfce4-terminal
146 ]
147 # TODO: NetworkManager doesn't belong here
148 ++ lib.optional config.networking.networkmanager.enable networkmanagerapplet
149 ++ lib.optional config.powerManagement.enable xfce.xfce4-power-manager
150 ++ lib.optionals (config.services.pulseaudio.enable || config.services.pipewire.pulse.enable) [
151 pavucontrol
152 # volume up/down keys support:
153 # xfce4-pulseaudio-plugin includes all the functionalities of xfce4-volumed-pulse
154 # but can only be used with xfce4-panel, so for no-desktop usage we still include
155 # xfce4-volumed-pulse
156 (if cfg.noDesktop then xfce.xfce4-volumed-pulse else xfce.xfce4-pulseaudio-plugin)
157 ]
158 ++ lib.optionals cfg.enableXfwm [
159 xfce.xfwm4
160 xfce.xfwm4-themes
161 ]
162 ++ lib.optionals (!cfg.noDesktop) [
163 xfce.xfce4-panel
164 xfce.xfdesktop
165 ]
166 ++ lib.optional cfg.enableScreensaver xfce.xfce4-screensaver
167 ) excludePackages;
168
169 programs.gnupg.agent.pinentryPackage = mkDefault pkgs.pinentry-gtk2;
170 programs.xfconf.enable = true;
171 programs.thunar.enable = true;
172 programs.labwc.enable = mkDefault (
173 cfg.enableWaylandSession
174 && (cfg.waylandSessionCompositor == "" || lib.substring 0 5 cfg.waylandSessionCompositor == "labwc")
175 );
176
177 environment.pathsToLink = [
178 "/share/xfce4"
179 "/lib/xfce4"
180 "/share/gtksourceview-3.0"
181 "/share/gtksourceview-4.0"
182 ];
183
184 services.xserver.desktopManager.session = [
185 {
186 name = "xfce";
187 prettyName = "Xfce Session";
188 desktopNames = [ "XFCE" ];
189 bgSupport = !cfg.noDesktop;
190 start = ''
191 ${pkgs.runtimeShell} ${pkgs.xfce.xfce4-session.xinitrc} &
192 waitPID=$!
193 '';
194 }
195 ];
196
197 # Copied from https://gitlab.xfce.org/xfce/xfce4-session/-/blob/xfce4-session-4.19.2/xfce-wayland.desktop.in
198 # to maintain consistent l10n state with X11 session file and to support the waylandSessionCompositor option.
199 services.displayManager.sessionPackages = optionals cfg.enableWaylandSession [
200 (
201 (pkgs.writeTextDir "share/wayland-sessions/xfce-wayland.desktop" ''
202 [Desktop Entry]
203 Version=1.0
204 Name=Xfce Session (Wayland)
205 Comment=Use this session to run Xfce as your desktop environment
206 Exec=startxfce4 --wayland ${cfg.waylandSessionCompositor}
207 Icon=
208 Type=Application
209 DesktopNames=XFCE
210 Keywords=xfce;wayland;desktop;environment;session;
211 '').overrideAttrs
212 (_: {
213 passthru.providedSessions = [ "xfce-wayland" ];
214 })
215 )
216 ];
217
218 services.xserver.updateDbusEnvironment = true;
219 programs.gdk-pixbuf.modulePackages = [ pkgs.librsvg ];
220
221 # Enable helpful DBus services.
222 services.udisks2.enable = true;
223 security.polkit.enable = true;
224 services.accounts-daemon.enable = true;
225 services.upower.enable = config.powerManagement.enable;
226 services.gnome.glib-networking.enable = true;
227 services.gvfs.enable = true;
228 services.tumbler.enable = true;
229 services.system-config-printer.enable = (mkIf config.services.printing.enable (mkDefault true));
230 services.libinput.enable = mkDefault true; # used in xfce4-settings-manager
231 services.colord.enable = mkDefault true;
232
233 # Enable default programs
234 programs.dconf.enable = true;
235
236 # Shell integration for VTE terminals
237 programs.bash.vteIntegration = mkDefault true;
238 programs.zsh.vteIntegration = mkDefault true;
239
240 # Systemd services
241 systemd.packages = utils.removePackagesByName (with pkgs.xfce; [
242 xfce4-notifyd
243 ]) excludePackages;
244
245 security.pam.services.xfce4-screensaver.unixAuth = cfg.enableScreensaver;
246
247 xdg.portal.configPackages = mkDefault [ pkgs.xfce.xfce4-session ];
248 };
249}