From b2b6f92d6bec57671a9e507e84d66f59fb4e5656 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:49:08 +0000 Subject: [PATCH] Split xserver upstart job into: - xserver configuration & job - display manager (slim) - window manager (compiz, kwm, metacity, twm, wmii, xmonad) - desktop manager (kde, gnome, xterm) Added features: - Add WM choice in slim (with F1) svn path=/nixos/branches/fix-style/; revision=13857 --- system/options.nix | 2 +- .../{xserver.nix => xserver/default.nix} | 396 ++++-------------- .../xserver/desktopManager/default.nix | 76 ++++ upstart-jobs/xserver/desktopManager/gnome.nix | 47 +++ upstart-jobs/xserver/desktopManager/kde.nix | 65 +++ upstart-jobs/xserver/desktopManager/none.nix | 14 + upstart-jobs/xserver/desktopManager/xterm.nix | 44 ++ .../xserver/displayManager/default.nix | 172 ++++++++ upstart-jobs/xserver/displayManager/slim.nix | 112 +++++ upstart-jobs/xserver/windowManager/compiz.nix | 64 +++ .../xserver/windowManager/default.nix | 61 +++ upstart-jobs/xserver/windowManager/kwm.nix | 46 ++ .../xserver/windowManager/metacity.nix | 49 +++ upstart-jobs/xserver/windowManager/none.nix | 12 + upstart-jobs/xserver/windowManager/twm.nix | 44 ++ upstart-jobs/xserver/windowManager/wmii.nix | 32 ++ upstart-jobs/xserver/windowManager/xmonad.nix | 32 ++ upstart-jobs/{ => xserver}/xserver.conf | 0 18 files changed, 948 insertions(+), 320 deletions(-) rename upstart-jobs/{xserver.nix => xserver/default.nix} (60%) create mode 100644 upstart-jobs/xserver/desktopManager/default.nix create mode 100644 upstart-jobs/xserver/desktopManager/gnome.nix create mode 100644 upstart-jobs/xserver/desktopManager/kde.nix create mode 100644 upstart-jobs/xserver/desktopManager/none.nix create mode 100644 upstart-jobs/xserver/desktopManager/xterm.nix create mode 100644 upstart-jobs/xserver/displayManager/default.nix create mode 100644 upstart-jobs/xserver/displayManager/slim.nix create mode 100644 upstart-jobs/xserver/windowManager/compiz.nix create mode 100644 upstart-jobs/xserver/windowManager/default.nix create mode 100644 upstart-jobs/xserver/windowManager/kwm.nix create mode 100644 upstart-jobs/xserver/windowManager/metacity.nix create mode 100644 upstart-jobs/xserver/windowManager/none.nix create mode 100644 upstart-jobs/xserver/windowManager/twm.nix create mode 100644 upstart-jobs/xserver/windowManager/wmii.nix create mode 100644 upstart-jobs/xserver/windowManager/xmonad.nix rename upstart-jobs/{ => xserver}/xserver.conf (100%) diff --git a/system/options.nix b/system/options.nix index f23adf9e7cf..6adb1ffb226 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2246,7 +2246,7 @@ in (import ../upstart-jobs/hal.nix) (import ../upstart-jobs/gpm.nix) (import ../upstart-jobs/nagios/default.nix) - (import ../upstart-jobs/xserver.nix) + (import ../upstart-jobs/xserver/default.nix) (import ../upstart-jobs/zabbix-agent.nix) (import ../upstart-jobs/zabbix-server.nix) (import ../upstart-jobs/disnix.nix) diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver/default.nix similarity index 60% rename from upstart-jobs/xserver.nix rename to upstart-jobs/xserver/default.nix index 9064ec15310..0a7a70c7175 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver/default.nix @@ -66,6 +66,7 @@ let "; }; +/* sessionType = mkOption { default = "gnome"; example = "xterm"; @@ -91,14 +92,6 @@ let "; }; - renderingFlag = mkOption { - default = ""; - example = "--indirect-rendering"; - description = " - Possibly pass --indierct-rendering to Compiz. - "; - }; - sessionStarter = mkOption { example = "${pkgs.xterm}/bin/xterm -ls"; description = " @@ -107,6 +100,7 @@ let is empty. "; }; +*/ startSSHAgent = mkOption { default = true; @@ -118,41 +112,6 @@ let "; }; - slim = { - - theme = mkOption { - default = null; - example = pkgs.fetchurl { - url = http://download.berlios.de/slim/slim-wave.tar.gz; - sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy"; - }; - description = " - The theme for the SLiM login manager. If not specified, SLiM's - default theme is used. See for a - collection of themes. - "; - }; - - defaultUser = mkOption { - default = ""; - example = "login"; - description = " - The default user to load. If you put a username here you - get it automatically loaded into the username field, and - the focus is placed on the password. - "; - }; - - hideCursor = mkOption { - default = false; - example = true; - description = " - Hide the mouse cursor on the login screen. - "; - }; - }; - isClone = mkOption { default = true; example = false; @@ -327,7 +286,6 @@ let # Abbreviations. cfg = config.services.xserver; xorg = cfg.package; - gnome = pkgs.gnome; stdenv = pkgs.stdenv; knownVideoDrivers = { @@ -344,25 +302,9 @@ let # Get a bunch of user settings. videoDriver = cfg.videoDriver; resolutions = map (res: ''"${toString res.x}x${toString res.y}"'') (cfg.resolutions); - sessionType = cfg.sessionType; videoDriverModules = getAttr [ videoDriver ] (throw "unkown video driver : \"${videoDriver}\"") knownVideoDrivers; - sessionCmd = - if sessionType == "" then cfg.sessionStarter else - if sessionType == "xterm" then "${pkgs.xterm}/bin/xterm -ls" else - if sessionType == "gnome" then "${gnome.gnometerminal}/bin/gnome-terminal -ls" else - abort ("unknown session type ${sessionType}"); - - - windowManager = - let wm = cfg.windowManager; in - if wm != "" then wm else - if sessionType == "gnome" then "metacity" else - if sessionType == "kde" then "none" /* started by startkde */ else - "twm"; - - modules = getAttr ["modulesFirst"] [] videoDriverModules @@ -518,244 +460,7 @@ let }; - clientScript = pkgs.writeText "xclient" '' - - source /etc/profile - - exec > $HOME/.Xerrors 2>&1 - - - ### Load X defaults. - if test -e ~/.Xdefaults; then - ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults - fi - - - ${if cfg.startSSHAgent then '' - ### Start the SSH agent. - export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass - eval $(${pkgs.openssh}/bin/ssh-agent) - '' else ""} - - ### Allow user to override system-wide configuration - if test -f ~/.xsession; then - source ~/.xsession; - fi - - - ### Start a window manager. - - ${if windowManager == "twm" then '' - ${xorg.twm}/bin/twm & - '' - - else if windowManager == "metacity" then '' - env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ - # !!! Hack: load the schemas for Metacity. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ - --makefile-install-rule ${gnome.metacity}/etc/gconf/schemas/*.schemas # */ - ${gnome.metacity}/bin/metacity & - '' - - else if windowManager == "kwm" then '' - ${pkgs.kdebase}/bin/kwin & - '' - - else if windowManager == "compiz" then '' - # !!! Hack: load the schemas for Compiz. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ - --makefile-install-rule ${pkgs.compiz}/etc/gconf/schemas/*.schemas # */ - - # !!! Hack: turn on most Compiz modules. - ${gnome.GConf}/bin/gconftool-2 -t list --list-type=string \ - --set /apps/compiz/general/allscreens/options/active_plugins \ - [gconf,png,decoration,wobbly,fade,minimize,move,resize,cube,switcher,rotate,place,scale,water] - - # Start Compiz and the GTK-style window decorator. - env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ - ${pkgs.compiz}/bin/compiz gconf ${cfg.renderingFlag} & - ${pkgs.compiz}/bin/gtk-window-decorator --sync & - '' - - else if windowManager == "xmonad" then '' - ${pkgs.xmonad}/bin/xmonad & - '' - - else if windowManager == "wmii" then '' - ${pkgs.wmiiSnap}/bin/wmii & - '' - - else if windowManager == "none" then '' - # The session starter will start the window manager. - '' - - else abort ("unknown window manager " + windowManager)} - WMpid=$! - - ### Show a background image. - # (but not if we're starting a full desktop environment that does it for us) - ${if sessionType != "kde" then '' - - if test -e $HOME/.background-image; then - ${pkgs.feh}/bin/feh --bg-scale $HOME/.background-image - fi - - '' else ""} - - - ### Start the session. - ${if sessionType == "kde" then '' - - # Start KDE. - export KDEDIRS=$HOME/.nix-profile:/nix/var/nix/profiles/default:${pkgs.kdebase}:${pkgs.kdelibs} - export XDG_CONFIG_DIRS=${pkgs.kdebase}/etc/xdg:${pkgs.kdelibs}/etc/xdg - export XDG_DATA_DIRS=${pkgs.kdebase}/share - exec ${pkgs.kdebase}/bin/startkde - - '' else '' - - # For all other session types, we currently just start a - # terminal of the kind indicated by sessionCmd. - # !!! yes, this means that you 'log out' by killing the X server. - while ${sessionCmd}; do - sleep 1 - done - - ''} - - ''; - - - xserverArgs = [ - "-ac" - "-logverbose" - "-verbose" - "-terminate" - "-logfile" "/var/log/X.${toString cfg.display}.log" - "-config ${configFile}" - ":${toString cfg.display}" "vt${toString cfg.tty}" - "-xkbdir" "${pkgs.xkeyboard_config}/etc/X11/xkb" - ] ++ optional (!config.services.xserver.tcpEnable) "-nolisten tcp"; - - - slimConfig = pkgs.writeText "slim.cfg" '' - xauth_path ${xorg.xauth}/bin/xauth - default_xserver ${xorg.xorgserver}/bin/X - xserver_arguments ${toString xserverArgs} - login_cmd exec ${stdenv.bash}/bin/sh ${clientScript} - halt_cmd ${pkgs.upstart}/sbin/shutdown -h now - reboot_cmd ${pkgs.upstart}/sbin/shutdown -r now - ${if cfg.slim.defaultUser != "" then "default_user " + cfg.slim.defaultUser else ""} - ${if cfg.slim.hideCursor then "hidecursor true" else ""} - ''; - - - # Unpack the SLiM theme, or use the default. - slimThemesDir = - let - unpackedTheme = stdenv.mkDerivation { - name = "slim-theme"; - buildCommand = '' - ensureDir $out - cd $out - unpackFile ${cfg.slim.theme} - ln -s * default - ''; - }; - in if cfg.slim.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme; - - nvidiaDrivers = (config.boot.kernelPackages pkgs).nvidiaDrivers; - - oldJob = rec { - # Warning the indentation is wrong since here in order to don't produce noise in diffs. - - name = "xserver"; - - - extraPath = [ - xorg.xrandr - xorg.xrdb - xorg.setxkbmap - xorg.iceauth # required for KDE applications (it's called by dcopserver) - pkgs.feh - ] - ++ optional (windowManager == "twm") [ - xorg.twm - ] - ++ optional (windowManager == "metacity") [ - gnome.metacity - ] - ++ optional (windowManager == "compiz") [ - pkgs.compiz - ] - ++ optional (sessionType == "xterm") [ - pkgs.xterm - ] - ++ optional (sessionType == "gnome") [ - gnome.gnometerminal - gnome.GConf - gnome.gconfeditor - ] - ++ optional (sessionType == "kde") [ - pkgs.kdelibs - pkgs.kdebase - xorg.xset # used by startkde, non-essential - ] - ++ optional (videoDriver == "nvidia") [ - kernelPackages.nvidiaDrivers - ]; - - - extraEtc = - optional (sessionType == "kde") - { source = "${pkgs.xkeyboard_config}/etc/X11/xkb"; - target = "X11/xkb"; - } - ++ - optional cfg.exportConfiguration - { source = "${configFile}"; - target = "X11/xorg.conf"; - }; - - - job = '' - start on ${if cfg.autorun then "network-interfaces" else "never"} - - start script - - rm -f /var/run/opengl-driver - ${if videoDriver == "nvidia" - then '' - ln -sf ${kernelPackages.nvidiaDrivers} /var/run/opengl-driver - '' - else if cfg.driSupport - then "ln -sf ${pkgs.mesa} /var/run/opengl-driver" - else "" - } - - rm -f /var/log/slim.log - - end script - - env SLIM_CFGFILE=${slimConfig} - env SLIM_THEMESDIR=${slimThemesDir} - env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup - env XKB_BINDIR=${xorg.xkbcomp}/bin # Needed for the Xkb extension. - - ${if videoDriver == "nvidia" - then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${kernelPackages.nvidiaDrivers}/lib" - else "" - } - - ${if videoDriver != "nvidia" - then "env XORG_DRI_DRIVER_PATH=${pkgs.mesa}/lib/modules/dri" - else "" - } - - exec ${pkgs.slim}/bin/slim - ''; - -}; + nvidiaDrivers = (config.boot.kernelPackages pkgs).nvidiaDrivers; in @@ -763,14 +468,19 @@ mkIf cfg.enable { require = [ options + # services.xserver.*Manager + (import ./displayManager/default.nix) + (import ./windowManager/default.nix) + (import ./desktopManager/default.nix) + # services.extraJobs - (import ../upstart-jobs/default.nix) + (import ../../upstart-jobs/default.nix) # environment.etc - (import ../etc/default.nix) + (import ../../etc/default.nix) # fonts.fonts - (import ../system/fonts.nix) + (import ../../system/fonts.nix) # boot.extraModulePackages # security.extraSetuidPrograms @@ -783,29 +493,77 @@ mkIf cfg.enable { ]; }; - security = { - extraSetuidPrograms = mkIf (cfg.sessionType == "kde") [ - "kcheckpass" + environment = { + etc = mkIf cfg.exportConfiguration [ + { source = "${configFile}"; + target = "X11/xorg.conf"; + } + ]; + + extraPackages = [ + xorg.xrandr + xorg.xrdb + xorg.setxkbmap + xorg.iceauth # required for KDE applications (it's called by dcopserver) + ] + ++ optional (videoDriver == "nvidia") [ + kernelPackages.nvidiaDrivers ]; }; - environment = { - etc = [ - { source = ../etc/pam.d/kde; - target = "pam.d/kde"; - } - { source = ../etc/pam.d/slim; - target = "pam.d/slim"; - } - ] ++ oldJob.extraEtc; - - extraPackages = - oldJob.extraPath; - }; - services = { + xserver = { + displayManager = { + xserverArgs = [ + "-ac" + "-logverbose" + "-verbose" + "-terminate" + "-logfile" "/var/log/X.${toString cfg.display}.log" + "-config ${configFile}" + ":${toString cfg.display}" "vt${toString cfg.tty}" + "-xkbdir" "${pkgs.xkeyboard_config}/etc/X11/xkb" + ] ++ optional (!cfg.tcpEnable) "-nolisten tcp"; + }; + }; + extraJobs = [{ - inherit (oldJob) name job; + name = "xserver"; + job = '' + start on ${if cfg.autorun then "network-interfaces" else "never"} + + start script + + rm -f /var/run/opengl-driver + ${if videoDriver == "nvidia" + then '' + ln -sf ${kernelPackages.nvidiaDrivers} /var/run/opengl-driver + '' + else if cfg.driSupport + then "ln -sf ${pkgs.mesa} /var/run/opengl-driver" + else "" + } + + ${cfg.displayManager.job.beforeScript} + + end script + + ${cfg.displayManager.job.env} + env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup + env XKB_BINDIR=${xorg.xkbcomp}/bin # Needed for the Xkb extension. + + ${if videoDriver == "nvidia" + then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${kernelPackages.nvidiaDrivers}/lib" + else "" + } + + ${if videoDriver != "nvidia" + then "env XORG_DRI_DRIVER_PATH=${pkgs.mesa}/lib/modules/dri" + else "" + } + + exec ${cfg.displayManager.job.execCmd} + ''; }]; }; } diff --git a/upstart-jobs/xserver/desktopManager/default.nix b/upstart-jobs/xserver/desktopManager/default.nix new file mode 100644 index 00000000000..73b0308bea2 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/default.nix @@ -0,0 +1,76 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption mkIf filter optionalString any; + cfg = config.services.xserver.desktopManager; + + needBGCond = d: ! (d ? bgSupport && d.bgSupport); +in + +{ + require = [ + (import ./kde.nix) + (import ./gnome.nix) + (import ./xterm.nix) + (import ./none.nix) + ]; + + services = { + xserver = { + displayManager = { + session = cfg.session.list; + }; + + desktopManager = { + session = mkOption { + default = []; + example = [{ + name = "kde"; + bgSupport = true; + start = "..."; + }]; + description = " + Internal option used to add some common line to desktop manager + scripts before forwarding the value to the + displayManager. + "; + apply = list: { + list = map (d: d // { + manage = "desktop"; + start = d.start + + optionalString (needBGCond d) '' + if test -e $HOME/.background-image; then + ${pkgs.feh}/bin/feh --bg-scale $HOME/.background-image + fi + ''; + }) list; + needBGPackages = [] != filter needBGCond list; + }; + }; + + + + default = mkOption { + default = "xterm"; + example = "none"; + description = " + Default desktop manager loaded if none have been chosen. + "; + merge = name: list: + let defaultDM = head list; in + if tail list != [] then + throw "Only one default desktop manager is allowed." + else if any (w: w.name == defaultDM) cfg.session.list then + defaultDM + else + throw "Default desktop manager not found."; + }; + }; + }; + }; + + environment = mkIf cfg.session.needBGPackages { + extraPackages = [ pkgs.feh ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/gnome.nix b/upstart-jobs/xserver/desktopManager/gnome.nix new file mode 100644 index 00000000000..d6fa064ef11 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/gnome.nix @@ -0,0 +1,47 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.gnome; + gnome = pkgs.gnome; + + options = { services = { xserver = { desktopManager = { + + gnome = { + enable = mkOption { + default = false; + example = true; + description = "Enable a gnome terminal as a desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "gnome"; + start = '' + ${gnome.gnometerminal}/bin/gnome-terminal -ls & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + gnome.gnometerminal + gnome.GConf + gnome.gconfeditor + ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/kde.nix b/upstart-jobs/xserver/desktopManager/kde.nix new file mode 100644 index 00000000000..9a241d77985 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/kde.nix @@ -0,0 +1,65 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.kde; + xorg = config.services.xserver.package; + + options = { services = { xserver = { desktopManager = { + + kde = { + enable = mkOption { + default = false; + example = true; + description = "Enable the kde desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "kde"; + start = '' + # Start KDE. + export KDEDIRS=$HOME/.nix-profile:/nix/var/nix/profiles/default:${pkgs.kdebase}:${pkgs.kdelibs} + export XDG_CONFIG_DIRS=${pkgs.kdebase}/etc/xdg:${pkgs.kdelibs}/etc/xdg + export XDG_DATA_DIRS=${pkgs.kdebase}/share + exec ${pkgs.kdebase}/bin/startkde + ''; + }]; + }; + + }; + }; + + security = { + extraSetuidPrograms = [ + "kcheckpass" + ]; + }; + + environment = { + extraPackages = [ + pkgs.kdelibs + pkgs.kdebase + xorg.xset # used by startkde, non-essential + ]; + + etc = [ + { source = ../../../etc/pam.d/kde; + target = "pam.d/kde"; + } + { source = "${pkgs.xkeyboard_config}/etc/X11/xkb"; + target = "X11/xkb"; + } + ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/none.nix b/upstart-jobs/xserver/desktopManager/none.nix new file mode 100644 index 00000000000..a86bd5a7415 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/none.nix @@ -0,0 +1,14 @@ +{ + services = { + xserver = { + + desktopManager = { + session = [{ + name = "none"; + start = ""; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/xterm.nix b/upstart-jobs/xserver/desktopManager/xterm.nix new file mode 100644 index 00000000000..e8aa0d289cb --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/xterm.nix @@ -0,0 +1,44 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.xterm; + + options = { services = { xserver = { desktopManager = { + + xterm = { + enable = mkOption { + default = false; + example = true; + description = "Enable a xterm terminal as a desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "xterm"; + start = '' + ${pkgs.xterm}/bin/xterm -ls & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + pkgs.xterm + ]; + }; +} diff --git a/upstart-jobs/xserver/displayManager/default.nix b/upstart-jobs/xserver/displayManager/default.nix new file mode 100644 index 00000000000..2699e34ecad --- /dev/null +++ b/upstart-jobs/xserver/displayManager/default.nix @@ -0,0 +1,172 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption optionals filter concatMap concatMapStrings; + cfg = config.services.xserver; + xorg = cfg.package; + + # file provided by services.xserver.displayManager.session.script + xsession = wm: dm: pkgs.writeText "xsession" '' + + source /etc/profile + + exec > $HOME/.Xerrors 2>&1 + + + ### Load X defaults. + if test -e ~/.Xdefaults; then + ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults + fi + + ${if cfg.startSSHAgent then '' + ### Start the SSH agent. + export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass + eval $(${pkgs.openssh}/bin/ssh-agent) + '' else ""} + + ### Allow user to override system-wide configuration + if test -f ~/.xsession; then + source ~/.xsession; + fi + + # this script expect to have as first argument the following input + # "desktop-manager + window-manager". + arg="$1" + + # extract the window manager. + windowManager="''${arg##* + }" + : ''${windowManager:=${cfg.windowManager.default}} + # extract the desktop manager. + desktopManager="''${arg% + *}" + : ''${desktopManager:=${cfg.desktopManager.default}} + + # used to restart the xserver. + waitPID=0 + + # handle window manager starts. + case $windowManager in + ${concatMapStrings (s: " + (${s.name}) + ${s.start} + ;; + ") wm} + (*) echo "$0: Window manager '$windowManager' not found.";; + esac + + # handle desktop manager starts. + case $desktopManager in + ${concatMapStrings (s: " + (${s.name}) + ${s.start} + ;; + ") dm} + (*) echo "$0: Desktop manager '$desktopManager' not found.";; + esac + + test "$waitPID" != 0 && wait "$waitPID" + exit + ''; + +in + +{ + # list of display managers. + require = [ + (import ./slim.nix) + ]; + + services = { + xserver = { + displayManager = { + + xauthBin = mkOption { + default = "${xorg.xauth}/bin/xauth"; + description = " + Path to the xauth binary used by display managers. + "; + }; + + xserverBin = mkOption { + default = "${xorg.xorgserver}/bin/X"; + description = " + Path to the xserver binary used by display managers. + "; + }; + + xserverArgs = mkOption { + default = []; + example = [ + "-ac" + "-logverbose" + "-nolisten tcp" + ]; + description = " + List of arguments which have to be pass to when + the display manager start the xserver. + "; + apply = toString; + }; + + session = mkOption { + default = []; + example = [ + { + manage = "desktop"; + name = "xterm"; + start = " + ${pkgs.xterm}/bin/xterm -ls & + waitPID=$! + "; + } + ]; + description = '' + List of session supported with the command used to start each + session. Each session script can set the + waitPID shell variable to make this script + waiting until the end of the user session. Each script is used + to define either a windows manager or a desktop manager. These + can be differentiated by setting the attribute + manage either to "window" + or "desktop". + + The list of desktop manager and window manager should appear + inside the display manager with the desktop manager name + followed by the window manager name. + ''; + apply = list: rec { + wm = filter (s: s.manage == "window") list; + dm = filter (s: s.manage == "desktop") list; + names = concatMap (d: map (w: d.name + " + " + w.name) wm) dm; + script = xsession wm dm; + }; + }; + + job = mkOption { + default = {}; + example = { + beforeScript = '' + rm -f /var/log/slim.log + ''; + env = '' + env 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 = name: list: + if tail list != [] then + throw "only one display manager is allowed." + else + head list; + }; + + }; + }; + }; +} diff --git a/upstart-jobs/xserver/displayManager/slim.nix b/upstart-jobs/xserver/displayManager/slim.nix new file mode 100644 index 00000000000..8363a7a14ee --- /dev/null +++ b/upstart-jobs/xserver/displayManager/slim.nix @@ -0,0 +1,112 @@ +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + options = { services = { xserver = { + + slim = { + + theme = mkOption { + default = null; + example = pkgs.fetchurl { + url = http://download.berlios.de/slim/slim-wave.tar.gz; + sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy"; + }; + description = " + The theme for the SLiM login manager. If not specified, SLiM's + default theme is used. See for a + collection of themes. + "; + }; + + defaultUser = mkOption { + default = ""; + example = "login"; + description = " + The default user to load. If you put a username here you + get it automatically loaded into the username field, and + the focus is placed on the password. + "; + }; + + hideCursor = mkOption { + default = false; + example = true; + description = " + Hide the mouse cursor on the login screen. + "; + }; + }; + + }; /* xserver */ }; /* services */ }; + +in + +###### implementation +let + xcfg = config.services.xserver; + dmcfg = xcfg.displayManager; + cfg = xcfg.slim; + + slimConfig = pkgs.writeText "slim.cfg" '' + xauth_path ${dmcfg.xauthBin} + default_xserver ${dmcfg.xserverBin} + xserver_arguments ${dmcfg.xserverArgs} + sessions ${pkgs.lib.concatStringsSep "," dmcfg.session.names} + login_cmd exec ${pkgs.stdenv.bash}/bin/sh ${dmcfg.session.script} "%session" + halt_cmd ${pkgs.upstart}/sbin/shutdown -h now + reboot_cmd ${pkgs.upstart}/sbin/shutdown -r now + ${if cfg.defaultUser != "" then "default_user " + cfg.defaultUser else ""} + ${if cfg.hideCursor then "hidecursor true" else ""} + ''; + + + # Unpack the SLiM theme, or use the default. + slimThemesDir = + let + unpackedTheme = pkgs.stdenv.mkDerivation { + name = "slim-theme"; + buildCommand = '' + ensureDir $out + cd $out + unpackFile ${cfg.theme} + ln -s * default + ''; + }; + in if cfg.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme; + +in + +{ + require = [ + options + ]; + + services = { + xserver = { + displayManager = { + job = { + beforeScript = '' + rm -f /var/log/slim.log + ''; + env = '' + env SLIM_CFGFILE=${slimConfig} + env SLIM_THEMESDIR=${slimThemesDir} + ''; + execCmd = "${pkgs.slim}/bin/slim"; + }; + }; + }; + }; + + environment = { + etc = [ + { source = ../../../etc/pam.d/slim; + target = "pam.d/slim"; + } + ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/compiz.nix b/upstart-jobs/xserver/windowManager/compiz.nix new file mode 100644 index 00000000000..e99c3adb5b4 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/compiz.nix @@ -0,0 +1,64 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.compiz; + xorg = config.services.xserver.package; + gnome = pkgs.gnome; + + options = { services = { xserver = { windowManager = { + + compiz = { + enable = mkOption { + default = false; + example = true; + description = "Enable the compiz window manager."; + }; + + + renderingFlag = mkOption { + default = ""; + example = "--indirect-rendering"; + description = " + Possibly pass --indierct-rendering to Compiz. + "; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "compiz"; + start = '' + # !!! Hack: load the schemas for Compiz. + GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ + --makefile-install-rule ${pkgs.compiz}/etc/gconf/schemas/*.schemas # */ + + # !!! Hack: turn on most Compiz modules. + ${gnome.GConf}/bin/gconftool-2 -t list --list-type=string \ + --set /apps/compiz/general/allscreens/options/active_plugins \ + [gconf,png,decoration,wobbly,fade,minimize,move,resize,cube,switcher,rotate,place,scale,water] + + # Start Compiz and the GTK-style window decorator. + env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ + ${pkgs.compiz}/bin/compiz gconf ${cfg.renderingFlag} & + ${pkgs.compiz}/bin/gtk-window-decorator --sync & + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ pkgs.compiz ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/default.nix b/upstart-jobs/xserver/windowManager/default.nix new file mode 100644 index 00000000000..41c3ad15983 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/default.nix @@ -0,0 +1,61 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption any; + cfg = config.services.xserver.windowManager; +in + +{ + require = [ + (import ./compiz.nix) + (import ./kwm.nix) + (import ./metacity.nix) + (import ./none.nix) + (import ./twm.nix) + (import ./wmii.nix) + (import ./xmonad.nix) + ]; + + services = { + xserver = { + displayManager = { + session = cfg.session; + }; + + windowManager = { + session = mkOption { + default = []; + example = [{ + name = "wmii"; + start = "..."; + }]; + description = " + Internal option used to add some common line to window manager + scripts before forwarding the value to the + displayManager. + "; + apply = map (d: d // { + manage = "window"; + }); + }; + + default = mkOption { + default = "none"; + example = "wmii"; + description = " + Default window manager loaded if none have been chosen. + "; + merge = name: list: + let defaultWM = head list; in + if tail list != [] then + throw "Only one default window manager is allowed." + else if any (w: w.name == defaultWM) cfg.session then + defaultWM + else + throw "Default window manager not found."; + }; + }; + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/kwm.nix b/upstart-jobs/xserver/windowManager/kwm.nix new file mode 100644 index 00000000000..db8696c510d --- /dev/null +++ b/upstart-jobs/xserver/windowManager/kwm.nix @@ -0,0 +1,46 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.kwm; + + option = { services = { xserver = { windowManager = { + + kwm = { + enable = mkOption { + default = false; + example = true; + description = "Enable the kwm window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "kwm"; + start = " + ${pkgs.kdebase}/bin/kwin & + waitPID=$! + "; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + pkgs.kdelibs + pkgs.kdebase + ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/metacity.nix b/upstart-jobs/xserver/windowManager/metacity.nix new file mode 100644 index 00000000000..dc1ff911d65 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/metacity.nix @@ -0,0 +1,49 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.metacity; + xorg = config.services.xserver.package; + gnome = pkgs.gnome; + + option = { services = { xserver = { windowManager = { + + metacity = { + enable = mkOption { + default = false; + example = true; + description = "Enable the metacity window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "metacity"; + start = '' + env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ + # !!! Hack: load the schemas for Metacity. + GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ + --makefile-install-rule ${gnome.metacity}/etc/gconf/schemas/*.schemas # */ + ${gnome.metacity}/bin/metacity & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ gnome.metacity ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/none.nix b/upstart-jobs/xserver/windowManager/none.nix new file mode 100644 index 00000000000..84cf1d77077 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/none.nix @@ -0,0 +1,12 @@ +{ + services = { + xserver = { + windowManager = { + session = [{ + name = "none"; + start = ""; + }]; + }; + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/twm.nix b/upstart-jobs/xserver/windowManager/twm.nix new file mode 100644 index 00000000000..f26be48776c --- /dev/null +++ b/upstart-jobs/xserver/windowManager/twm.nix @@ -0,0 +1,44 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.twm; + xorg = config.services.xserver.package; + + option = { services = { xserver = { windowManager = { + + twm = { + enable = mkOption { + default = false; + example = true; + description = "Enable the twm window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "twm"; + start = " + ${xorg.twm}/bin/twm & + waitPID=$! + "; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ xorg.twm ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/wmii.nix b/upstart-jobs/xserver/windowManager/wmii.nix new file mode 100644 index 00000000000..59a88f9352f --- /dev/null +++ b/upstart-jobs/xserver/windowManager/wmii.nix @@ -0,0 +1,32 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.wmii; +in + +{ + services = { + xserver = { + + windowManager = { + wmii = { + enable = mkOption { + default = false; + example = true; + description = "Enable the wmii window manager."; + }; + }; + + session = mkIf cfg.enable [{ + name = "wmii"; + start = " + ${pkgs.wmiiSnap}/bin/wmii & + waitPID=$! + "; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/xmonad.nix b/upstart-jobs/xserver/windowManager/xmonad.nix new file mode 100644 index 00000000000..6f73ad9edc3 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/xmonad.nix @@ -0,0 +1,32 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.xmonad; +in + +{ + services = { + xserver = { + + windowManager = { + xmonad = { + enable = mkOption { + default = false; + example = true; + description = "Enable the xmonad window manager."; + }; + }; + + session = mkIf cfg.enable [{ + name = "xmonad"; + start = " + ${pkgs.xmonad}/bin/xmonad & + waitPID=$! + "; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver.conf b/upstart-jobs/xserver/xserver.conf similarity index 100% rename from upstart-jobs/xserver.conf rename to upstart-jobs/xserver/xserver.conf