2008-01-04 10:54:33 +00:00
{ config , pkgs
2006-11-28 22:27:56 +00:00
2007-02-25 15:53:57 +00:00
, # List of font directories.
fontDirectories
2006-11-28 22:27:56 +00:00
} :
let
2007-02-26 23:11:32 +00:00
optional = condition : x : if condition then [ x ] else [ ] ;
2008-01-04 10:54:33 +00:00
# Abbreviations.
cfg = config . services . xserver ;
xorg = pkgs . xorg ;
gnome = pkgs . gnome ;
stdenv = pkgs . stdenvNewSetupScript ;
2007-03-06 00:07:00 +00:00
# Get a bunch of user settings.
2007-11-09 18:49:45 +00:00
videoDriver = cfg . videoDriver ;
2008-01-04 10:28:12 +00:00
resolutions = map ( res : '' " ${ toString res . x } x ${ toString res . y } " '' ) ( cfg . resolutions ) ;
2007-11-09 18:49:45 +00:00
sessionType = cfg . sessionType ;
sessionStarter = cfg . sessionStarter ;
renderingFlag = cfg . renderingFlag ;
2007-03-06 00:07:00 +00:00
sessionCmd =
if sessionType == " " then sessionStarter else
2008-01-04 10:54:33 +00:00
if sessionType == " x t e r m " then " ${ pkgs . xterm } / b i n / x t e r m - l s " else
2007-05-28 14:09:04 +00:00
if sessionType == " g n o m e " then " ${ gnome . gnometerminal } / b i n / g n o m e - t e r m i n a l - l s " else
2007-03-06 00:07:00 +00:00
abort ( " u n k n o w n s e s s i o n t y p e " + sessionType ) ;
2007-02-28 23:00:09 +00:00
2007-02-26 23:11:32 +00:00
2007-03-28 21:16:35 +00:00
windowManager =
2007-11-09 18:49:45 +00:00
let wm = cfg . windowManager ; in
2007-03-28 21:16:35 +00:00
if wm != " " then wm else
if sessionType == " g n o m e " then " m e t a c i t y " else
if sessionType == " k d e " then " n o n e " /* s t a r t e d b y s t a r t k d e */ else
" t w m " ;
2007-05-28 14:09:04 +00:00
modules =
2008-01-04 10:54:33 +00:00
optional ( videoDriver == " n v i d i a " ) pkgs . nvidiaDrivers ++ #make sure it first loads the nvidia libs
2007-05-29 19:53:03 +00:00
[
xorg . xorgserver
xorg . xf86inputkeyboard
xorg . xf86inputmouse
]
++ optional ( videoDriver == " v e s a " ) xorg . xf86videovesa
2007-10-26 04:28:01 +00:00
++ optional ( videoDriver == " v g a " ) xorg . xf86videovga
2007-06-28 09:57:36 +00:00
++ optional ( videoDriver == " s i s " ) xorg . xf86videosis
2007-05-29 19:53:03 +00:00
++ optional ( videoDriver == " i 8 1 0 " ) xorg . xf86videoi810
2007-09-24 09:02:43 +00:00
++ optional ( videoDriver == " i n t e l " ) xorg . xf86videointel
2007-11-15 23:57:20 +00:00
++ optional ( videoDriver == " n v " ) xorg . xf86videonv
2007-12-18 22:43:17 +00:00
++ optional ( videoDriver == " a t i " ) xorg . xf86videoati
2008-01-04 10:54:33 +00:00
++ ( optional cfg . isSynaptics [ " ${ pkgs . synaptics } / ${ xorg . xorgserver } " /* x o r g . x f 8 6 i n p u t e v d e v */ ] ) ;
2008-01-04 10:28:12 +00:00
2007-02-26 23:11:32 +00:00
configFile = stdenv . mkDerivation {
2006-11-28 22:27:56 +00:00
name = " x s e r v e r . c o n f " ;
src = ./xserver.conf ;
2008-01-04 10:36:14 +00:00
inherit fontDirectories videoDriver resolutions ;
isClone = if cfg . isClone then " o n " else " o f f " ;
2007-11-06 00:00:29 +00:00
2008-01-04 10:28:12 +00:00
synapticsInputDevice = if cfg . isSynaptics then ''
Section " I n p u t D e v i c e "
Identifier " T o u c h p a d [ 0 ] "
Driver " s y n a p t i c s "
Option " D e v i c e " " ${ cfg . devSynaptics } "
Option " P r o t o c o l " " P S / 2 "
Option " L e f t E d g e " " 1 7 0 0 "
Option " R i g h t E d g e " " 5 3 0 0 "
Option " T o p E d g e " " 1 7 0 0 "
Option " B o t t o m E d g e " " 4 2 0 0 "
Option " F i n g e r L o w " " 2 5 "
Option " F i n g e r H i g h " " 3 0 "
Option " M a x T a p T i m e " " 1 8 0 "
Option " M a x T a p M o v e " " 2 2 0 "
Option " V e r t S c r o l l D e l t a " " 1 0 0 "
Option " M i n S p e e d " " 0 . 0 6 "
Option " M a x S p e e d " " 0 . 1 2 "
Option " A c c e l F a c t o r " " 0 . 0 0 1 0 "
Option " S H M C o n f i g " " o n "
Option " R e p e a t e r " " / d e v / i n p u t / m i c e "
Option " T a p B u t t o n 1 " " 1 "
Option " T a p B u t t o n 2 " " 2 "
Option " T a p B u t t o n 3 " " 3 "
EndSection
'' e l s e " " ;
xkbOptions = if cfg . xkbOptions == " " then " " else ''
Option " X k b O p t i o n s " " ${ cfg . xkbOptions } "
'' ;
2007-11-06 00:00:29 +00:00
2007-11-09 18:49:45 +00:00
layout = cfg . layout ;
2007-11-06 00:00:29 +00:00
2007-11-09 18:49:45 +00:00
corePointer = if cfg . isSynaptics then " T o u c h p a d [ 0 ] " else " M o u s e [ 0 ] " ;
2007-11-06 00:00:29 +00:00
internalAGPGART =
2008-01-04 10:28:12 +00:00
if cfg . useInternalAGPGART == " y e s " then
'' O p t i o n " U s e I n t e r n a l A G P G A R T " " y e s " ''
else if cfg . useInternalAGPGART == " n o " then
'' O p t i o n " U s e I n t e r n a l A G P G A R T " " n o " ''
else " " ;
2007-11-06 00:00:29 +00:00
2007-11-09 18:49:45 +00:00
extraDeviceConfig = cfg . extraDeviceConfig ;
extraMonitorSettings = cfg . extraMonitorSettings ;
2008-01-02 21:16:58 +00:00
extraDisplaySettings = cfg . extraDisplaySettings ;
2007-11-09 18:49:45 +00:00
extraModules = cfg . extraModules ;
serverLayoutOptions = cfg . serverLayoutOptions ;
defaultDepth = cfg . defaultDepth ;
2007-09-24 09:02:43 +00:00
2008-01-04 10:28:12 +00:00
xfs = if cfg . useXFS == false then " " else
'' F o n t P a t h " ${ toString cfg . useXFS } " '' ;
2007-12-25 12:16:38 +00:00
2008-01-04 10:28:12 +00:00
buildCommand = ''
2007-02-25 15:53:57 +00:00
buildCommand = # urgh, don't substitute this
2007-02-26 21:39:07 +00:00
2007-02-25 15:53:57 +00:00
export fontPaths =
for i in $ fontDirectories ; do
2008-01-04 10:28:12 +00:00
if test " ' ' ${ i:0:''$ { #NIX_STORE}}" == "$NIX_STORE"; then
2007-02-25 15:53:57 +00:00
for j in $ ( find $ i - name fonts . dir ) ; do
2008-01-04 10:28:12 +00:00
fontPaths = " ' ' ${ fontPaths } F o n t P a t h \" $ ( d i r n a m e $ j ) \" ' ' \n "
2007-02-25 15:53:57 +00:00
done
fi
done
2007-02-26 21:39:07 +00:00
export modulePaths =
2007-02-26 23:11:32 +00:00
for i in $ ( find $ { toString modules } - type d ) ; do
2007-02-26 21:39:07 +00:00
if ls $ i /* . s o 2 > / d e v / n u l l ; t h e n
2008-01-04 10:28:12 +00:00
modulePaths = " ' ' ${ modulePaths } M o d u l e P a t h \" $ i \" ' ' \n "
2007-02-26 21:39:07 +00:00
fi
done
2007-05-28 14:09:04 +00:00
#if only my gf were this dirty
2008-01-04 10:28:12 +00:00
if test " ${ toString videoDriver } " == " n v i d i a " ; then
2007-10-03 14:48:41 +00:00
export moduleSection = '
2008-01-04 10:28:12 +00:00
Load " g l x "
SubSection " e x t m o d "
Option " o m i t x f r e e 8 6 - d g a "
2007-10-03 14:48:41 +00:00
EndSubSection
'
export screen = '
2008-01-04 10:28:12 +00:00
Option " A d d A R G B G L X V i s u a l s " " t r u e "
Option " D i s a b l e G L X R o o t C l i p p i n g " " t r u e "
2007-10-03 14:48:41 +00:00
'
export device = '
2008-01-04 10:28:12 +00:00
Option " R e n d e r A c c e l " " t r u e "
Option " A l l o w G L X W i t h C o m p o s i t e " " t r u e "
Option " A d d A R G B G L X V i s u a l s " " t r u e "
2007-10-03 14:48:41 +00:00
'
export extensions = '
2008-01-04 10:28:12 +00:00
Option " C o m p o s i t e " " E n a b l e "
2007-10-03 14:48:41 +00:00
'
2007-05-28 14:09:04 +00:00
2007-05-29 19:53:03 +00:00
else
2007-10-03 14:48:41 +00:00
export moduleSection = '
2008-01-04 10:28:12 +00:00
Load " g l x "
Load " d r i "
2007-10-03 14:48:41 +00:00
'
2007-05-29 19:53:03 +00:00
export screen =
export device =
export extensions =
2007-05-28 14:09:04 +00:00
fi
2007-10-27 17:47:54 +00:00
2008-01-04 10:28:12 +00:00
if [ " ${ toString videoDriver } " = i810 ] ; then
export extensions = '
Option " C o m p o s i t e " " E n a b l e "
' ;
fi ;
2007-05-28 14:09:04 +00:00
2007-02-25 15:53:57 +00:00
substituteAll $ src $ out
2008-01-04 10:36:14 +00:00
'' ; # * /
2006-11-28 22:27:56 +00:00
} ;
2007-02-26 23:11:32 +00:00
2008-01-04 10:54:33 +00:00
clientScript = pkgs . writeText " x c l i e n t " ''
2007-03-06 00:07:00 +00:00
2007-03-28 21:16:35 +00:00
source /etc/profile
2007-03-06 00:07:00 +00:00
exec > $ HOME/.Xerrors 2 > & 1
2007-03-30 12:33:42 +00:00
2007-04-02 15:01:09 +00:00
### Load X defaults.
2007-03-30 12:33:42 +00:00
if test - e ~/.Xdefaults ; then
$ { xorg . xrdb } /bin/xrdb - merge ~/.Xdefaults
fi
2007-04-02 15:01:09 +00:00
2008-01-04 10:28:12 +00:00
$ { if cfg . startSSHAgent then ''
2007-04-02 15:01:09 +00:00
### Start the SSH agent.
2008-01-04 10:54:33 +00:00
export SSH_ASKPASS = $ { pkgs . x11_ssh_askpass } /libexec/x11-ssh-askpass
eval $ ( $ { pkgs . openssh } /bin/ssh-agent )
2008-01-04 10:28:12 +00:00
'' e l s e " " }
2007-09-01 17:57:04 +00:00
### Allow user to override system-wide configuration
if test - f ~/.xsession ; then
source ~/.xsession ;
fi
2007-03-06 00:07:00 +00:00
### Start a window manager.
2008-01-04 10:28:12 +00:00
$ { if windowManager == " t w m " then ''
2007-03-28 21:16:35 +00:00
$ { xorg . twm } /bin/twm &
2008-01-04 10:28:12 +00:00
''
2007-03-01 00:00:16 +00:00
2008-01-04 10:28:12 +00:00
else if windowManager == " m e t a c i t y " then ''
2008-01-04 10:54:33 +00:00
env LD_LIBRARY_PATH = $ { xorg . libX11 } /lib : $ { xorg . libXext } /lib : /usr/lib /
2007-03-28 21:16:35 +00:00
# !!! Hack: load the schemas for Metacity.
2008-01-04 10:28:12 +00:00
GCONF_CONFIG_SOURCE = xml::~/.gconf $ { gnome . GConf } /bin/gconftool-2 \
2007-03-28 21:16:35 +00:00
- - makefile-install-rule $ { gnome . metacity } /etc/gconf/schemas /* . s c h e m a s
$ { gnome . metacity } /bin/metacity &
2008-01-04 10:28:12 +00:00
''
2007-03-28 21:16:35 +00:00
2008-01-04 10:28:12 +00:00
else if windowManager == " k w m " then ''
2008-01-04 10:54:33 +00:00
$ { pkgs . kdebase } /bin/kwin &
2008-01-04 10:28:12 +00:00
''
2007-03-01 00:00:16 +00:00
2008-01-04 10:28:12 +00:00
else if windowManager == " c o m p i z " then ''
2007-03-28 21:16:35 +00:00
# !!! Hack: load the schemas for Compiz.
2008-01-04 10:28:12 +00:00
GCONF_CONFIG_SOURCE = xml::~/.gconf $ { gnome . GConf } /bin/gconftool-2 \
2008-01-04 10:54:33 +00:00
- - makefile-install-rule $ { pkgs . compiz } /etc/gconf/schemas /* . s c h e m a s
2007-03-28 21:16:35 +00:00
# !!! Hack: turn on most Compiz modules.
2008-01-04 10:28:12 +00:00
$ { gnome . GConf } /bin/gconftool-2 - t list - - list-type = string \
- - set /apps/compiz/general/allscreens/options/active_plugins \
2007-03-28 21:16:35 +00:00
[ gconf , png , decoration , wobbly , fade , minimize , move , resize , cube , switcher , rotate , place , scale , water ]
# Start Compiz and the GTK-style window decorator.
2008-01-04 10:54:33 +00:00
env LD_LIBRARY_PATH = $ { xorg . libX11 } /lib : $ { xorg . libXext } /lib : /usr/lib /
$ { pkgs . compiz } /bin/compiz gconf $ { renderingFlag } &
$ { pkgs . compiz } /bin/gtk-window-decorator - - sync &
2008-01-04 10:28:12 +00:00
''
else if windowManager == " n o n e " then ''
2007-03-28 21:16:35 +00:00
# The session starter will start the window manager.
2008-01-04 10:28:12 +00:00
''
2007-03-01 00:00:16 +00:00
2007-03-28 21:16:35 +00:00
else abort ( " u n k n o w n w i n d o w m a n a g e r " + windowManager ) }
2007-03-06 00:07:00 +00:00
### Show a background image.
2007-03-28 21:16:35 +00:00
# (but not if we're starting a full desktop environment that does it for us)
2008-01-04 10:28:12 +00:00
$ { if sessionType != " k d e " then ''
2007-03-01 00:00:16 +00:00
2007-03-28 21:16:35 +00:00
if test - e $ HOME/.background-image ; then
2008-01-04 10:54:33 +00:00
$ { pkgs . feh } /bin/feh - - bg-scale $ HOME/.background-image
2007-03-28 21:16:35 +00:00
fi
2008-01-04 10:28:12 +00:00
'' e l s e " " }
2007-03-28 21:16:35 +00:00
### Start the session.
2008-01-04 10:28:12 +00:00
$ { if sessionType == " k d e " then ''
2007-03-28 21:16:35 +00:00
# Start KDE.
2008-01-04 10:54:33 +00:00
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
2007-03-28 21:16:35 +00:00
2008-01-04 10:28:12 +00:00
'' e l s e ''
2007-03-06 00:07:00 +00:00
2007-03-28 21:16:35 +00:00
# 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
2008-01-04 10:28:12 +00:00
'' }
2007-03-28 21:16:35 +00:00
2008-01-04 10:36:14 +00:00
'' ; # * /
2007-02-25 16:20:14 +00:00
2007-02-26 23:11:32 +00:00
2007-02-25 22:27:17 +00:00
xserverArgs = [
" - a c "
2007-05-28 14:09:04 +00:00
" - l o g v e r b o s e "
" - v e r b o s e "
2007-02-25 22:27:17 +00:00
" - t e r m i n a t e "
2008-01-04 10:54:33 +00:00
" - l o g f i l e " " / v a r / l o g / X . ${ toString cfg . display } . l o g "
2007-02-26 23:11:32 +00:00
" - c o n f i g ${ configFile } "
2008-01-04 10:54:33 +00:00
" : ${ toString cfg . display } " " v t ${ toString cfg . tty } "
" - x k b d i r " " ${ pkgs . xkeyboard_config } / e t c / X 1 1 / x k b "
2008-01-04 10:28:12 +00:00
] ++ optional ( ! config . services . xserver . tcpEnable ) " - n o l i s t e n t c p " ;
2007-02-25 22:27:17 +00:00
2007-03-06 00:07:00 +00:00
2008-01-04 10:54:33 +00:00
slimConfig = pkgs . writeText " s l i m . c f g " ''
2008-01-04 10:28:12 +00:00
xauth_path $ { xorg . xauth } /bin/xauth
default_xserver $ { xorg . xorgserver } /bin/X
xserver_arguments $ { toString xserverArgs }
login_cmd exec $ { stdenv . bash } /bin/sh $ { clientScript }
'' ;
2007-02-25 22:27:17 +00:00
2007-02-26 23:11:32 +00:00
2007-06-05 11:51:59 +00:00
# Unpack the SLiM theme, or use the default.
slimThemesDir =
let
unpackedTheme = stdenv . mkDerivation {
name = " s l i m - t h e m e " ;
2008-01-04 10:28:12 +00:00
buildCommand = ''
2007-06-05 11:51:59 +00:00
ensureDir $ out
cd $ out
2007-11-09 18:49:45 +00:00
unpackFile $ { cfg . slim . theme }
2007-06-05 11:51:59 +00:00
ln - s * default
2008-01-04 10:28:12 +00:00
'' ;
2007-06-05 11:51:59 +00:00
} ;
2008-01-04 10:54:33 +00:00
in if cfg . slim . theme == null then " ${ pkgs . slim } / s h a r e / s l i m / t h e m e s " else unpackedTheme ;
2007-06-05 11:51:59 +00:00
2006-11-28 22:27:56 +00:00
in
2007-02-26 23:11:32 +00:00
2006-11-28 22:27:56 +00:00
rec {
name = " x s e r v e r " ;
2007-03-06 00:07:00 +00:00
extraPath = [
xorg . xrandr
2007-03-30 12:33:42 +00:00
xorg . xrdb
xorg . setxkbmap
2008-01-04 10:54:33 +00:00
pkgs . feh
2007-03-06 00:07:00 +00:00
]
++ optional ( windowManager == " t w m " ) [
xorg . twm
]
++ optional ( windowManager == " m e t a c i t y " ) [
gnome . metacity
]
++ optional ( windowManager == " c o m p i z " ) [
2008-01-04 10:54:33 +00:00
pkgs . compiz
2007-03-06 00:07:00 +00:00
]
++ optional ( sessionType == " x t e r m " ) [
2008-01-04 10:54:33 +00:00
pkgs . xterm
2007-03-06 00:07:00 +00:00
]
++ optional ( sessionType == " g n o m e " ) [
gnome . gnometerminal
gnome . GConf
gnome . gconfeditor
2007-03-28 21:16:35 +00:00
]
++ optional ( sessionType == " k d e " ) [
2008-01-04 10:54:33 +00:00
pkgs . kdelibs
pkgs . kdebase
2007-03-28 21:16:35 +00:00
xorg . iceauth # absolutely required by dcopserver
xorg . xset # used by startkde, non-essential
2007-03-06 00:07:00 +00:00
] ;
2007-03-30 12:55:09 +00:00
extraEtc =
optional ( sessionType == " k d e " )
2008-01-04 10:54:33 +00:00
{ source = " ${ pkgs . xkeyboard_config } / e t c / X 1 1 / x k b " ;
2007-03-30 12:55:09 +00:00
target = " X 1 1 / x k b " ;
2007-12-31 08:55:40 +00:00
}
++
2008-01-04 10:36:14 +00:00
optional cfg . exportConfiguration
2008-01-04 10:28:12 +00:00
{ source = " ${ configFile } " ;
target = " X 1 1 / x o r g . c o n f " ;
} ;
2007-03-30 12:55:09 +00:00
2007-03-06 00:07:00 +00:00
2008-01-04 10:28:12 +00:00
job = ''
2008-01-04 10:36:14 +00:00
start on $ { if cfg . autorun then " n e t w o r k - i n t e r f a c e s " else " n e v e r " }
2006-11-28 22:27:56 +00:00
2007-02-27 00:50:22 +00:00
start script
2007-06-05 11:51:59 +00:00
2007-06-09 19:46:57 +00:00
rm - f /var/run/opengl-driver
2007-05-28 14:09:04 +00:00
$ { if videoDriver == " n v i d i a "
2008-01-04 10:54:33 +00:00
then " l n - s f ${ pkgs . nvidiaDrivers } / v a r / r u n / o p e n g l - d r i v e r "
2007-11-09 18:49:45 +00:00
else if cfg . driSupport
2008-01-04 10:54:33 +00:00
then " l n - s f ${ pkgs . mesa } / v a r / r u n / o p e n g l - d r i v e r "
2007-03-06 00:07:00 +00:00
else " "
2007-05-28 14:09:04 +00:00
}
2007-06-05 11:51:59 +00:00
2008-01-04 10:28:12 +00:00
rm - f /var/log/slim.log
2007-06-05 11:51:59 +00:00
2007-02-27 00:50:22 +00:00
end script
2006-11-28 22:27:56 +00:00
2007-02-27 00:50:22 +00:00
env SLIM_CFGFILE = $ { slimConfig }
2007-06-05 11:51:59 +00:00
env SLIM_THEMESDIR = $ { slimThemesDir }
2008-01-04 10:54:33 +00:00
env FONTCONFIG_FILE = /etc/fonts/fonts.conf # !!! cleanup
env XKB_BINDIR = $ { xorg . xkbcomp } /bin # Needed for the Xkb extension.
env LD_LIBRARY_PATH = $ { xorg . libX11 } /lib : $ { xorg . libXext } /lib : /usr/lib / # related to xorg-sys-opengl - needed to load libglx for (AI)GLX support (for compiz)
2006-11-28 22:27:56 +00:00
2007-05-28 14:09:04 +00:00
$ { if videoDriver == " n v i d i a "
2008-01-04 10:54:33 +00:00
then " e n v X O R G _ D R I _ D R I V E R _ P A T H = ${ pkgs . nvidiaDrivers } / X 1 1 R 6 / l i b / m o d u l e s / d r i v e r s / "
2007-11-13 16:38:39 +00:00
else if cfg . driSupport
2008-01-04 10:54:33 +00:00
then " e n v X O R G _ D R I _ D R I V E R _ P A T H = ${ pkgs . mesa } / l i b / m o d u l e s / d r i "
2007-03-06 00:07:00 +00:00
else " "
2007-05-28 14:09:04 +00:00
}
2007-02-25 22:27:17 +00:00
2008-01-04 10:54:33 +00:00
exec $ { pkgs . slim } /bin/slim
2008-01-04 10:28:12 +00:00
'' ;
2006-11-28 22:27:56 +00:00
}