* Cleaned up the display manager module a bit.

svn path=/nixos/trunk/; revision=17012
This commit is contained in:
Eelco Dolstra 2009-09-10 15:49:16 +00:00
parent 22693ae44e
commit 0156cfbe9e
3 changed files with 163 additions and 158 deletions

View File

@ -1,74 +1,82 @@
{pkgs, config, ...}: # This module declares the options to define a *display manager*, the
# program responsible for handling X logins (such as xdm, kdm, gdb, or
# SLiM). The display manager allows the user to select a *session
# type*. When the user logs in, the display manager starts the
# *session script* ("xsession" below) to launch the selected session
# type. The session type defines two things: the *desktop manager*
# (e.g., KDE, Gnome or a plain xterm), and optionally the *window
# manager* (e.g. kwin or twm).
{ config, pkgs, ... }:
with pkgs.lib;
let let
inherit (pkgs.lib) mkOption mergeOneOption optionals filter concatMap concatMapStrings;
cfg = config.services.xserver; cfg = config.services.xserver;
xorg = pkgs.xorg; xorg = pkgs.xorg;
# file provided by services.xserver.displayManager.session.script # file provided by services.xserver.displayManager.session.script
xsession = wm: dm: pkgs.writeScript "xsession" '' xsession = wm: dm: pkgs.writeScript "xsession"
''
#! /bin/sh #! /bin/sh
exec > $HOME/.xsession-errors 2>&1
source /etc/profile source /etc/profile
exec > $HOME/.Xerrors 2>&1
### Load X defaults. ### Load X defaults.
if test -e ~/.Xdefaults; then if test -e ~/.Xdefaults; then
${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults
fi fi
${if cfg.startSSHAgent then '' ${optionalString cfg.startSSHAgent ''
### Start the SSH agent. ### Start the SSH agent.
export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass
eval $(${pkgs.openssh}/bin/ssh-agent) eval $(${pkgs.openssh}/bin/ssh-agent)
'' else ""} ''}
### Allow user to override system-wide configuration ### Allow user to override system-wide configuration
if test -f ~/.xsession; then if test -f ~/.xsession; then
source ~/.xsession; source ~/.xsession
fi fi
# this script expect to have as first argument the following input # The first argument of this script is the session type
# "desktop-manager + window-manager". sessionType="$1"
arg="$1"
# extract the window manager. # The session type "<desktop-manager> + <window-manager>", so
# extract those.
windowManager="''${arg##* + }" windowManager="''${arg##* + }"
: ''${windowManager:=${cfg.windowManager.default}} : ''${windowManager:=${cfg.windowManager.default}}
# extract the desktop manager.
desktopManager="''${arg% + *}" desktopManager="''${arg% + *}"
: ''${desktopManager:=${cfg.desktopManager.default}} : ''${desktopManager:=${cfg.desktopManager.default}}
# used to restart the xserver. # Start the window manager.
waitPID=0
# handle window manager starts.
case $windowManager in case $windowManager in
${concatMapStrings (s: " ${concatMapStrings (s: ''
(${s.name}) (${s.name})
${s.start} ${s.start}
;; ;;
") wm} '') wm}
(*) echo "$0: Window manager '$windowManager' not found.";; (*) echo "$0: Window manager '$windowManager' not found.";;
esac esac
# handle desktop manager starts. # Start the desktop manager.
case $desktopManager in case $desktopManager in
${concatMapStrings (s: " ${concatMapStrings (s: ''
(${s.name}) (${s.name})
${s.start} ${s.start}
;; ;;
") dm} '') dm}
(*) echo "$0: Desktop manager '$desktopManager' not found.";; (*) echo "$0: Desktop manager '$desktopManager' not found.";;
esac esac
test "$waitPID" != 0 && wait "$waitPID" test -n "$waitPID" && wait "$waitPID"
exit exit 0
''; '';
mkDesktops = names: pkgs.runCommand "desktops" {} '' mkDesktops = names: pkgs.runCommand "desktops" {}
''
ensureDir $out ensureDir $out
${concatMapStrings (n: '' ${concatMapStrings (n: ''
cat - > "$out/${n}.desktop" << EODESKTOP cat - > "$out/${n}.desktop" << EODESKTOP
@ -86,41 +94,28 @@ let
in in
{ {
# list of display managers.
require = [
./kdm.nix
./slim.nix
];
services = { imports = [ ./kdm.nix ./slim.nix ];
xserver = {
displayManager = {
options = {
services.xserver.displayManager = {
xauthBin = mkOption { xauthBin = mkOption {
default = "${xorg.xauth}/bin/xauth"; default = "${xorg.xauth}/bin/xauth";
description = " description = "Path to the <command>xauth</command> program used by display managers.";
Path to the xauth binary used by display managers.
";
}; };
xserverBin = mkOption { xserverBin = mkOption {
default = "${xorg.xorgserver}/bin/X"; default = "${xorg.xorgserver}/bin/X";
description = " description = "Path to the X server used by display managers.";
Path to the xserver binary used by display managers.
";
}; };
xserverArgs = mkOption { xserverArgs = mkOption {
default = []; default = [];
example = [ example = [ "-ac" "-logverbose" "-nolisten tcp" ];
"-ac" description = "List of arguments for the X server.";
"-logverbose"
"-nolisten tcp"
];
description = "
List of arguments which have to be pass to when
the display manager start the xserver.
";
apply = toString; apply = toString;
}; };
@ -137,10 +132,10 @@ in
} }
]; ];
description = '' description = ''
List of session supported with the command used to start each List of sessions supported with the command used to start each
session. Each session script can set the session. Each session script can set the
<varname>waitPID</varname> shell variable to make this script <varname>waitPID</varname> shell variable to make this script
waiting until the end of the user session. Each script is used wait until the end of the user session. Each script is used
to define either a windows manager or a desktop manager. These to define either a windows manager or a desktop manager. These
can be differentiated by setting the attribute can be differentiated by setting the attribute
<varname>manage</varname> either to <literal>"window"</literal> <varname>manage</varname> either to <literal>"window"</literal>
@ -161,23 +156,35 @@ in
job = mkOption { job = mkOption {
default = {}; default = {};
example = { type = types.optionSet;
preStart = ''
rm -f /var/log/slim.log
'';
environment = { SLIM_CFGFILE = /etc/slim.conf; };
execCmd = "${pkgs.slim}/bin/slim";
};
description = "
List of arguments which have to be pass to when
the display manager start the xserver.
";
merge = mergeOneOption; merge = mergeOneOption;
description = "This option defines how to start the display manager.";
options = {
preStart = mkOption {
default = "";
example = "rm -f /var/log/my-display-manager.log";
description = "Script executed before the display manager is started.";
};
execCmd = mkOption {
example = "${pkgs.slim}/bin/slim";
description = "Command to start the display manager.";
};
environment = mkOption {
default = {};
example = { SLIM_CFGFILE = /etc/slim.conf; };
description = "Additional environment variables needed by the display manager.";
}; };
}; };
}; };
}; };
};
} }

View File

@ -73,9 +73,7 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.xserver.displayManager.job = services.xserver.displayManager.job =
{ beforeScript = ""; { execCmd = "${kdebase_workspace}/bin/kdm -config ${kdmrc}";
environment = {};
execCmd = "${kdebase_workspace}/bin/kdm -config ${kdmrc}";
}; };
security.pam.services = [ { name = "kde"; localLogin = true; ckHack = true; } ]; security.pam.services = [ { name = "kde"; localLogin = true; ckHack = true; } ];

View File

@ -378,7 +378,7 @@ in
else "" else ""
} }
${cfg.displayManager.job.beforeScript} ${cfg.displayManager.job.preStart}
rm -f /tmp/.X0-lock rm -f /tmp/.X0-lock
''; '';