@@ -32,8 +32,32 @@ let
3232 ''
3333 #! ${pkgs.bash}/bin/bash
3434
35− # Handle being called by SDDM.
36− if test "''${1:0:1}" = / ; then eval exec "$1" "$2" ; fi
35+ # Expected parameters:
36+ # $1 = <desktop-manager>+<window-manager>
37+
38+ # Actual parameters (FIXME):
39+ # SDDM is calling this script like the following:
40+ # $1 = /nix/store/xxx-xsession (= $0)
41+ # $2 = <desktop-manager>+<window-manager>
42+ # SLiM is using the following parameter:
43+ # $1 = /nix/store/xxx-xsession <desktop-manager>+<window-manager>
44+ # LightDM keeps the double quotes:
45+ # $1 = /nix/store/xxx-xsession "<desktop-manager>+<window-manager>"
46+ # The fake/auto display manager doesn't use any parameters and GDM is
47+ # broken.
48+ # If you want to "debug" this script don't print the parameters to stdout
49+ # or stderr because this script will be executed multiple times and the
50+ # output won't be visible in the log when the script is executed for the
51+ # first time (e.g. append them to a file instead)!
52+
53+ # All of the above cases are handled by the following hack (FIXME).
54+ # Since this line is *very important* for *all display managers* it is
55+ # very important to test changes to the following line with all display
56+ # managers:
57+ if [ "''${1:0:1}" = "/" ]; then eval exec "$1" "$2" ; fi
58+
59+ # Now it should be safe to assume that the script was called with the
60+ # expected parameters.
3761
3862 ${optionalString cfg.displayManager.logToJournal ''
3963 if [ -z "$_DID_SYSTEMD_CAT" ]; then
@@ -107,11 +131,12 @@ let
107131 fi
108132 fi
109133
110− # The session type is "<desktop-manager> + <window-manager>", so
111− # extract those.
112− windowManager="''${sessionType##* + }"
134+ # The session type is "<desktop-manager>+<window-manager>", so
135+ # extract those (see:
136+ # http://wiki.bash-hackers.org/syntax/pe#substring_removal).
137+ windowManager="''${sessionType##*+}"
113138 : ''${windowManager:=${cfg.windowManager.default}}
114− desktopManager="''${sessionType% + *}"
139+ desktopManager="''${sessionType%%+*}"
115140 : ''${desktopManager:=${cfg.desktopManager.default}}
116141
117142 # Start the window manager.
@@ -142,6 +167,9 @@ let
142167 exit 0
143168 '';
144169
170+ # Desktop Entry Specification:
171+ # - https://standards.freedesktop.org/desktop-entry-spec/latest/
172+ # - https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
145173 mkDesktops = names: pkgs.runCommand "desktops"
146174 { # trivial derivation
147175 preferLocalBuild = true;
@@ -155,7 +183,7 @@ let
155183 Version=1.0
156184 Type=XSession
157185 TryExec=${cfg.displayManager.session.script}
158− Exec=${cfg.displayManager.session.script} '${n}'
186+ Exec=${cfg.displayManager.session.script} "${n}"
159187 X-GDM-BypassXsession=true
160188 Name=${n}
161189 Comment=
@@ -238,7 +266,7 @@ in
238266 wm = filter (s: s.manage == "window") list;
239267 dm = filter (s: s.manage == "desktop") list;
240268 names = flip concatMap dm
241− (d: map (w: d.name + optionalString (w.name != "none") (" + " + w.name))
269+ (d: map (w: d.name + optionalString (w.name != "none") ("+" + w.name))
242270 (filter (w: d.name != "none" || w.name != "none") wm));
243271 desktops = mkDesktops names;
244272 script = xsession wm dm;