1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 xcfg = config.services.xserver;
8 cfg = xcfg.desktopManager;
9
10 # If desktop manager `d' isn't capable of setting a background and
11 # the xserver is enabled, `feh' or `xsetroot' are used as a fallback.
12 needBGCond = d: ! (d ? bgSupport && d.bgSupport) && xcfg.enable;
13
14in
15
16{
17 # Note: the order in which desktop manager modules are imported here
18 # determines the default: later modules (if enabled) are preferred.
19 # E.g., if Plasma 5 is enabled, it supersedes xterm.
20 imports = [
21 ./none.nix ./xterm.nix ./xfce.nix ./plasma5.nix ./lumina.nix
22 ./lxqt.nix ./enlightenment.nix ./gnome3.nix ./kodi.nix ./maxx.nix
23 ];
24
25 options = {
26
27 services.xserver.desktopManager = {
28
29 wallpaper = {
30 mode = mkOption {
31 type = types.enum [ "center" "fill" "max" "scale" "tile" ];
32 default = "scale";
33 example = "fill";
34 description = ''
35 The file <filename>~/.background-image</filename> is used as a background image.
36 This option specifies the placement of this image onto your desktop.
37
38 Possible values:
39 <literal>center</literal>: Center the image on the background. If it is too small, it will be surrounded by a black border.
40 <literal>fill</literal>: Like <literal>scale</literal>, but preserves aspect ratio by zooming the image until it fits. Either a horizontal or a vertical part of the image will be cut off.
41 <literal>max</literal>: Like <literal>fill</literal>, but scale the image to the maximum size that fits the screen with black borders on one side.
42 <literal>scale</literal>: Fit the file into the background without repeating it, cutting off stuff or using borders. But the aspect ratio is not preserved either.
43 <literal>tile</literal>: Tile (repeat) the image in case it is too small for the screen.
44 '';
45 };
46
47 combineScreens = mkOption {
48 type = types.bool;
49 default = false;
50 description = ''
51 When set to <literal>true</literal> the wallpaper will stretch across all screens.
52 When set to <literal>false</literal> the wallpaper is duplicated to all screens.
53 '';
54 };
55 };
56
57 session = mkOption {
58 internal = true;
59 default = [];
60 example = singleton
61 { name = "kde";
62 bgSupport = true;
63 start = "...";
64 };
65 description = ''
66 Internal option used to add some common line to desktop manager
67 scripts before forwarding the value to the
68 <varname>displayManager</varname>.
69 '';
70 apply = list: {
71 list = map (d: d // {
72 manage = "desktop";
73 start = d.start
74 + optionalString (needBGCond d) ''
75 if [ -e $HOME/.background-image ]; then
76 ${pkgs.feh}/bin/feh --bg-${cfg.wallpaper.mode} ${optionalString cfg.wallpaper.combineScreens "--no-xinerama"} $HOME/.background-image
77 else
78 # Use a solid black background as fallback
79 ${pkgs.xorg.xsetroot}/bin/xsetroot -solid black
80 fi
81 '';
82 }) list;
83 needBGPackages = [] != filter needBGCond list;
84 };
85 };
86
87 default = mkOption {
88 type = types.str;
89 default = "";
90 example = "none";
91 description = "Default desktop manager loaded if none have been chosen.";
92 apply = defaultDM:
93 if defaultDM == "" && cfg.session.list != [] then
94 (head cfg.session.list).name
95 else if any (w: w.name == defaultDM) cfg.session.list then
96 defaultDM
97 else
98 throw ''
99 Default desktop manager (${defaultDM}) not found.
100 Probably you want to change
101 services.xserver.desktopManager.default = "${defaultDM}";
102 to one of
103 ${concatMapStringsSep "\n " (w: "services.xserver.desktopManager.default = \"${w.name}\";") cfg.session.list}
104 '';
105 };
106
107 };
108
109 };
110
111 config = {
112 services.xserver.displayManager.session = cfg.session.list;
113 environment.systemPackages =
114 mkIf cfg.session.needBGPackages [ pkgs.feh ]; # xsetroot via xserver.enable
115 };
116}