From 8d731dacadd9be6701d3371a9b0bfa435f5ba404 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 6 Mar 2007 00:07:00 +0000 Subject: [PATCH] * X session script: - Set the desktop background to the image ~/.background-image. - Depending on services.xserver.sessionType, start an xterm or a gnome-terminal as the "desktop" :-) * Upstart jobs can now declare extra packages to be added to the system path through the `extraPath' attribute. For instance, the ALSA job adds alsa-utils, and the X server job adds lots of stuff depending on the X configuration (e.g., xrandr, gnome-terminal, twm). * Create a cdrom/dvd symlink for SCSI sr? devices. svn path=/nixos/trunk/; revision=8221 --- system/options.nix | 24 ++++++++ system/system.nix | 2 +- system/upstart.nix | 8 ++- upstart-jobs/alsa.nix | 2 + upstart-jobs/make-job.nix | 14 ++++- upstart-jobs/udev-rules/50-udev.rules | 1 + upstart-jobs/xserver.conf | 5 ++ upstart-jobs/xserver.nix | 88 +++++++++++++++++++++++---- 8 files changed, 125 insertions(+), 19 deletions(-) diff --git a/system/options.nix b/system/options.nix index 9115cedc7b12..fa3a6f077442 100644 --- a/system/options.nix +++ b/system/options.nix @@ -505,6 +505,30 @@ } + { + name = ["services" "xserver" "sessionType"]; + default = "gnome"; + example = "xterm"; + description = " + The kind of session to start after login. Current possibilies + are gnome (which starts + gnome-terminal) and xterm + (which starts xterm). + "; + } + + + { + name = ["services" "xserver" "sessionStarter"]; + example = "${pkgs.xterm}/bin/xterm -ls"; + description = " + The command executed after login and after the window manager + has been started. Used if + is not empty. + "; + } + + { name = ["services" "httpd" "enable"]; default = false; diff --git a/system/system.nix b/system/system.nix index 03ec3b1c3a4c..e4c093c5dd27 100644 --- a/system/system.nix +++ b/system/system.nix @@ -208,7 +208,7 @@ rec { nixosCheckout setuidWrapper ] - ++ (if config.get ["sound" "enable"] then [pkgs.alsaUtils] else []); + ++ pkgs.lib.concatLists (map (job: job.extraPath) upstartJobs.jobs); # We don't want to put all of `startPath' and `path' in $PATH, since diff --git a/system/upstart.nix b/system/upstart.nix index eb185a2b204b..0a00a1ba31f1 100644 --- a/system/upstart.nix +++ b/system/upstart.nix @@ -125,8 +125,8 @@ import ../upstart-jobs/gather.nix { ++ optional ["services" "xserver" "enable"] (import ../upstart-jobs/xserver.nix { inherit config; - inherit (pkgs) stdenv writeText lib xterm slim xorg mesa compiz; - inherit (pkgs.gnome) metacity GConf; + inherit (pkgs) stdenv writeText lib xterm slim xorg mesa + gnome compiz feh; fontDirectories = import ./fonts.nix {inherit pkgs;}; }) @@ -201,6 +201,8 @@ import ../upstart-jobs/gather.nix { ++ (map makeJob (config.get ["services" "extraJobs"])) # For the built-in logd job. - ++ [pkgs.upstart]; + ++ [ + (pkgs.upstart // {extraPath = [];}) + ]; } diff --git a/upstart-jobs/alsa.nix b/upstart-jobs/alsa.nix index 1b018b2259a8..ea6b1c557b23 100644 --- a/upstart-jobs/alsa.nix +++ b/upstart-jobs/alsa.nix @@ -8,6 +8,8 @@ in { name = "alsa"; + + extraPath = [alsaUtils]; job = " start on hardware-scan diff --git a/upstart-jobs/make-job.nix b/upstart-jobs/make-job.nix index 630ae1d83e16..457336c8f201 100644 --- a/upstart-jobs/make-job.nix +++ b/upstart-jobs/make-job.nix @@ -1,4 +1,14 @@ {runCommand}: job: -runCommand job.name {inherit (job) job;} - "ensureDir $out/etc/event.d; echo \"$job\" > $out/etc/event.d/$name" +( + runCommand job.name {inherit (job) job;} + "ensureDir $out/etc/event.d; echo \"$job\" > $out/etc/event.d/$name" +) + +// + +# Allow jobs to declare extra packages that should be added to the +# system path. +{ + extraPath = if job ? extraPath then job.extraPath else []; +} \ No newline at end of file diff --git a/upstart-jobs/udev-rules/50-udev.rules b/upstart-jobs/udev-rules/50-udev.rules index 9b12e9b3e380..cb375103de30 100644 --- a/upstart-jobs/udev-rules/50-udev.rules +++ b/upstart-jobs/udev-rules/50-udev.rules @@ -28,6 +28,7 @@ KERNEL=="uinput", NAME="input/%k", MODE="0600" # Create a symlink for the CD-ROM device. KERNEL=="hd[a-z]", BUS=="ide", SYSFS{removable}=="1", SYSFS{device/media}=="cdrom", SYMLINK+="cdrom cdrom-%k" +KERNEL=="sr[0-9]", BUS=="scsi", SYMLINK+="cdrom cdrom-%k" # ALSA sound devices. diff --git a/upstart-jobs/xserver.conf b/upstart-jobs/xserver.conf index 34f507a2c357..0a655dd5e86a 100644 --- a/upstart-jobs/xserver.conf +++ b/upstart-jobs/xserver.conf @@ -78,3 +78,8 @@ EndSection Section "Extensions" Option "Composite" "Enable" EndSection + + +Section "DRI" + Mode 0666 # !!! FIX THIS! +EndSection diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver.nix index f97c4f001745..810df8482831 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver.nix @@ -1,4 +1,5 @@ -{ stdenv, writeText, lib, xorg, mesa, xterm, slim, metacity, GConf, compiz +{ stdenv, writeText, lib, xorg, mesa, xterm, slim, gnome +, compiz, feh , config @@ -20,11 +21,19 @@ let optional = condition: x: if condition then [x] else []; + # Get a bunch of user settings. videoDriver = getCfg "videoDriver"; - resolutions = map (res: "\"${toString res.x}x${toString res.y}\"") (getCfg "resolutions"); - windowManager = getCfg "windowManager"; + sessionType = getCfg "sessionType"; + sessionStarter = getCfg "sessionStarter"; + + + sessionCmd = + if sessionType == "" then sessionStarter else + if sessionType == "xterm" then "${xterm}/bin/xterm -ls" else + if sessionType == "gnome" then "${gnome.gnometerminal}/bin/gnome-terminal" else + abort ("unknown session type "+ sessionType); modules = [ @@ -65,28 +74,54 @@ let clientScript = writeText "xclient" " + + exec > $HOME/.Xerrors 2>&1 + + + ### Start a window manager. + ${if windowManager == "twm" then " ${xorg.twm}/bin/twm & " else if windowManager == "metacity" then " # !!! Hack: load the schemas for Metacity. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${GConf}/bin/gconftool-2 --makefile-install-rule ${metacity}/etc/gconf/schemas/*.schemas - ${metacity}/bin/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 == "compiz" then " + # !!! Hack: load the schemas for Compiz. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${GConf}/bin/gconftool-2 --makefile-install-rule ${compiz}/etc/gconf/schemas/*.schemas - ${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,zoom] + GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \\ + --makefile-install-rule ${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,zoom] + + # Start Compiz and the GTK-style window decorator. ${compiz}/bin/compiz gconf & ${compiz}/bin/gtk-window-decorator & " else abort ("unknown window manager "+ windowManager)} + + + ### Show a background image. + if test -e $HOME/.background-image; then + ${feh}/bin/feh --bg-scale $HOME/.background-image + fi - ${xterm}/bin/xterm -ls - "; + + ### Start a 'session' (right now, this is just a terminal). + # !!! yes, this means that you 'log out' by killing the X server. + while ${sessionCmd}; do + sleep 1 + done + "; # */ <- hack to fix syntax highlighting xserverArgs = [ @@ -98,6 +133,7 @@ let ":${toString display}" "vt${toString tty}" ]; + # Note: lines must not be indented. slimConfig = writeText "slim.cfg" " xauth_path ${xorg.xauth}/bin/xauth @@ -113,22 +149,48 @@ in rec { name = "xserver"; + + extraPath = [ + xorg.xrandr + feh + ] + ++ optional (windowManager == "twm") [ + xorg.twm + ] + ++ optional (windowManager == "metacity") [ + gnome.metacity + ] + ++ optional (windowManager == "compiz") [ + compiz + ] + ++ optional (sessionType == "xterm") [ + xterm + ] + ++ optional (sessionType == "gnome") [ + gnome.gnometerminal + gnome.GConf + gnome.gconfeditor + ]; + + job = " #start on network-interfaces start script rm -f /var/state/opengl-driver ${if getCfg "driSupport" - then "ln -sf ${mesa} /var/state/opengl-driver" - else ""} + then "ln -sf ${mesa} /var/state/opengl-driver" + else "" + } end script env SLIM_CFGFILE=${slimConfig} env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup ${if getCfg "driSupport" - then "env XORG_DRI_DRIVER_PATH=${mesa}/lib/modules/dri" - else ""} + then "env XORG_DRI_DRIVER_PATH=${mesa}/lib/modules/dri" + else "" + } exec ${slim}/bin/slim ";