1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 # Remove packages of ys from xs, based on their names
8 removePackagesByName = xs: ys:
9 let
10 pkgName = drv: (builtins.parseDrvName drv.name).name;
11 ysNames = map pkgName ys;
12 in
13 filter (x: !(builtins.elem (pkgName x) ysNames)) xs;
14
15 addToXDGDirs = p: ''
16 if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then
17 export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name}
18 fi
19
20 if [ -d "${p}/lib/girepository-1.0" ]; then
21 export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0
22 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib
23 fi
24 '';
25
26 xcfg = config.services.xserver;
27 cfg = xcfg.desktopManager.mate;
28
29in
30
31{
32 options = {
33
34 services.xserver.desktopManager.mate = {
35 enable = mkOption {
36 type = types.bool;
37 default = false;
38 description = "Enable the MATE desktop environment";
39 };
40
41 debug = mkEnableOption "mate-session debug messages";
42 };
43
44 environment.mate.excludePackages = mkOption {
45 default = [];
46 example = literalExample "[ pkgs.mate.mate-terminal pkgs.mate.pluma ]";
47 type = types.listOf types.package;
48 description = "Which MATE packages to exclude from the default environment";
49 };
50
51 };
52
53 config = mkIf (xcfg.enable && cfg.enable) {
54
55 services.xserver.desktopManager.session = singleton {
56 name = "mate";
57 bgSupport = true;
58 start = ''
59 # Set GTK_DATA_PREFIX so that GTK+ can find the themes
60 export GTK_DATA_PREFIX=${config.system.path}
61
62 # Find theme engines
63 export GTK_PATH=${config.system.path}/lib/gtk-3.0:${config.system.path}/lib/gtk-2.0
64
65 export XDG_MENU_PREFIX=mate-
66
67 # Find the mouse
68 export XCURSOR_PATH=~/.icons:${config.system.path}/share/icons
69
70 # Let caja find extensions
71 export CAJA_EXTENSION_DIRS=$CAJA_EXTENSION_DIRS''${CAJA_EXTENSION_DIRS:+:}${config.system.path}/lib/caja/extensions-2.0
72
73 # Let caja extensions find gsettings schemas
74 ${concatMapStrings (p: ''
75 if [ -d "${p}/lib/caja/extensions-2.0" ]; then
76 ${addToXDGDirs p}
77 fi
78 '')
79 config.environment.systemPackages
80 }
81
82 # Let mate-panel find applets
83 export MATE_PANEL_APPLETS_DIR=$MATE_PANEL_APPLETS_DIR''${MATE_PANEL_APPLETS_DIR:+:}${config.system.path}/share/mate-panel/applets
84 export MATE_PANEL_EXTRA_MODULES=$MATE_PANEL_EXTRA_MODULES''${MATE_PANEL_EXTRA_MODULES:+:}${config.system.path}/lib/mate-panel/applets
85
86 # Add mate-control-center paths to some XDG variables because its schemas are needed by mate-settings-daemon, and mate-settings-daemon is a dependency for mate-control-center (that is, they are mutually recursive)
87 ${addToXDGDirs pkgs.mate.mate-control-center}
88
89 # Update user dirs as described in http://freedesktop.org/wiki/Software/xdg-user-dirs/
90 ${pkgs.xdg-user-dirs}/bin/xdg-user-dirs-update
91
92 ${pkgs.mate.mate-session-manager}/bin/mate-session ${optionalString cfg.debug "--debug"} &
93 waitPID=$!
94 '';
95 };
96
97 environment.systemPackages =
98 pkgs.mate.basePackages ++
99 (removePackagesByName
100 pkgs.mate.extraPackages
101 config.environment.mate.excludePackages);
102
103 services.dbus.packages = [
104 pkgs.gnome3.dconf
105 pkgs.at-spi2-core
106 ];
107
108 services.gnome3.gnome-keyring.enable = true;
109 services.upower.enable = config.powerManagement.enable;
110
111 security.pam.services."mate-screensaver".unixAuth = true;
112
113 environment.pathsToLink = [ "/share" ];
114 };
115
116}