summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/applications/audio/audacity/default.nix7
-rw-r--r--pkgs/applications/audio/ladspa-plugins/default.nix7
-rw-r--r--pkgs/applications/audio/ladspa-plugins/ladspah.nix5
-rw-r--r--pkgs/applications/audio/snd/default.nix5
-rw-r--r--pkgs/applications/editors/bvi/default.nix17
-rwxr-xr-xpkgs/applications/editors/eclipse/builder.sh1
-rw-r--r--pkgs/applications/editors/eclipse/default.nix3
-rw-r--r--pkgs/applications/graphics/gocr/0.44.nix5
-rw-r--r--pkgs/applications/graphics/xfig/builder.sh5
-rw-r--r--pkgs/applications/graphics/xfig/default.nix4
-rw-r--r--pkgs/applications/graphics/xscreensaver/5.04.nix3
-rw-r--r--pkgs/applications/misc/xterm/default.nix1
-rw-r--r--pkgs/applications/networking/browsers/opera/default.nix9
-rw-r--r--pkgs/applications/networking/sync/unison/default.nix22
-rw-r--r--pkgs/applications/version-management/bazaar/default.nix22
-rw-r--r--pkgs/applications/version-management/cvs2svn/default.nix28
-rw-r--r--pkgs/applications/version-management/mercurial/default.nix21
-rw-r--r--pkgs/applications/virtualization/qemu/0.9.0.nix5
-rw-r--r--pkgs/applications/virtualization/qemu/linux-img/0.2.nix6
-rw-r--r--pkgs/applications/virtualization/virtualbox/1.5.2.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/bcop/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/ccsm/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/compiz-manager/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/compizconfig-python/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/config-backend/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/extra/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/libcompizconfig/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz-fusion/main/0.6.0.nix5
-rw-r--r--pkgs/applications/window-managers/compiz/0.6.2.nix5
-rw-r--r--pkgs/applications/window-managers/fbpanel/4.12.nix5
-rw-r--r--pkgs/applications/window-managers/xmonad/default.nix42
-rw-r--r--pkgs/build-support/fetchurl/mirrors.nix6
-rw-r--r--pkgs/build-support/make-wrapper/make-wrapper.sh19
-rw-r--r--pkgs/data/fonts/fontWrap/default.nix7
-rw-r--r--pkgs/development/compilers/ghcs/default.nix58
-rw-r--r--pkgs/development/compilers/jdk/builder.sh1
-rw-r--r--pkgs/development/compilers/jdk/default-5.nix9
-rw-r--r--pkgs/development/compilers/jdk/jdk5-sun-linux.nix23
-rw-r--r--pkgs/development/compilers/qi/9.1.nix5
-rw-r--r--pkgs/development/interpreters/erlang/builder.sh14
-rw-r--r--pkgs/development/interpreters/erlang/default.nix11
-rw-r--r--pkgs/development/interpreters/pyrex/0.9.6.nix5
-rw-r--r--pkgs/development/libraries/fftw/default.nix5
-rw-r--r--pkgs/development/libraries/glew/default.nix19
-rw-r--r--pkgs/development/libraries/haskell/Crypto/default.nix11
-rw-r--r--pkgs/development/libraries/haskell/X11/default.nix13
-rw-r--r--pkgs/development/libraries/haskell/binary/default.nix11
-rw-r--r--pkgs/development/libraries/haskell/cabal/cabal.nix95
-rw-r--r--pkgs/development/libraries/haskell/pcre-light/default.nix12
-rw-r--r--pkgs/development/libraries/haskell/uulib-ghc-6.6/builder.sh21
-rw-r--r--pkgs/development/libraries/haskell/uulib-ghc-6.6/default.nix11
-rw-r--r--pkgs/development/libraries/haskell/uulib/builder.sh51
-rw-r--r--pkgs/development/libraries/haskell/uulib/default.nix18
-rw-r--r--pkgs/development/libraries/haskell/vty/default.nix13
-rw-r--r--pkgs/development/libraries/haskell/zlib/default.nix11
-rw-r--r--pkgs/development/libraries/libdbi-drivers/0.8.2-1.nix5
-rw-r--r--pkgs/development/libraries/libdbi/0.8.2.nix5
-rw-r--r--pkgs/development/libraries/libextractor/0.5.18.nix5
-rw-r--r--pkgs/development/python-modules/ZopeInterface/default.nix6
-rw-r--r--pkgs/development/python-modules/twisted/default.nix6
-rw-r--r--pkgs/development/tools/documentation/haddock/default.nix11
-rw-r--r--pkgs/development/tools/haskell/uuagc/default.nix26
-rw-r--r--pkgs/development/tools/misc/indent/2.2.9.nix5
-rw-r--r--pkgs/development/tools/misc/intltool/0.36.2.nix5
-rw-r--r--pkgs/development/tools/misc/ltrace/default.nix5
-rw-r--r--pkgs/development/tools/parsing/alex/default.nix33
-rw-r--r--pkgs/development/tools/parsing/happy/happy-1.17.nix12
-rw-r--r--pkgs/games/construo/0.2.2.nix5
-rw-r--r--pkgs/games/fsg/alt-builder.nix8
-rw-r--r--pkgs/games/orbit/1.01.nix43
-rw-r--r--pkgs/lib/default.nix290
-rw-r--r--pkgs/lib/strings-with-deps.nix36
-rw-r--r--pkgs/misc/tex/nix/find-includes.pl1
-rw-r--r--pkgs/misc/trac/builder.sh6
-rw-r--r--pkgs/misc/trac/default.nix17
-rw-r--r--pkgs/os-specific/linux/atheros/0.9.3.3.nix5
-rw-r--r--pkgs/os-specific/linux/atheros/r2756.nix5
-rw-r--r--pkgs/os-specific/linux/atheros/r3122.nix5
-rw-r--r--pkgs/os-specific/linux/dmidecode/2.9.nix5
-rw-r--r--pkgs/os-specific/linux/dvd+rw-tools/7.0.nix5
-rw-r--r--pkgs/os-specific/linux/kqemu/1.3.0pre11.nix6
-rw-r--r--pkgs/os-specific/linux/module-init-tools/aggregator.nix7
-rw-r--r--pkgs/os-specific/linux/sdparm/1.02.nix5
-rw-r--r--pkgs/os-specific/linux/usbutils/default.nix10
-rw-r--r--pkgs/servers/http/apache-modules/tomcat-connectors/builder.sh8
-rw-r--r--pkgs/servers/http/apache-modules/tomcat-connectors/default.nix14
-rw-r--r--pkgs/servers/http/jboss/builder.sh18
-rw-r--r--pkgs/servers/http/jboss/default.nix20
-rw-r--r--pkgs/servers/sql/postgresql/default.nix6
-rw-r--r--pkgs/servers/xmpp/ejabberd/builder.sh9
-rw-r--r--pkgs/servers/xmpp/ejabberd/default.nix11
-rw-r--r--pkgs/stdenv/generic/setup-sh-defs.nix902
-rw-r--r--pkgs/tools/misc/grub/default.nix24
-rw-r--r--pkgs/tools/misc/mc/builder.sh7
-rw-r--r--pkgs/tools/misc/mc/default.nix11
-rw-r--r--pkgs/tools/misc/relfs/cvs.2007.12.01.nix5
-rw-r--r--pkgs/tools/networking/ntp/default.nix10
-rw-r--r--pkgs/tools/networking/p2p/bittorrent/builder.sh8
-rw-r--r--pkgs/tools/networking/p2p/bittorrent/default.nix12
-rw-r--r--pkgs/tools/package-management/nix/unstable.nix4
-rw-r--r--pkgs/tools/system/gdmap/0.7.5.nix5
-rw-r--r--pkgs/tools/system/pciutils/default.nix10
-rw-r--r--pkgs/tools/system/which/default.nix14
-rw-r--r--pkgs/tools/typesetting/lhs2tex/default.nix6
-rw-r--r--pkgs/top-level/all-packages.nix224
-rw-r--r--pkgs/top-level/build-for-release.nix2
-rw-r--r--pkgs/top-level/builder-defs.nix100
-rw-r--r--pkgs/top-level/template-composing+config.nix5
-rw-r--r--pkgs/top-level/template-composing-builder.nix10
109 files changed, 1396 insertions, 1354 deletions
diff --git a/pkgs/applications/audio/audacity/default.nix b/pkgs/applications/audio/audacity/default.nix
index 56ee6a56ccb88..3eaf1ed3ee08f 100644
--- a/pkgs/applications/audio/audacity/default.nix
+++ b/pkgs/applications/audio/audacity/default.nix
@@ -1,5 +1,5 @@
 args: with args;
-	with (builderDefs { 
+	let localDefs = builderDefs { 
 	  src = 
 		fetchurl {
 			url = mirror://sourceforge/audacity/audacity-src-1.3.3.tar.gz;
@@ -8,7 +8,8 @@ args: with args;
 
   	buildInputs =[(wxGTK null) libogg libvorbis libsndfile libmad pkgconfig gtk 
 		gettext glib];
-	} null);
+	} null;
+	in with localDefs;
 let 
 	postInstall = FullDepEntry ("
 		old_rpath=$(patchelf --print-rpath \$out/bin/audacity);
@@ -25,7 +26,7 @@ stdenv.mkDerivation {
   name = "audacity-1.3.3";
 
   builder = writeScript "audacity-1.3.3-builder"
-		(textClosure [addInputs (doDump "0") (noDepEntry "echo \$PATH; ar --version") doConfigure preBuild doMakeInstall postInstall doForceShare]);
+		(textClosure localDefs [addInputs (doDump "0") (noDepEntry "echo \$PATH; ar --version") doConfigure preBuild doMakeInstall postInstall doForceShare]);
 
   meta = {
     description = "
diff --git a/pkgs/applications/audio/ladspa-plugins/default.nix b/pkgs/applications/audio/ladspa-plugins/default.nix
index 70dc36240c653..9f2fcbc0ed0f4 100644
--- a/pkgs/applications/audio/ladspa-plugins/default.nix
+++ b/pkgs/applications/audio/ladspa-plugins/default.nix
@@ -1,5 +1,5 @@
 args: with args;
-	with (builderDefs {
+	let localDefs = builderDefs {
 		src = 
 		fetchurl {
 			url = http://plugin.org.uk/releases/0.4.15/swh-plugins-0.4.15.tar.gz;
@@ -7,7 +7,8 @@ args: with args;
 		};
 		buildInputs = [fftw ladspaH pkgconfig];
 		configureFlags = [];
-	} null);
+	} null;
+	in with localDefs;
 let
 	postInstall = FullDepEntry ("
 		ensureDir \$out/share/ladspa/
@@ -17,7 +18,7 @@ in
 stdenv.mkDerivation {
 	name = "swh-plugins-0.4.15";
 	builder = writeScript "swh-plugins-0.4.15-builder"
-		(textClosure [doConfigure doMakeInstall 
+		(textClosure localDefs [doConfigure doMakeInstall 
 			postInstall doForceShare]);
 	meta = {
 		description = "
diff --git a/pkgs/applications/audio/ladspa-plugins/ladspah.nix b/pkgs/applications/audio/ladspa-plugins/ladspah.nix
index b526e48b10ee1..65647cf0a22d6 100644
--- a/pkgs/applications/audio/ladspa-plugins/ladspah.nix
+++ b/pkgs/applications/audio/ladspa-plugins/ladspah.nix
@@ -6,10 +6,11 @@ let
 		sha256 = "1b908csn85ng9sz5s5d1mqk711cmawain2z8px2ajngihdrynb67";
 	};
 in
-	with builderDefs {
+	let localDefs = builderDefs {
 		buildInputs = [];
 		inherit src;
 	} null;
+	in with localDefs;
 let
 	copyFile = FullDepEntry ("
 		ensureDir \$out/include
@@ -19,7 +20,7 @@ in
 stdenv.mkDerivation {
 	name = "ladspa.h";
 	builder = writeScript "ladspa.h-builder"
-		(textClosure [copyFile]);
+		(textClosure localDefs [copyFile]);
 	meta = {
 		description = "
 	LADSPA format audio plugins.
diff --git a/pkgs/applications/audio/snd/default.nix b/pkgs/applications/audio/snd/default.nix
index 9a650570a6d2f..961d82fb88935 100644
--- a/pkgs/applications/audio/snd/default.nix
+++ b/pkgs/applications/audio/snd/default.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = 
 	fetchurl {
 		url = ftp://ccrma-ftp.stanford.edu/pub/Lisp/snd-9.4.tar.gz;
@@ -20,6 +20,7 @@ args : with args;
 			++ (lib.optional (args ? sndlib) "--with-midi" )
 			;
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 	let preBuild = FullDepEntry ("
 		cp config.log /tmp/snd-config.log
 	") [minInit doUnpack];
@@ -27,7 +28,7 @@ in
 stdenv.mkDerivation rec {
 	name = "Snd-9.4";
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure preBuild doMakeInstall doForceShare]);
+		(textClosure localDefs [doConfigure preBuild doMakeInstall doForceShare]);
 	meta = {
 		description = "
 		Snd sound editor.
diff --git a/pkgs/applications/editors/bvi/default.nix b/pkgs/applications/editors/bvi/default.nix
new file mode 100644
index 0000000000000..6d9ffdaecc813
--- /dev/null
+++ b/pkgs/applications/editors/bvi/default.nix
@@ -0,0 +1,17 @@
+args:
+args.stdenv.mkDerivation {
+  name = "bvi-1.3.2";
+
+  src = args.fetchurl {
+    url = http://prdownloads.sourceforge.net/bvi/bvi-1.3.2.src.tar.gz;
+    sha256 = "110wxqnyianqamxq4y53drqqxb9vp4k2fcvic45qggvlqkqhlfgz";
+  };
+
+  buildInputs =(with args; [ncurses]);
+
+  meta = { 
+      description = "hex editor with vim style keybindings";
+      homepage = http://bvi.sourceforge.net/download.html;
+      license = "GPL2";
+  };
+}
diff --git a/pkgs/applications/editors/eclipse/builder.sh b/pkgs/applications/editors/eclipse/builder.sh
index b38befee41ad7..6e064e1fa9b65 100755
--- a/pkgs/applications/editors/eclipse/builder.sh
+++ b/pkgs/applications/editors/eclipse/builder.sh
@@ -1,5 +1,4 @@
 source $stdenv/setup
-source $makeWrapper
 
 unpackFile $src 
 ensureDir $out
diff --git a/pkgs/applications/editors/eclipse/default.nix b/pkgs/applications/editors/eclipse/default.nix
index 71afb07eece54..23199bdcc129f 100644
--- a/pkgs/applications/editors/eclipse/default.nix
+++ b/pkgs/applications/editors/eclipse/default.nix
@@ -6,7 +6,8 @@ let {
       name = "eclipse-sdk-3.3.3.1";
       builder = ./builder.sh;
       src = bindist;
-      inherit makeWrapper jdk plugins;
+      buildInputs = [makeWrapper];
+      inherit jdk plugins;
       libraries = [gtk glib libXtst];
    };
 
diff --git a/pkgs/applications/graphics/gocr/0.44.nix b/pkgs/applications/graphics/gocr/0.44.nix
index 4bf7bda50cb24..b415fd6fb1256 100644
--- a/pkgs/applications/graphics/gocr/0.44.nix
+++ b/pkgs/applications/graphics/gocr/0.44.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 fetchurl {
 		url = http://prdownloads.sourceforge.net/jocr/gocr-0.44.tar.gz;
@@ -9,10 +9,11 @@ fetchurl {
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "gocr";
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		GPL Optical Character Recognition
diff --git a/pkgs/applications/graphics/xfig/builder.sh b/pkgs/applications/graphics/xfig/builder.sh
index de64fbce78fa2..dc943180508e2 100644
--- a/pkgs/applications/graphics/xfig/builder.sh
+++ b/pkgs/applications/graphics/xfig/builder.sh
@@ -1,5 +1,4 @@
 source $stdenv/setup
-source $makeWrapper
 
 makeFlags="XAWLIB=-lXaw3d BINDIR=$out/bin XAPPLOADDIR=$out/etc/X11/app-defaults LIBDIR=$out/lib/X11 XFIGDOCDIR=$out/share/doc/xfig MANPATH=$out/man"
 
@@ -16,9 +15,7 @@ installCommand=myInstall
 myInstall() {
     make install.all $makeFlags
 
-    mv $out/bin/xfig $out/bin/.xfig
-
-    makeWrapper $out/bin/.xfig $out/bin/xfig \
+    wrapProgram $out/bin/xfig \
         --set XAPPLRESDIR $out/etc/X11/app-defaults
 }
 
diff --git a/pkgs/applications/graphics/xfig/default.nix b/pkgs/applications/graphics/xfig/default.nix
index 0d94d4a655d0e..49de840e2dcbf 100644
--- a/pkgs/applications/graphics/xfig/default.nix
+++ b/pkgs/applications/graphics/xfig/default.nix
@@ -11,9 +11,7 @@ stdenv.mkDerivation {
 
   builder = ./builder.sh;
 
-  buildInputs = [imake x11 libXpm libXmu libXi libXp Xaw3d libpng libjpeg];
-
-  inherit makeWrapper;
+  buildInputs = [imake x11 libXpm libXmu libXi libXp Xaw3d libpng libjpeg makeWrapper];
 
   NIX_CFLAGS_COMPILE = "-I${libXpm}/include/X11";
 
diff --git a/pkgs/applications/graphics/xscreensaver/5.04.nix b/pkgs/applications/graphics/xscreensaver/5.04.nix
index 132bf997e18cd..a9fa7978237e0 100644
--- a/pkgs/applications/graphics/xscreensaver/5.04.nix
+++ b/pkgs/applications/graphics/xscreensaver/5.04.nix
@@ -1,4 +1,4 @@
-args : with args; with builderDefs (args // {
+args : with args; let localDefs = builderDefs (args // {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://www.jwz.org/xscreensaver/xscreensaver-5.04.tar.gz;
@@ -20,6 +20,7 @@ args : with args; with builderDefs (args // {
 				" --with-hackdir=\$out/share/xscreensaver-hacks ")
 		];
 	}) null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 	preConfigure = FullDepEntry ("
 		sed -e 's%@GTK_DATADIR@%@datadir@% ; s%@PO_DATADIR@%@datadir@%' "+
diff --git a/pkgs/applications/misc/xterm/default.nix b/pkgs/applications/misc/xterm/default.nix
index c1be706b547a8..97c8b42697f0e 100644
--- a/pkgs/applications/misc/xterm/default.nix
+++ b/pkgs/applications/misc/xterm/default.nix
@@ -7,5 +7,6 @@ stdenv.mkDerivation rec {
 	sha256 = "0qlz5nkdqkahdg9kbd1ni96n69srj1pd9yggwrw3z0kghaajb2sr";
   };
   buildInputs = [libXaw xproto libXt libX11 libSM libICE ncurses];
+  configureFlags = ["--enable-wide-chars"];
 }
 
diff --git a/pkgs/applications/networking/browsers/opera/default.nix b/pkgs/applications/networking/browsers/opera/default.nix
index d807add5111f6..7393cffe316df 100644
--- a/pkgs/applications/networking/browsers/opera/default.nix
+++ b/pkgs/applications/networking/browsers/opera/default.nix
@@ -20,8 +20,13 @@ stdenv.mkDerivation rec {
         sha256 = "0vv1q86is9x6vw8fx92wrnvlyn4x29zgk9zjn66rcx37n6grqqah";
       } else if (stdenv.system == "x86_64-linux") then
       fetchurl {
-        url = ftp://ftp.task.gda.pl/pub/opera/linux/950b/final/en/x86_64/opera-9.50-20071024.2-shared-qt.x86_64-1643.tar.bz2;
-        sha256 = "1gv1r18ar3vz1l24nf8qixjlba1yb5d3xvg3by41i4dy0vlznqn6";
+        url = http://snapshot.opera.com/unix/snapshot-1754/x86_64-linux/opera-9.50-20080110.2-shared-qt.x86_64-1754.tar.bz2;
+        sha256 = "08y1ajjncdvbhvcq2izmpgc4fi37bwn43zsw7rz41jf8qhvb5ywv";
+        #url = ftp://ftp.task.gda.pl/pub/opera/linux/950b/final/en/x86_64/opera-9.50-20071024.2-shared-qt.x86_64-1643.tar.bz2;
+        #sha256 = "1gv1r18ar3vz1l24nf8qixjlba1yb5d3xvg3by41i4dy0vlznqn6";
+        #name = opera-9.25-20071214.6-shared-qt.i386-en.tar.gz;
+        #url = http://www.opera.com/download/get.pl?id=30462&location=225&nothanks=yes&sub=marine;
+        #sha256 = "1wnc1s4r5gz73mxs8pgsi9a1msz7x8a8pb1ykb1xgdfn21h69p2p";
       } else throw "unsupported platform ${stdenv.system} (only i686-linux and x86_64 linux supported yet)";
 
   # operapluginwrapper seems to require libXt ?
diff --git a/pkgs/applications/networking/sync/unison/default.nix b/pkgs/applications/networking/sync/unison/default.nix
index 75c976a432940..0883c236d0107 100644
--- a/pkgs/applications/networking/sync/unison/default.nix
+++ b/pkgs/applications/networking/sync/unison/default.nix
@@ -7,21 +7,15 @@ stdenv.mkDerivation {
     sha256 = "808400a933aeb67654edc770822cd186d1b2adc92e7cb5836996c71c69ffe656";
   };
 
-  buildInputs = [ocaml];
+  buildInputs = [ocaml makeWrapper];
 
-  addInputsHook = "source $makeWrapper";
-  preBuild = "sed -i \"s|\\(OCAMLOPT=.*\\)$|\\1 -I $lablgtk/lib/ocaml/lablgtk2|\" Makefile.OCaml";
+  preBuild = "sed -i \"s|\\(OCAMLOPT=.*\\)$|\\1 -I ${lablgtk}/lib/ocaml/lablgtk2|\" Makefile.OCaml";
   makeFlags = "UISTYLE=gtk2 INSTALLDIR=$(out)/bin/";
   preInstall = "ensureDir $out/bin";
-  postInstall = [
-    "for i in $(cd $out/bin && ls); do"
-    "   mv $out/bin/$i $out/bin/.orig-$i;"
-    "   echo \"#! $SHELL\" > $out/bin/$i;"
-    "   echo \"$xset/bin/xset q | grep -q \\\"$fontschumachermisc\\\" || $xset/bin/xset +fp \\\"$fontschumachermisc/lib/X11/fonts/misc\\\"\" >> $out/bin/$i;"
-    "   echo \"exec \\\"$out/bin/.orig-$i\\\" \\\"\\\$@\\\"\" >> $out/bin/$i;"
-    "   chmod +x $out/bin/$i;"
-    "done"
-  ];
-
-  inherit lablgtk fontschumachermisc xset makeWrapper;
+  postInstall = ''
+    for i in $(cd $out/bin && ls); do
+      wrapProgram $out/bin/$i \
+        --run "${xset}/bin/xset q | grep -q \"${fontschumachermisc}\" || ${xset}/bin/xset +fp \"${fontschumachermisc}/lib/X11/fonts/misc\""
+    done
+  '';
 }
diff --git a/pkgs/applications/version-management/bazaar/default.nix b/pkgs/applications/version-management/bazaar/default.nix
new file mode 100644
index 0000000000000..71134c0841ad8
--- /dev/null
+++ b/pkgs/applications/version-management/bazaar/default.nix
@@ -0,0 +1,22 @@
+{stdenv, fetchurl, python, makeWrapper}:
+
+stdenv.mkDerivation {
+  name = "bazaar-1.1";
+
+  src = fetchurl {
+    url = https://launchpad.net/bzr/1.1/1.1/+download/bzr-1.1.tar.gz;
+    sha256 = "1qpkw580r22yxybdghx2ha0kyk22brbhd1kg9wwjh209dqy2gqzc";
+  };
+
+  buildInputs = [python makeWrapper];
+
+  installPhase = ''
+    python setup.py install --prefix=$out
+    wrapProgram $out/bin/bzr --prefix PYTHONPATH : "$(toPythonPath $out)"
+  '';
+
+  meta = {
+    homepage = http://bazaar-vcs.org/;
+    description = "A distributed version control system that Just Works";
+  };
+}
diff --git a/pkgs/applications/version-management/cvs2svn/default.nix b/pkgs/applications/version-management/cvs2svn/default.nix
index e519be9273356..65c2c84d0da1f 100644
--- a/pkgs/applications/version-management/cvs2svn/default.nix
+++ b/pkgs/applications/version-management/cvs2svn/default.nix
@@ -1,25 +1,27 @@
-{stdenv, fetchurl, python, bsddb3, makeWrapper}:
+{stdenv, fetchurl, python, makeWrapper}:
 
 stdenv.mkDerivation {
-  name = "cvs2svn-1.5.1";
+  name = "cvs2svn-2.0.1";
 
   src = fetchurl {
-    url = http://cvs2svn.tigris.org/files/documents/1462/36129/cvs2svn-1.5.1.tar.gz;
-    md5 = "d1e42ea51b373be0023f2b3f6b80ec01";
+    url = http://cvs2svn.tigris.org/files/documents/1462/39919/cvs2svn-2.0.1.tar.gz;
+    sha256 = "1pgbyxzgn22lnw3h5c2nd8z46pkk863jg3fgh9pqa1jihsx1cg1j";
   };
 
-  buildInputs = [python bsddb3];
+  buildInputs = [python makeWrapper];
 
   buildPhase = "true";
-  installPhase = "
+  installPhase = ''
     python ./setup.py install --prefix=$out
-
-    source ${makeWrapper}
-    mv $out/bin/cvs2svn $out/bin/.orig-cvs2svn
-    makeWrapper $out/bin/.orig-cvs2svn $out/bin/cvs2svn \\
-        --set PYTHONPATH \"$(toPythonPath $out):$(toPythonPath ${bsddb3}):$PYTHONPATH\"
-  ";
+    wrapProgram $out/bin/cvs2svn \
+        --set PYTHONPATH "$(toPythonPath $out):$PYTHONPATH"
+  '';
 
   /* !!! maybe we should absolutise the program names in
      $out/lib/python2.4/site-packages/cvs2svn_lib/config.py. */
-}
\ No newline at end of file
+
+  meta = {
+    description = "A tool to convert CVS repositories to Subversion repositories";
+    homepage = http://cvs2svn.tigris.org/;
+  };
+}
diff --git a/pkgs/applications/version-management/mercurial/default.nix b/pkgs/applications/version-management/mercurial/default.nix
index f65a34ec5c452..408c9d8ebac0d 100644
--- a/pkgs/applications/version-management/mercurial/default.nix
+++ b/pkgs/applications/version-management/mercurial/default.nix
@@ -7,20 +7,17 @@ stdenv.mkDerivation {
     sha256 = "1n34yl4z7nc3vmsgpkmqc94hsmy846ny86xgpgv3m371ljm2pq6g";
   };
 
-  inherit makeWrapper;
-
-  buildInputs = [ python ];
-  addInputsHook = "source $makeWrapper";
+  buildInputs = [ python makeWrapper ];
   makeFlags = "PREFIX=$(out)";
-  postInstall = [
-    "for i in $(cd $out/bin && ls); do"
-    "   mv $out/bin/$i $out/bin/.orig-$i;"
-    "   makeWrapper $out/bin/.orig-$i $out/bin/$i"
-    "       --set PYTHONPATH \"$(toPythonPath $out):$PYTHONPATH:\$PYTHONPATH\";"
-    "done"
-  ];
+  postInstall = ''
+    for i in $(cd $out/bin && ls); do
+      wrapProgram $out/bin/$i \
+        --prefix PYTHONPATH : "$(toPythonPath $out)"
+    done
+  '';
 
   meta = {
-    description = "a fast, lightweight SCM system for very large distributed projects";
+    description = "A fast, lightweight SCM system for very large distributed projects";
+    homepage = http://www.selenic.com/mercurial/;
   };
 }
diff --git a/pkgs/applications/virtualization/qemu/0.9.0.nix b/pkgs/applications/virtualization/qemu/0.9.0.nix
index 8604f5ae66b75..439ec34a8c380 100644
--- a/pkgs/applications/virtualization/qemu/0.9.0.nix
+++ b/pkgs/applications/virtualization/qemu/0.9.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://fabrice.bellard.free.fr/qemu/qemu-0.9.0.tar.gz;
@@ -9,6 +9,7 @@ args : with args;
 		buildInputs = [ SDL zlib which ];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 preConfigure = FullDepEntry ("
   gcc --version
@@ -17,7 +18,7 @@ in
 stdenv.mkDerivation rec {
 	name = "qemu-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [ preConfigure doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [ preConfigure doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		QEmu processor emulator.
diff --git a/pkgs/applications/virtualization/qemu/linux-img/0.2.nix b/pkgs/applications/virtualization/qemu/linux-img/0.2.nix
index 02ac87ef2e2fc..ae1933b9d1d81 100644
--- a/pkgs/applications/virtualization/qemu/linux-img/0.2.nix
+++ b/pkgs/applications/virtualization/qemu/linux-img/0.2.nix
@@ -1,6 +1,5 @@
-
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://fabrice.bellard.free.fr/qemu/linux-0.2.img.bz2;
@@ -9,6 +8,7 @@ args : with args;
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 doCopy = FullDepEntry ("
   ensureDir \$out/share/qemu-images
@@ -18,7 +18,7 @@ in
 stdenv.mkDerivation rec {
 	name = "QEmu-Linux-Image-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doCopy doForceShare doPropagate]);
+		(textClosure localDefs [doCopy doForceShare doPropagate]);
 	meta = {
 		description = "
 		${abort "Write a description"}
diff --git a/pkgs/applications/virtualization/virtualbox/1.5.2.nix b/pkgs/applications/virtualization/virtualbox/1.5.2.nix
index e633c55a26347..e8f2988ade2a0 100644
--- a/pkgs/applications/virtualization/virtualbox/1.5.2.nix
+++ b/pkgs/applications/virtualization/virtualbox/1.5.2.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://www.virtualbox.org/download/1.5.2/VirtualBox-1.5.2_OSE.tar.bz2;
@@ -9,10 +9,11 @@ args : with args;
 		      wine jre libxslt libIDL SDL qt3 openssl zlib];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "VirtualBox-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Virtual Box is just software for running virtual machines. 
diff --git a/pkgs/applications/window-managers/compiz-fusion/bcop/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/bcop/0.6.0.nix
index 1072e9b363c11..6337d6a4ebe02 100644
--- a/pkgs/applications/window-managers/compiz-fusion/bcop/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/bcop/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/compiz-bcop-0.6.0.tar.bz2;
@@ -9,6 +9,7 @@ args : with args;
 		propagatedBuildInputs = [getopt libxslt];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 	fixPkgconfig = FullDepEntry ("
 		ensureDir \$out/lib
@@ -21,7 +22,7 @@ in
 stdenv.mkDerivation rec {
 	name = "compiz-bcop-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doAutotools doConfigure doMakeInstall fixPkgconfig fixInterpreter doForceShare 
+		(textClosure localDefs [doAutotools doConfigure doMakeInstall fixPkgconfig fixInterpreter doForceShare 
 			doPropagate]);
 	inherit propagatedBuildInputs;
 	meta = {
diff --git a/pkgs/applications/window-managers/compiz-fusion/ccsm/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/ccsm/0.6.0.nix
index fba1c5d995f61..6e3448bebf81d 100644
--- a/pkgs/applications/window-managers/compiz-fusion/ccsm/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/ccsm/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/ccsm-0.6.0.tar.bz2;
@@ -15,10 +15,11 @@ args : with args;
 			"PYTHONPATH" "$(toPythonPath ${pygtk})/gtk-2.0"
 		];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "compizconfig-settings-"+args.version;
 	builder = writeScript (name + "-builder")
-		(textClosure [installPythonPackage (doWrap "\$out/bin/ccsm")]);
+		(textClosure localDefs [installPythonPackage (doWrap "\$out/bin/ccsm")]);
 	meta = {
 		description = "
 	Compiz Settings Manager
diff --git a/pkgs/applications/window-managers/compiz-fusion/compiz-manager/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/compiz-manager/0.6.0.nix
index a388550748083..6033ea1663af3 100644
--- a/pkgs/applications/window-managers/compiz-fusion/compiz-manager/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/compiz-manager/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/compiz-manager-0.6.0.tar.bz2;
@@ -20,6 +20,7 @@ args : with args;
 			"XORG_DRIVER_PATH" "/nix/store/.*"
 		]];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	install = FullDepEntry ("
 		sed -e '/Checking for texture_from_pixmap:/areturn 0' -i compiz-manager
@@ -34,7 +35,7 @@ in
 stdenv.mkDerivation rec {
 	name = "compiz-manager-"+args.version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doUnpack doReplaceScripts install doPropagate doForceShare]);
+		(textClosure localDefs [doUnpack doReplaceScripts install doPropagate doForceShare]);
 	meta = {
 		description = "
 	Compiz Launch Manager
diff --git a/pkgs/applications/window-managers/compiz-fusion/compizconfig-python/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/compizconfig-python/0.6.0.nix
index 73f1c653361c0..64247cb1b8d2f 100644
--- a/pkgs/applications/window-managers/compiz-fusion/compizconfig-python/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/compizconfig-python/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0.1/compizconfig-python-0.6.0.1.tar.bz2;
@@ -9,10 +9,11 @@ args : with args;
 			[libcompizconfig bcop python pyrex configBackendGConf];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "compizconfig-python-"+args.version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doAutotools doConfigure doMakeInstall doForceShare]);
+		(textClosure localDefs [doAutotools doConfigure doMakeInstall doForceShare]);
 	meta = {
 		description = "
 	Compiz configuration - Python part.
diff --git a/pkgs/applications/window-managers/compiz-fusion/config-backend/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/config-backend/0.6.0.nix
index 3405ae0ce97ab..12ef3bb58a03d 100644
--- a/pkgs/applications/window-managers/compiz-fusion/config-backend/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/config-backend/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/compizconfig-backend-gconf-0.6.0.tar.bz2;
@@ -10,10 +10,11 @@ args : with args;
 		configureFlags = [];
 		forceShare = ["man" "doc" "info" "lib/compizconfig"];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "compizconfig-backend-GConf-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doAutotools doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doAutotools doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Compiz configuration backend (GConf).
diff --git a/pkgs/applications/window-managers/compiz-fusion/extra/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/extra/0.6.0.nix
index e304eb9d6ae4d..cc6b2f215cab8 100644
--- a/pkgs/applications/window-managers/compiz-fusion/extra/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/extra/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/compiz-fusion-plugins-extra-0.6.0.tar.bz2;
@@ -9,6 +9,7 @@ args : with args;
 		[bcop libjpeg gettext pluginsMain];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	sharePlugins = FullDepEntry ("
 		ensureDir \$out/share/compiz-plugins
@@ -22,7 +23,7 @@ in
 stdenv.mkDerivation rec {
 	name = "compiz-fusion-plugins-extra-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [fixIncludes doConfigure doMakeInstall sharePlugins doForceShare]);
+		(textClosure localDefs [fixIncludes doConfigure doMakeInstall sharePlugins doForceShare]);
 	meta = {
 		description = "
 	Extra Compiz Fusion plugins.
diff --git a/pkgs/applications/window-managers/compiz-fusion/libcompizconfig/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/libcompizconfig/0.6.0.nix
index 8b5d729dc2dc4..5602c65786737 100644
--- a/pkgs/applications/window-managers/compiz-fusion/libcompizconfig/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/libcompizconfig/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/libcompizconfig-0.6.0.tar.bz2;
@@ -9,10 +9,11 @@ args : with args;
 			[bcop];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "libcompizconfig-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doAutotools doConfigure doMakeInstall doForceShare]);
+		(textClosure localDefs [doAutotools doConfigure doMakeInstall doForceShare]);
 	meta = {
 		description = "
 	Compiz configuration backend library.
diff --git a/pkgs/applications/window-managers/compiz-fusion/main/0.6.0.nix b/pkgs/applications/window-managers/compiz-fusion/main/0.6.0.nix
index 40261da5cc4e8..deb4b2e3a5760 100644
--- a/pkgs/applications/window-managers/compiz-fusion/main/0.6.0.nix
+++ b/pkgs/applications/window-managers/compiz-fusion/main/0.6.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/0.6.0/compiz-fusion-plugins-main-0.6.0.tar.bz2;
@@ -9,6 +9,7 @@ args : with args;
 		[bcop libjpeg gettext];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	sharePlugins = FullDepEntry ("
 		ensureDir \$out/share/compiz-plugins
@@ -18,7 +19,7 @@ in
 stdenv.mkDerivation rec {
 	name = "compiz-fusion-plugins-main-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall sharePlugins doForceShare]);
+		(textClosure localDefs [doConfigure doMakeInstall sharePlugins doForceShare]);
 	meta = {
 		description = "
 	Main Compiz Fusion plugins.
diff --git a/pkgs/applications/window-managers/compiz/0.6.2.nix b/pkgs/applications/window-managers/compiz/0.6.2.nix
index 6eef24beb9948..78369081bc9d6 100644
--- a/pkgs/applications/window-managers/compiz/0.6.2.nix
+++ b/pkgs/applications/window-managers/compiz/0.6.2.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://releases.compiz-fusion.org/compiz/0.6.2/compiz-0.6.2.tar.bz2;
@@ -22,6 +22,7 @@ args : with args;
 			(if args ? extraConfigureFlags then args.extraConfigureFlags else []);
 		patches = [ ./glx-patch-0.6.2.patch ];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	postAll = FullDepEntry ("
     for i in $out/bin/*; do
@@ -36,7 +37,7 @@ stdenv.mkDerivation
 rec {
 	name = "compiz-0.6.2";
 	builder = writeScript (name + "-builder")
-		(textClosure [doPatch doConfigure doMakeInstall doPropagate 
+		(textClosure localDefs [doPatch doConfigure doMakeInstall doPropagate 
 			doForceShare postAll]);
 	inherit propagatedBuildInputs;
 	meta = {
diff --git a/pkgs/applications/window-managers/fbpanel/4.12.nix b/pkgs/applications/window-managers/fbpanel/4.12.nix
index 4e08102af80ae..1958ffa642bf0 100644
--- a/pkgs/applications/window-managers/fbpanel/4.12.nix
+++ b/pkgs/applications/window-managers/fbpanel/4.12.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://garr.dl.sourceforge.net/sourceforge/fbpanel/fbpanel-4.12.tgz;
@@ -10,10 +10,11 @@ args : with args;
 		  libpng libjpeg libtiff librsvg];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "fbpanel";
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Just a desktop panel.	
diff --git a/pkgs/applications/window-managers/xmonad/default.nix b/pkgs/applications/window-managers/xmonad/default.nix
new file mode 100644
index 0000000000000..ccd2dc05adbee
--- /dev/null
+++ b/pkgs/applications/window-managers/xmonad/default.nix
@@ -0,0 +1,42 @@
+{stdenv, fetchurl, ghc, X11, xmessage}:
+
+stdenv.mkDerivation (rec {
+
+  pname = "xmonad";
+  version = "0.5";
+
+  name = "${pname}-${version}";
+
+  src = fetchurl {
+    url = "http://hackage.haskell.org/packages/archive/${pname}/${version}/${name}.tar.gz";
+    sha256 = "cfcc4501b000fa740ed35a5be87dc01216e036219551630dcf71d9c3cf57e4c4";
+  };
+
+  buildInputs = [ghc X11];
+
+  meta = {
+    description = "xmonad is a tiling window manager for X";
+  };
+
+  configurePhase = '' 
+    sed -i 's|"xmessage"|"${xmessage}/bin/xmessage"|' XMonad/Core.hs
+    ghc --make Setup.lhs
+    ./Setup configure --prefix="$out"
+  '';
+
+  buildPhase = ''
+    ./Setup build
+  '';
+
+  installPhase = ''
+    ./Setup copy
+    ./Setup register --gen-script
+    mkdir $out/nix-support
+    sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
+    cp register.sh $out/nix-support/register-ghclib.sh
+    sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
+    mkdir -p $out/bin
+    cp register.sh $out/bin/register-ghclib-${name}.sh
+  '';
+
+})
diff --git a/pkgs/build-support/fetchurl/mirrors.nix b/pkgs/build-support/fetchurl/mirrors.nix
index 2fc8ce4eec29d..52fc9dfa2c18c 100644
--- a/pkgs/build-support/fetchurl/mirrors.nix
+++ b/pkgs/build-support/fetchurl/mirrors.nix
@@ -42,4 +42,10 @@ rec {
     ftp://ftp.heanet.ie/mirrors/ftp.kde.org/
     ftp://ftp.kde.org/pub/kde/
   ];
+
+  # Gentoo files.
+  gentoo = [
+    http://www.ibiblio.org/pub/Linux/distributions/gentoo/
+    http://distfiles.gentoo.org/
+  ];
 }
diff --git a/pkgs/build-support/make-wrapper/make-wrapper.sh b/pkgs/build-support/make-wrapper/make-wrapper.sh
index 847db8910fd5b..558ff94c1a03a 100644
--- a/pkgs/build-support/make-wrapper/make-wrapper.sh
+++ b/pkgs/build-support/make-wrapper/make-wrapper.sh
@@ -1,6 +1,7 @@
 makeWrapper() {
-    original=$1
-    wrapper=$2
+    local original=$1
+    local wrapper=$2
+    local params varName value command separator n fileNames
 
     ensureDir "$(dirname $wrapper)"
 
@@ -17,6 +18,12 @@ makeWrapper() {
             echo "export $varName=$value" >> $wrapper
         fi
 
+        if test "$p" = "--run"; then
+            command=${params[$((n + 1))]}
+            n=$((n + 1))
+            echo "$command" >> $wrapper
+        fi
+
         if test "$p" = "--suffix" -o "$p" = "--prefix"; then
             varName=${params[$((n + 1))]}
             separator=${params[$((n + 2))]}
@@ -72,3 +79,11 @@ filterExisting() {
         fi
     done
 }
+
+# Syntax: wrapProgram <PROGRAM> <MAKE-WRAPPER FLAGS...>
+wrapProgram() {
+    local prog="$1"
+    local hidden="$(dirname "$prog")/.wrapped-$(basename "$prog")"
+    mv $prog $hidden
+    makeWrapper $hidden $prog "$@"
+}
diff --git a/pkgs/data/fonts/fontWrap/default.nix b/pkgs/data/fonts/fontWrap/default.nix
index ef370be8e3565..8bc120c686a93 100644
--- a/pkgs/data/fonts/fontWrap/default.nix
+++ b/pkgs/data/fonts/fontWrap/default.nix
@@ -1,9 +1,10 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src =""; /* put a fetchurl here */
 		buildInputs = [mkfontdir mkfontscale];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	doInstall = FullDepEntry ("
 		ensureDir \$out/share/fonts/
@@ -18,10 +19,10 @@ in
 stdenv.mkDerivation rec {
 	name = "wrapped-font-dir";
 	builder = writeScript (name + "-builder")
-		(textClosure [ doInstall doForceShare doPropagate]);
+		(textClosure localDefs [ doInstall doForceShare doPropagate]);
 	meta = {
 		description = "
-		Just a wrapper to create fots.dir and fonts.scale .
+		Just a wrapper to create fonts.dir and fonts.scale .
 ";
 	};
 }
diff --git a/pkgs/development/compilers/ghcs/default.nix b/pkgs/development/compilers/ghcs/default.nix
index c026a860d40cf..b4e14c9921d8a 100644
--- a/pkgs/development/compilers/ghcs/default.nix
+++ b/pkgs/development/compilers/ghcs/default.nix
@@ -47,7 +47,7 @@
       rec {
         # using undocumented feature that attribute can contain hyphens when using listToAttrs
         # You should be able to get the attribute values using __getAttr
-        result = builtins.listToAttrs (map ( l : lib.av l.name (
+        result = builtins.listToAttrs (map ( l : lib.nv l.name (
                                packageByPackageDB ghc l.name 
                                       ("lib/ghc-${ghc.version}/${l.name}.conf")
                                       (map (n: builtins.getAttr n result) l.deps)
@@ -80,6 +80,7 @@
        +" --prefix=\$out "
        +" --with-ghc=\$ghcboot/bin/ghc"
        +" --with-gmp-libraries=$gmp/lib"
+       +" --with-gmp-includes=${gmp}/include"
        +" --with-readline-libraries=\"$readline/lib\"";
 
       # now read the main package.conf and create a single package db file for each of them
@@ -107,26 +108,26 @@
 
     # Why this effort? If you want to use pretty-0.9 you can do this now without cabal choosing the 1.0 version hassle 
     core_libs = resolveDeps ghc
-      [ { name = "Cabal-1.2.0"; deps = ["base-2.1" "pretty-1.0" "old-locale-1.0" "old-time-1.0" "directory-1.0" "unix-2.0" "process-1.0" "array-0.1" "containers-0.1" "rts-1.0" "filepath-1.0"];} #
-        { name = "array-0.1"; deps = ["base-2.1"];}
-        { name = "base-2.1"; deps = [];} #
-        { name = "bytestring-0.9"; deps = [ "base-2.1" "array-0.1" ];}
-        { name = "containers-0.1"; deps = [ "base-2.1" "array-0.1" ];}
-        { name = "directory-1.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0"];}
-        { name = "filepath-1.0"; deps = [ "base-2.1" ];} #
-        { name = "ghc-6.8.0.20071004"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "array-0.1" "containers-0.1" "hpc-0.5" "bytestring-0.9" "pretty-1.0" "packedstring-0.1" "template-haskell-0.1" "unix-2.0" "process-1.0" "readline-1.0" "Cabal-1.2.0" "random-1.0" "haskell98-1.0"];}
-        { name = "haskell98-1.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "random-1.0" "unix-2.0" "process-1.0" "array-0.1"];}
-        { name = "hpc-0.5"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "array-0.1" "containers-0.1"]; }
-        { name = "old-locale-1.0"; deps = [ "base-2.1"];}
-        { name = "old-time-1.0"; deps = [ "base-2.1" "old-locale-1.0" ];}
-        { name = "packedstring-0.1"; deps = [ "base-2.1" "array-0.1" ];}
-        { name = "pretty-1.0"; deps = [ "base-2.1" ];}
-        { name = "process-1.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "unix-2.0"];}
-        { name = "random-1.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0"];}
-        { name = "readline-1.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "unix-2.0" "process-1.0" ];}
-        { name = "rts-1.0"; deps = [ "base-2.1" ];} #
-        { name = "template-haskell-0.1"; deps = [ "base-2.1" "pretty-1.0" "array-0.1" "packedstring-0.1" "containers-0.1" ];}
-        { name = "unix-2.0"; deps = [ "base-2.1" "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" ];}
+      [ { name = "Cabal-1.2.3.0"; deps = ["base-3.0.1.0" "pretty-1.0.0.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "directory-1.0.0.0" "unix-2.3.0.0" "process-1.0.0.0" "array-0.1.0.0" "containers-0.1.0.1" "rts-1.0" "filepath-1.1.0.0"];} #
+        { name = "array-0.1.0.0"; deps = ["base-3.0.1.0"];}
+        { name = "base-3.0.1.0"; deps = [];} #
+        { name = "bytestring-0.9.0.1"; deps = [ "base-3.0.1.0" "array-0.1.0.0" ];}
+        { name = "containers-0.1.0.1"; deps = [ "base-3.0.1.0" "array-0.1.0.0" ];}
+        { name = "directory-1.0.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0"];}
+        { name = "filepath-1.1.0.0"; deps = [ "base-3.0.1.0" ];} #
+        { name = "ghc-${version}"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "array-0.1.0.0" "containers-0.1.0.1" "hpc-0.5.0.0" "bytestring-0.9.0.1" "pretty-1.0.0.0" "packedstring-0.1.0.0" "template-haskell-2.2.0.0" "unix-2.3.0.0" "process-1.0.0.0" "readline-1.0.1.0" "Cabal-1.2.3.0" "random-1.0.0.0" "haskell98-1.0.1.0"];}
+        { name = "haskell98-1.0.1.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "random-1.0.0.0" "unix-2.3.0.0" "process-1.0.0.0" "array-0.1.0.0"];}
+        { name = "hpc-0.5.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "array-0.1.0.0" "containers-0.1.0.1"]; }
+        { name = "old-locale-1.0.0.0"; deps = [ "base-3.0.1.0"];}
+        { name = "old-time-1.0.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" ];}
+        { name = "packedstring-0.1.0.0"; deps = [ "base-3.0.1.0" "array-0.1.0.0" ];}
+        { name = "pretty-1.0.0.0"; deps = [ "base-3.0.1.0" ];}
+        { name = "process-1.0.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "unix-2.3.0.0"];}
+        { name = "random-1.0.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0"];}
+        { name = "readline-1.0.1.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "unix-2.3.0.0" "process-1.0.0.0" ];}
+        { name = "rts-1.0"; deps = [ "base-3.0.1.0" ];} #
+        { name = "template-haskell-2.2.0.0"; deps = [ "base-3.0.1.0" "pretty-1.0.0.0" "array-0.1.0.0" "packedstring-0.1.0.0" "containers-0.1.0.1" ];}
+        { name = "unix-2.3.0.0"; deps = [ "base-3.0.1.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" ];}
       ];
 
       
@@ -137,18 +138,20 @@
 
   } );
 
-  ghc68 = ghcAndLibraries {
-    version = "6.8.0.20071004";
+  ghc68 = ghcAndLibraries rec {
+    version = "6.8.2";
     src = fetchurl {
-      url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.0.20071004-src.tar.bz2;
-      sha256 = "1yyl7sxykmvkiwfxkfzpqa6cmgw19phkyjcdv99ml22j16wli63l";
+      #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.0.20071004-src.tar.bz2;
+      #sha256 = "1yyl7sxykmvkiwfxkfzpqa6cmgw19phkyjcdv99ml22j16wli63l";
+      url = "http://www.haskell.org/ghc/dist/stable/dist/ghc-${version}-src.tar.bz2";
+      md5 = "745c6b7d4370610244419cbfec4b2f84";
       #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.20070912-src.tar.bz2;
       #sha256 = "1b1gvi7hc7sc0fkh29qvzzd5lgnlvdv3ayiak4mkfnzkahvmq85s";
     };
 
     extra_src = fetchurl {
-      url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.0.20071004-src-extralibs.tar.bz2;
-      sha256 = "0vjx4vb2xhv5v2wj74ii3gpjim7x9wj0m87zglqlhc8xn31pmrd2";
+      url = "http://www.haskell.org/ghc/dist/stable/dist/ghc-${version}-src-extralibs.tar.bz2";
+      sha256 = "044mpbzpkbxcnqhjnrnmjs00mr85057d123rrlz2vch795lxbkcn";
       #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.20070912-src-extralibs.tar.bz2;
       #sha256 = "0py7d9nh3lkhjxr3yb3n9345d0hmzq79bi40al5rcr3sb84rnp9r";
     };
@@ -165,4 +168,3 @@
 
   };
 }
-
diff --git a/pkgs/development/compilers/jdk/builder.sh b/pkgs/development/compilers/jdk/builder.sh
index 1b61d548c1bcb..71dd6c433f67b 100644
--- a/pkgs/development/compilers/jdk/builder.sh
+++ b/pkgs/development/compilers/jdk/builder.sh
@@ -1,3 +1,4 @@
+buildInputs="$unzip"
 source $stdenv/setup
 
 src=$filename.bin
diff --git a/pkgs/development/compilers/jdk/default-5.nix b/pkgs/development/compilers/jdk/default-5.nix
new file mode 100644
index 0000000000000..1cb83ca5ddc7f
--- /dev/null
+++ b/pkgs/development/compilers/jdk/default-5.nix
@@ -0,0 +1,9 @@
+{stdenv, fetchurl, unzip}: 
+
+if stdenv.system == "i686-linux"
+  then
+    (import ./jdk5-sun-linux.nix) {
+      inherit stdenv fetchurl unzip;
+    }
+  else
+    abort "the Java 5 SDK is not supported on this platform"
diff --git a/pkgs/development/compilers/jdk/jdk5-sun-linux.nix b/pkgs/development/compilers/jdk/jdk5-sun-linux.nix
new file mode 100644
index 0000000000000..479a5a456af40
--- /dev/null
+++ b/pkgs/development/compilers/jdk/jdk5-sun-linux.nix
@@ -0,0 +1,23 @@
+/**
+ * This Nix expression requires the user to download the j2sdk
+ * distribution to /tmp. Please obtain jdk-1_5_0_14-linux-i586.bin
+ * from java.sun.com by hand and place it in /tmp. Blame Sun, not me.
+ *
+ * Note that this is not necessary if someone has already pushed a
+ * binary.
+ */
+{stdenv, fetchurl, unzip}: 
+
+assert stdenv.system == "i686-linux";
+
+stdenv.mkDerivation {
+  name = "jdk-1.5.0_14";
+  filename = "jdk-1_5_0_14";
+  dirname = "jdk1.5.0_14";
+  builder = ./builder.sh;
+  pathname = "/tmp/jdk-1_5_0_14-linux-i586.bin";
+  md5 = "32df8f2be09c3a0f39da1b3869164b55";
+  stdenv = stdenv;
+
+  inherit unzip;
+}
diff --git a/pkgs/development/compilers/qi/9.1.nix b/pkgs/development/compilers/qi/9.1.nix
index 661bb85e79894..3a1a4f37886b3 100644
--- a/pkgs/development/compilers/qi/9.1.nix
+++ b/pkgs/development/compilers/qi/9.1.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://www.lambdassociates.org/Download/Qi9.1.zip;
@@ -8,6 +8,7 @@ args : with args;
 		buildInputs = [ unzip clisp];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 	shell=stdenv.shell;
 in
@@ -28,7 +29,7 @@ in
 stdenv.mkDerivation rec {
 	name = "Qi-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [allBuild doForceShare doPropagate]);
+		(textClosure localDefs [allBuild doForceShare doPropagate]);
 	meta = {
 		description = "
 		Qi - next generation on top of Common Lisp.
diff --git a/pkgs/development/interpreters/erlang/builder.sh b/pkgs/development/interpreters/erlang/builder.sh
new file mode 100644
index 0000000000000..43c964d88b80c
--- /dev/null
+++ b/pkgs/development/interpreters/erlang/builder.sh
@@ -0,0 +1,14 @@
+buildInputs="$perl $gnum4 $ncurses $openssl"
+
+source $stdenv/setup
+
+tar xfvz $src
+cd otp_src_*
+
+# Fix some hard coded paths to /bin/rm
+sed -i -e "s|/bin/rm|rm|" lib/odbc/configure
+sed -i -e "s|/bin/rm|rm|" erts/configure
+
+./configure --prefix=$out --with-ssl=$openssl
+make
+make install
diff --git a/pkgs/development/interpreters/erlang/default.nix b/pkgs/development/interpreters/erlang/default.nix
new file mode 100644
index 0000000000000..f8caed7f329b8
--- /dev/null
+++ b/pkgs/development/interpreters/erlang/default.nix
@@ -0,0 +1,11 @@
+{stdenv, fetchurl, perl, ncurses, gnum4, openssl}:
+
+stdenv.mkDerivation {
+  name = "erlang-R11B-5";
+  builder = ./builder.sh;
+  src = fetchurl {
+    url = http://www.erlang.org/download/otp_src_R11B-5.tar.gz;
+    md5 = "96acec41da87d6ee0ef18e1aab36ffdd";
+  };
+  inherit perl ncurses gnum4 openssl;
+}
diff --git a/pkgs/development/interpreters/pyrex/0.9.6.nix b/pkgs/development/interpreters/pyrex/0.9.6.nix
index 7053f949a4306..1b11e8efe36e9 100644
--- a/pkgs/development/interpreters/pyrex/0.9.6.nix
+++ b/pkgs/development/interpreters/pyrex/0.9.6.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/oldtar/Pyrex-0.9.6.tar.gz;
@@ -8,10 +8,11 @@ args : with args;
 		buildInputs = [python];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "Pyrex-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [installPythonPackage doForceShare]);
+		(textClosure localDefs [installPythonPackage doForceShare]);
 	meta = {
 		description = "
 	Python package compiler or something like that.	
diff --git a/pkgs/development/libraries/fftw/default.nix b/pkgs/development/libraries/fftw/default.nix
index 3f71254430349..3f5d13b09fb94 100644
--- a/pkgs/development/libraries/fftw/default.nix
+++ b/pkgs/development/libraries/fftw/default.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs { 
 		src = 
 			fetchurl {
 				url = ftp://ftp.fftw.org/pub/fftw/fftw-3.1.2.tar.gz;
@@ -8,10 +8,11 @@ args : with args;
 		buildInputs = [];
 		configureFlags = ["--enable-float --enable-shared"];
 	} null;
+	in with localDefs;
 stdenv.mkDerivation {
 	name = "fftw-3.1.2";
 	builder = writeScript "fftw-3.1.2-builder"
-		(textClosure [doConfigure doMakeInstall doForceShare]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare]);
 	meta = {
 		description = "
 	Fastest Fourier Transform in the West library.
diff --git a/pkgs/development/libraries/glew/default.nix b/pkgs/development/libraries/glew/default.nix
new file mode 100644
index 0000000000000..2af500b3db6c8
--- /dev/null
+++ b/pkgs/development/libraries/glew/default.nix
@@ -0,0 +1,19 @@
+args:
+args.stdenv.mkDerivation {
+  name = "glew-1.5.0";
+
+  src = args.fetchurl {
+    url = http://dfn.dl.sourceforge.net/sourceforge/glew/glew-1.5.0-src.tgz;
+    sha256 = "1kjr1fchnl785wsg11vzc03q3pm12lh20n1i593zr1xqfjgx2b4h";
+  };
+
+  buildInputs =(with args; [mesa x11 libXmu libXi]);
+
+  meta = { 
+      description = "cross-platform open-source C/C++ extension loading library";
+      homepage = http://glew.sourceforge.net/;
+      license = ["BSD" "GLX" "SGI-B" "GPL2"]; # License description copied from gentoo-1.4.0 
+  };
+
+  installPhase="GLEW_DEST=\$out make install";
+}
diff --git a/pkgs/development/libraries/haskell/Crypto/default.nix b/pkgs/development/libraries/haskell/Crypto/default.nix
new file mode 100644
index 0000000000000..9cb465e50b38b
--- /dev/null
+++ b/pkgs/development/libraries/haskell/Crypto/default.nix
@@ -0,0 +1,11 @@
+{cabal}:
+
+cabal.mkDerivation (self : {
+  pname = "Crypto";
+  version = "4.1.0";
+  sha256 = "0984c833c5dfa6f4d56fd6fb284db7b7cef6676dc7999a1436aa856becba2b8f";
+  meta = {
+    description = "Several encryption algorithms for Haskell";
+  };
+})  
+
diff --git a/pkgs/development/libraries/haskell/X11/default.nix b/pkgs/development/libraries/haskell/X11/default.nix
new file mode 100644
index 0000000000000..39fb562846785
--- /dev/null
+++ b/pkgs/development/libraries/haskell/X11/default.nix
@@ -0,0 +1,13 @@
+{cabal, libX11, xineramaSupport ? true, libXinerama ? null, libXext ? null}:
+
+assert xineramaSupport -> (libXinerama != null && libXext != null);
+
+cabal.mkDerivation (self : {
+  pname = "X11";
+  version = "1.4.1";
+  sha256 = "e51038541415686f0e278ccdbc0b2373cd11f212de99023b7b8f8e776aa09f79";
+  propagatedBuildInputs = [libX11] ++ (if xineramaSupport then [libXinerama libXext] else []);
+  meta = {
+    description = "A Haskell binding to the X11 graphics library";
+  };
+})
diff --git a/pkgs/development/libraries/haskell/binary/default.nix b/pkgs/development/libraries/haskell/binary/default.nix
new file mode 100644
index 0000000000000..081779fd31245
--- /dev/null
+++ b/pkgs/development/libraries/haskell/binary/default.nix
@@ -0,0 +1,11 @@
+{cabal}:
+
+cabal.mkDerivation (self : {
+  pname = "binary";
+  version = "0.4.1";
+  sha256 = "bb74824306843da25f6d97c271e2a06ee3a7e05fc529156fb81d7c576688e549";
+  meta = {
+    description = "Efficient, pure binary serialisation using lazy ByteStrings";
+  };
+})  
+
diff --git a/pkgs/development/libraries/haskell/cabal/cabal.nix b/pkgs/development/libraries/haskell/cabal/cabal.nix
new file mode 100644
index 0000000000000..1e08a819c0ec0
--- /dev/null
+++ b/pkgs/development/libraries/haskell/cabal/cabal.nix
@@ -0,0 +1,95 @@
+# generic builder for Cabal packages
+
+attrs :
+{
+  mkDerivation =
+    transform :
+    let dtransform =
+          self : {
+
+            # pname should be defined by the client to be the package basename
+            # version should be defined by the client to be the package version
+ 
+            # fname is the internal full name of the package
+            fname = "${self.pname}-${self.version}";
+
+	    # name is the external full name of the package; usually we prefix
+	    # all packages with haskell- to avoid name clashes for libraries;
+	    # if that is not desired (for applications), name can be set to
+	    # fname.
+            name = "haskell-${self.fname}"; 
+
+            # the default download location for Cabal packages is Hackage,
+            # you still have to specify the checksum
+            src = attrs.fetchurl {
+              url = "http://hackage.haskell.org/packages/archive/${self.pname}/${self.version}/${self.fname}.tar.gz";
+              inherit (self) sha256;
+            };
+
+            # default buildInputs are just ghc, if more buildInputs are required
+            # buildInputs can be extended by the client by using extraBuildInputs,
+            # but often propagatedBuildInputs is preferable anyway
+            buildInputs = [attrs.ghc] ++ self.extraBuildInputs;
+            extraBuildInputs = [];
+
+            # we make sure that propagatedBuildInputs is defined, so that we don't
+            # have to check for its existence
+            propagatedBuildInputs = [];
+
+            # library directories that have to be added to the Cabal files
+            extraLibDirs = map (x : x + "/lib") self.propagatedBuildInputs;
+
+            # file(s) that have to be patched with information about extra libraries;
+            # can be redefined to the empty list by the client if this is not desired
+            patchLibFiles = [ "${self.pname}.cabal" ];
+
+            # patches files, compiles Setup, and configures
+            configurePhase = ''
+              eval "$preConfigure"
+
+              for i in ${toString self.patchLibFiles}; do
+                echo "patching $i"
+                test -f $i && sed -i '/extra-libraries/ { s|\( *\)extra-libraries.*|&\n\1extra-lib-dirs: ${toString self.extraLibDirs}| }' $i
+              done
+              for i in Setup.hs Setup.lhs; do
+                test -f $i && ghc --make $i
+              done
+              ./Setup configure --verbose --prefix="$out"
+
+              eval "$postConfigure"
+            '';
+
+            # builds via Cabal
+            buildPhase = ''
+              eval "$preBuild"
+
+              ./Setup build
+
+              eval "$postBuild"
+            '';
+
+	    # installs via Cabal; creates a registration file for nix-support
+	    # so that the package can be used in other Haskell-builds; also
+	    # creates a register-${name}.sh in userspace that can be used to
+	    # register the library in a user environment (but this scheme
+	    # should sooner or later be deprecated in favour of using a
+	    # ghc-wrapper).
+            installPhase = ''
+              eval "$preInstall"
+
+              ./Setup copy
+              ./Setup register --gen-script
+              mkdir -p $out/nix-support
+              if test -f register.sh; then
+                sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
+                cp register.sh $out/nix-support/register-ghclib.sh
+                sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
+                mkdir -p $out/bin
+                cp register.sh $out/bin/register-${self.name}.sh
+              fi
+
+              eval "$postInstall"
+            '';
+          };
+    in  attrs.stdenv.mkDerivation ((rec { f = dtransform f // transform f; }).f);
+} 
diff --git a/pkgs/development/libraries/haskell/pcre-light/default.nix b/pkgs/development/libraries/haskell/pcre-light/default.nix
new file mode 100644
index 0000000000000..1542bb7968ac0
--- /dev/null
+++ b/pkgs/development/libraries/haskell/pcre-light/default.nix
@@ -0,0 +1,12 @@
+{cabal, pcre}:
+
+cabal.mkDerivation (self : {
+  pname = "pcre-light";
+  version = "0.3";
+  sha256 = "a8cfec1c265530388efbb187426368e280331d9829fa93d8f49f16db3c3e7794";
+  propagatedBuildInputs = [pcre];
+  meta = {
+    description = "A small, efficient and portable regex library for Perl 5 compatible regular expressions";
+  };
+})  
+
diff --git a/pkgs/development/libraries/haskell/uulib-ghc-6.6/builder.sh b/pkgs/development/libraries/haskell/uulib-ghc-6.6/builder.sh
deleted file mode 100644
index bbe21eac49e69..0000000000000
--- a/pkgs/development/libraries/haskell/uulib-ghc-6.6/builder.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-source $stdenv/setup
-
-
-tar xzf "$src" &&
-cd uulib-* &&
-
-
-autoconf &&
-./configure --prefix=$out &&
-
-
-ghc --make Setup.hs -o setup -package Cabal &&
-./setup configure --prefix=$out --with-hc-pkg=ghc-pkg &&
-
-
-./setup build &&
-./setup install &&
-./setup register --gen-script &&
-
-mkdir -p $out/nix-support/ &&
-cp register.sh $out/nix-support/register-ghclib.sh
diff --git a/pkgs/development/libraries/haskell/uulib-ghc-6.6/default.nix b/pkgs/development/libraries/haskell/uulib-ghc-6.6/default.nix
deleted file mode 100644
index 1c315b1cffac9..0000000000000
--- a/pkgs/development/libraries/haskell/uulib-ghc-6.6/default.nix
+++ /dev/null
@@ -1,11 +0,0 @@
-{stdenv, fetchurl, autoconf, ghc}:
-
-stdenv.mkDerivation
-{
-  name = "uulib-0.9.2-ghc-6.6";
-  src = fetchurl { url = http://www.cs.uu.nl/~ariem/uulib-2006-10-30-src.tar.gz;
-                   md5 = "d26059447d45fa91f54eca38680be7b7";
-                 };
-  builder = ./builder.sh;
-  buildInputs = [ autoconf ghc ];
-}
diff --git a/pkgs/development/libraries/haskell/uulib/builder.sh b/pkgs/development/libraries/haskell/uulib/builder.sh
deleted file mode 100644
index bdb0e81430e1a..0000000000000
--- a/pkgs/development/libraries/haskell/uulib/builder.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-source $stdenv/setup
-
-
-export HOME=$(pwd)/fake-home
-
-
-#add ghc to search path
-test -n "$ghc" && PATH=$PATH:$ghc/bin
-
-#unpack
-tar xzf "$src" &&
-cd uulib-* &&
-
-#configure
-ghc --make Setup.hs -o setup -package Cabal &&
-./setup configure --prefix=$out &&
-
-#make
-./setup build &&
-
-#install
-./setup copy &&
-
-# Create package database. If we can find the ghc version we might install the
-# package, like ghc does, in $out/lib/ghc-version/package.conf.
-
-support=$out/nix-support &&
-packages_db=$out/nix-support/package.conf &&
-
-mkdir $support &&
-cp $ghc/lib/ghc-*/package.conf $packages_db &&
-chmod +w $packages_db &&
-#echo '[]' > $packages_db &&
-
-# We save a modified version of a register script. This gives a dependency on
-# ghc, but this should not be a problem as long as $out is a static library.
-
-./setup register --gen-script &&
-sed '/ghc-pkg/ s|update -|-f "$1" update -|' register.sh > register-pkg.sh &&
-sed '/ghc-pkg/ s|--auto-ghci-libs||' register-pkg.sh > $support/register.sh &&
-
-# The package and its direct cabal dependencies are registered. This may result
-# in duplicate registrations attempts but hopefully that will not result in
-# errors.
-
-# uulib has no dependencies on other ghc libraries
-for dep in ; do
-	sh $dep/nix-support/register.sh $packages_db || exit 1
-done &&
-sh register-pkg.sh $packages_db &&
-rm -f $package_db.old
diff --git a/pkgs/development/libraries/haskell/uulib/default.nix b/pkgs/development/libraries/haskell/uulib/default.nix
index c8bcf25dcc4bc..0e5e517d7c542 100644
--- a/pkgs/development/libraries/haskell/uulib/default.nix
+++ b/pkgs/development/libraries/haskell/uulib/default.nix
@@ -1,12 +1,10 @@
-{stdenv, fetchurl, ghc}:
+{cabal}:
 
-stdenv.mkDerivation {
-  name = "uulib-0.9.2";
-  src = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/uulib-0.9.2-src.tar.gz;
-    md5 = "0cc9acc6a268e2bc5c8a954e67406e2d";
+cabal.mkDerivation (self : {
+  pname = "uulib";
+  version = "0.9.5";
+  sha256 = "38415725133af464de582dadc7d7e60b1aeb96344b18b239d176bf2181f98563";
+  meta = {
+    description = "Fast Parser Combinators and Pretty Printing Combinators";
   };
-  builder = ./builder.sh;
-  #buildInputs = [ ghc ];
-  inherit ghc;
-}
+})
diff --git a/pkgs/development/libraries/haskell/vty/default.nix b/pkgs/development/libraries/haskell/vty/default.nix
new file mode 100644
index 0000000000000..930e19ae89c5f
--- /dev/null
+++ b/pkgs/development/libraries/haskell/vty/default.nix
@@ -0,0 +1,13 @@
+{cabal}:
+
+cabal.mkDerivation (self : {
+  pname = "vty";
+  version = "3.0.0";
+  sha256 = "44ae53d06b8b45c14cd3861e860a38730ed9995ed56b1b3d9aba6641771f1947";
+  meta = {
+    description = "vty is a *very* simplistic library in the niche of ncurses";
+  };
+  preConfigure = ''
+    sed -i 's|^Build-Depends:.*$|&, bytestring, containers|' ${self.pname}.cabal
+  '';
+})
diff --git a/pkgs/development/libraries/haskell/zlib/default.nix b/pkgs/development/libraries/haskell/zlib/default.nix
new file mode 100644
index 0000000000000..268a43b5ea3f7
--- /dev/null
+++ b/pkgs/development/libraries/haskell/zlib/default.nix
@@ -0,0 +1,11 @@
+{cabal, zlib}:
+
+cabal.mkDerivation (self : {
+  pname = "zlib";
+  version = "0.4.0.2";
+  sha256 = "e6e9e51ca5b7f1685eb031f826f7865acc10cc2c8d0dfad975e0e81fd17f17ed";
+  propagatedBuildInputs = [zlib];
+  meta = {
+    description = "Compression and decompression in the gzip and zlib formats";
+  };
+})
diff --git a/pkgs/development/libraries/libdbi-drivers/0.8.2-1.nix b/pkgs/development/libraries/libdbi-drivers/0.8.2-1.nix
index be0db328ef943..8c3975c8da21b 100644
--- a/pkgs/development/libraries/libdbi-drivers/0.8.2-1.nix
+++ b/pkgs/development/libraries/libdbi-drivers/0.8.2-1.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 			fetchurl {
 				url = mirror://sourceforge/libdbi-drivers/libdbi-drivers-0.8.2-1.tar.gz;
@@ -27,10 +27,11 @@ args : with args;
 		] else [])
 		;
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "libdbi"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	DB independent interface to DB; DB drivers (mysql only for now).
diff --git a/pkgs/development/libraries/libdbi/0.8.2.nix b/pkgs/development/libraries/libdbi/0.8.2.nix
index e7dc24417f218..e80c0196650ae 100644
--- a/pkgs/development/libraries/libdbi/0.8.2.nix
+++ b/pkgs/development/libraries/libdbi/0.8.2.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 			fetchurl {
 				url = mirror://sourceforge/libdbi/libdbi-0.8.2.tar.gz;
@@ -9,10 +9,11 @@ args : with args;
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "libdbi"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	DB independent interface to DB.	
diff --git a/pkgs/development/libraries/libextractor/0.5.18.nix b/pkgs/development/libraries/libextractor/0.5.18.nix
index 3f8304d7304ae..6fc5e8524486d 100644
--- a/pkgs/development/libraries/libextractor/0.5.18.nix
+++ b/pkgs/development/libraries/libextractor/0.5.18.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://gnunet.org/libextractor/download/libextractor-0.5.18.tar.gz;
@@ -9,10 +9,11 @@ args : with args;
 		buildInputs = [ zlib];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "libextractor"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Libextractor - extracts metadata from files.
diff --git a/pkgs/development/python-modules/ZopeInterface/default.nix b/pkgs/development/python-modules/ZopeInterface/default.nix
index 0fe40954115b6..6bcedcd0f171a 100644
--- a/pkgs/development/python-modules/ZopeInterface/default.nix
+++ b/pkgs/development/python-modules/ZopeInterface/default.nix
@@ -1,10 +1,10 @@
 {stdenv, fetchurl, python}:
 
 stdenv.mkDerivation {
-  name = "ZopeInterface-3.1.0c1";
+  name = "ZopeInterface-3.3.0";
   src = fetchurl {
-    url = http://www.zope.org/Products/ZopeInterface/3.1.0c1/ZopeInterface-3.1.0c1.tgz;
-    md5 = "f34cb95f2fbdbe3f1850c95cefddbd2c";
+    url = http://www.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz;
+    sha256 = "0xahg9cmagn4j3dbifvgzbjliw2jdrbf27fhqwkdp8j80xpyyjf0";
   };
   buildInputs = [python];
   buildPhase = "true";
diff --git a/pkgs/development/python-modules/twisted/default.nix b/pkgs/development/python-modules/twisted/default.nix
index 37a42faf8568f..7fdf610d74caf 100644
--- a/pkgs/development/python-modules/twisted/default.nix
+++ b/pkgs/development/python-modules/twisted/default.nix
@@ -1,10 +1,10 @@
 {stdenv, fetchurl, python, ZopeInterface}:
 
 stdenv.mkDerivation {
-  name = "twisted-2.4.0";
+  name = "twisted-2.5.0";
   src = fetchurl {
-    url = http://tmrc.mit.edu/mirror/twisted/Twisted/2.4/Twisted-2.4.0.tar.bz2;
-    md5 = "42eb0c8fd0f8707a39fff1dd6adab27d";
+    url = http://tmrc.mit.edu/mirror/twisted/Twisted/2.5/Twisted-2.5.0.tar.bz2;
+    sha256 = "1kfj4354lm4kphm317giyldykyd17lba2xd7y512lxc38hzxzcpk";
   };
   buildInputs = [python];
   propagatedBuildInputs = [ZopeInterface];
diff --git a/pkgs/development/tools/documentation/haddock/default.nix b/pkgs/development/tools/documentation/haddock/default.nix
new file mode 100644
index 0000000000000..86d07b240a546
--- /dev/null
+++ b/pkgs/development/tools/documentation/haddock/default.nix
@@ -0,0 +1,11 @@
+{cabal}:
+
+cabal.mkDerivation (self : {
+  pname = "haddock";
+  version = "2.0.0.0";
+  name = self.fname;
+  sha256 = "a2ea5bdc127bc8b189a8d869f582ec774fea0933e7f5ca89549a6c142b9993df";
+  meta = {
+    description = "a tool for automatically generating documentation from annotated Haskell source code";
+  };
+})
diff --git a/pkgs/development/tools/haskell/uuagc/default.nix b/pkgs/development/tools/haskell/uuagc/default.nix
index 519244ae7b849..b45db5f2ea6cb 100644
--- a/pkgs/development/tools/haskell/uuagc/default.nix
+++ b/pkgs/development/tools/haskell/uuagc/default.nix
@@ -1,14 +1,12 @@
-{stdenv, fetchurl, ghc, uulib}:
-
-stdenv.mkDerivation
-{
-  name = "uuagc-0.9.2";
-
-  src = fetchurl { url = http://www.cs.uu.nl/~ariem/uuagc-0.9.2-src.tar.gz;
-                   md5 = "cbac92287c9c0a858ccbfa37615d9f5f";
-                 };
-
-  buildInputs = [ghc uulib];
-
-  meta = { description = "The UUAG Compiler"; };
-}
+{cabal, uulib}:
+
+cabal.mkDerivation (self : {
+  pname = "uuagc";
+  version = "0.9.5";
+  name = self.fname;
+  sha256 = "c5be435efa609f72c09e175dd5cf7835a060bd7eaf6634ec4cde72ea84b99f25";
+  extraBuildInputs = [uulib];
+  meta = {
+    description = "Attribute Grammar System of Universiteit Utrecht";
+  };
+})
diff --git a/pkgs/development/tools/misc/indent/2.2.9.nix b/pkgs/development/tools/misc/indent/2.2.9.nix
index d7e91abcf83bf..5e92802beed1d 100644
--- a/pkgs/development/tools/misc/indent/2.2.9.nix
+++ b/pkgs/development/tools/misc/indent/2.2.9.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = ftp://ftp.gnu.org/gnu/indent/indent-2.2.9.tar.gz;
@@ -9,6 +9,7 @@ args : with args;
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 	preBuild = FullDepEntry ("
 		sed -e '/extern FILE [*]output/i#ifndef OUTPUT_DEFINED_ELSEWHERE' -i src/indent.h
@@ -19,7 +20,7 @@ in
 stdenv.mkDerivation rec {
 	name = "indent";
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure preBuild doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure preBuild doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	GNU Indent - a source text formatter.
diff --git a/pkgs/development/tools/misc/intltool/0.36.2.nix b/pkgs/development/tools/misc/intltool/0.36.2.nix
index d8315a9ba62e4..884c76a800c79 100644
--- a/pkgs/development/tools/misc/intltool/0.36.2.nix
+++ b/pkgs/development/tools/misc/intltool/0.36.2.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = http://ftp.gnome.org/pub/gnome/sources/intltool/0.36/intltool-0.36.2.tar.bz2;
@@ -9,10 +9,11 @@ args : with args;
 		propagatedBuildInputs = [perl perlXMLParser];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "intltool-0.36.2";
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doPropagate doForceShare]);
+		(textClosure localDefs [doConfigure doMakeInstall doPropagate doForceShare]);
 	inherit propagatedBuildInputs;
 	meta = {
 		description = "
diff --git a/pkgs/development/tools/misc/ltrace/default.nix b/pkgs/development/tools/misc/ltrace/default.nix
index 23b44bf3b5b7f..cd77984ded6cf 100644
--- a/pkgs/development/tools/misc/ltrace/default.nix
+++ b/pkgs/development/tools/misc/ltrace/default.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 	fetchurl {
 		url = ftp://ftp.debian.org/debian/pool/main/l/ltrace/ltrace_0.5.orig.tar.gz;
@@ -12,6 +12,7 @@ args : with args;
 			cd ltrace-*;
 		";
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let
 	preConfigure = FullDepEntry ("
 		sed -e 's@-o root -g root@@' -i Makefile.in;
@@ -20,7 +21,7 @@ in
 stdenv.mkDerivation rec {
 	name = "ltrace-0.5";
 	builder = writeScript (name + "-builder")
-		(textClosure [preConfigure doConfigure doMakeInstall doForceShare]);
+		(textClosure localDefs [preConfigure doConfigure doMakeInstall doForceShare]);
 	meta = {
 		description = "
 	Library call tracer.
diff --git a/pkgs/development/tools/parsing/alex/default.nix b/pkgs/development/tools/parsing/alex/default.nix
index 00d414d56bde5..273a25753e82f 100644
--- a/pkgs/development/tools/parsing/alex/default.nix
+++ b/pkgs/development/tools/parsing/alex/default.nix
@@ -1,23 +1,12 @@
-{stdenv, fetchurl, ghc, perl}:
-
-stdenv.mkDerivation {
-  name = "alex-2.1.0";
-  src = fetchurl {
-    url = http://www.haskell.org/alex/dist/2.1.0/alex-2.1.0.tar.gz;
-    sha1 = "37599b7be5249d639b3a5a3fdc61907dc4dad660";
+{cabal, perl}:
+
+cabal.mkDerivation (self : {
+  pname = "alex";
+  version = "2.2";
+  name = self.fname;
+  sha256 = "e958d4fc6cfdb1d351dc39a45ea882f23b1b1773a736d43814a52d4939a41ffe";
+  extraBuildInputs = [perl];
+  meta = {
+    description = "A lexical analyser generator for Haskell";
   };
-  buildInputs = [ghc perl];
-
-  configurePhase = "
-    ghc --make Setup.lhs
-    ./Setup configure --prefix=\"\${out}\"
-  ";
-
-  buildPhase = "
-    ./Setup build
-  ";
-
-  installPhase = "
-    ./Setup install
-  ";
-}
+})
diff --git a/pkgs/development/tools/parsing/happy/happy-1.17.nix b/pkgs/development/tools/parsing/happy/happy-1.17.nix
new file mode 100644
index 0000000000000..b7fa22ccb800e
--- /dev/null
+++ b/pkgs/development/tools/parsing/happy/happy-1.17.nix
@@ -0,0 +1,12 @@
+{cabal, perl}:
+
+cabal.mkDerivation (self : {
+
+  # requires cabal-1.2 (and therefore, in Nix, currently ghc-6.8)
+
+  pname = "happy";
+  version = "1.17";
+  name = self.fname;
+  sha256 = "dca4e47d17e5d538335496236b3d2c3cbff644cf7380c987a4714e7784c70a2b";
+  extraBuildInputs = [perl];
+})
diff --git a/pkgs/games/construo/0.2.2.nix b/pkgs/games/construo/0.2.2.nix
index 964b0e3898e6f..555d2f4b30b95 100644
--- a/pkgs/games/construo/0.2.2.nix
+++ b/pkgs/games/construo/0.2.2.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://savannah.nongnu.org/download/construo/construo-0.2.2.tar.gz;
@@ -11,6 +11,7 @@ args : with args;
 		;
 		configureFlags = [""];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 preConfigure = FullDepEntry ("
   sed -e 's/math[.]h/cmath/' -i vector.cxx
@@ -20,7 +21,7 @@ in
 stdenv.mkDerivation rec {
 	name = "construo-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [preConfigure doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [preConfigure doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Construo masses and springs simulation.
diff --git a/pkgs/games/fsg/alt-builder.nix b/pkgs/games/fsg/alt-builder.nix
index 8efd788789b4e..4401bf8451aca 100644
--- a/pkgs/games/fsg/alt-builder.nix
+++ b/pkgs/games/fsg/alt-builder.nix
@@ -1,13 +1,13 @@
 args: with args; 
-	with (builderDefs 
-	{ 
+	let localDefs = builderDefs {
   		buildInputs =[(wxGTK null)];
 		  src = 
 			fetchurl {
 				url = http://www.piettes.com/fallingsandgame/fsg-src-4.4.tar.gz;
 				sha256 = "1756y01rkvd3f1pkj88jqh83fqcfl2fy0c48mcq53pjzln9ycv8c";
 			};
-	} null);
+	} null;
+	in with localDefs;
 let 
 	preBuild = FullDepEntry "
 		sed -e '
@@ -25,7 +25,7 @@ in
 stdenv.mkDerivation {
   name = "fsg-4.4";
 	builder = writeScript "fsg-4.4-builder"
-		(textClosure [doUnpack addInputs preBuild doMake installPhase doForceShare]);
+		(textClosure localDefs [doUnpack addInputs preBuild doMake installPhase doForceShare]);
 
   meta = {
     description = "
diff --git a/pkgs/games/orbit/1.01.nix b/pkgs/games/orbit/1.01.nix
new file mode 100644
index 0000000000000..ba824e83f1c52
--- /dev/null
+++ b/pkgs/games/orbit/1.01.nix
@@ -0,0 +1,43 @@
+args : with args; with builderDefs {src="";} null;
+	let localDefs = builderDefs rec {
+		src = /* put a fetchurl here */
+		fetchurl {
+			sha256 = "1kx69f9jqnfzwjh47cl1df8p8hn3bnp6bznxnb6c4wx32ijn5gri";
+			url = http://ftp.de.debian.org/debian/pool/main/s/space-orbit/space-orbit_1.01.orig.tar.gz;
+		};
+
+		buildInputs = [mesa libXi libXt libXext libX11 libXmu freeglut esound];
+		configureFlags = [];
+		debianPatch = 
+		fetchurl {
+			url = http://ftp.de.debian.org/debian/pool/main/s/space-orbit/space-orbit_1.01-9.diff.gz;
+			sha256 = "1v3s97day6fhv08l2rn81waiprhi1lfyjjsj55axfh6n6zqfn1w2";
+		};
+		customBuild = FullDepEntry (''
+			gunzip < ${debianPatch} | patch -Np1
+                        cd src
+			sed -e 's@/usr/share/games/orbit/@'$out'/dump/@g' -i *.c
+                        sed -e '/DIR=/d' -i Makefile 
+                        make 
+                        ensureDir $out/bin
+                        cp -r .. $out/dump
+                        cat >$out/bin/space-orbit <<EOF
+#! /bin/sh
+$out/dump/orbit "\$@"
+EOF
+                        chmod a+x $out/bin/space-orbit
+		'') ["minInit" "doUnpack" "defEnsureDir" "addInputs"];
+	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
+stdenv.mkDerivation rec {
+	name = "space-orbit-"+version;
+	builder = writeScript (name + "-builder")
+		(textClosure localDefs 
+			[ customBuild doForceShare doPropagate]);
+	meta = {
+		description = "
+		Orbit space flight simulator.
+";
+	};
+}
+
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
index 108d62b3d8a37..87d08ab7c1c02 100644
--- a/pkgs/lib/default.nix
+++ b/pkgs/lib/default.nix
@@ -3,7 +3,8 @@
 let
 
   inherit (builtins)
-    head tail isList stringLength substring lessThan sub;
+    head tail isList stringLength substring lessThan sub
+    listToAttrs attrNames hasAttr;
 
 in
 
@@ -15,11 +16,15 @@ rec {
   id = x: x;
 
 
-  # !!! need documentation...
+  # accumulates / merges all attr sets until null is fed.
+  # example: sumArgs id { a = 'a'; x = 'x'; } { y = 'y'; x = 'X'; } null
+  # result : { a = 'a'; x = 'X'; y = 'Y'; }
   innerSumArgs = f : x : y : (if y == null then (f x)
 	else (innerSumArgs f (x // y)));
   sumArgs = f : innerSumArgs f {};
 
+  # example a = pairMap (x : y : x + y) ["a" "b" "c" "d"];
+  # result: ["ab" "cd"]
   innerPairMap = acc: f: l: 
   	if l == [] then acc else
 	innerPairMap (acc ++ [(f (head l)(head (tail l)))])
@@ -55,6 +60,7 @@ rec {
     else [(head list) separator]
          ++ (intersperse separator (tail list));
 
+  toList = x : if (__isList x) then x else [x];
 
   concatStringsSep = separator: list:
     concatStrings (intersperse separator list);
@@ -72,6 +78,7 @@ rec {
   # Return an attribute from nested attribute sets.  For instance ["x"
   # "y"] applied to some set e returns e.x.y, if it exists.  The
   # default value is returned otherwise.
+  # comment: there is also builtins.getAttr ? (is there a better name for this function?)
   getAttr = attrPath: default: e:
     let attr = head attrPath;
     in
@@ -116,6 +123,12 @@ rec {
     else if pred (head list) then all pred (tail list)
     else false;
 
+  # much shorter implementations using map and fold (are lazy as well)
+  # which ones are better?
+  # true if all/ at least one element(s) satisfy f
+  # all = f : l : fold logicalAND true (map f l);
+  # any = f : l : fold logicalOR false (map f l);
+
 
   # Return true if each element of a list is equal, false otherwise.
   eqLists = xs: ys:
@@ -246,8 +259,6 @@ rec {
 			checker
 	else condConcat
 		name (tail (tail list)) checker;
-
-
   /* Options. */
   
   mkOption = attrs: attrs // {_type = "option";};
@@ -305,4 +316,275 @@ rec {
 
   closePropagation = list: (uniqList {inputList = (innerClosePropagation [] list);});
 
+  # calls a function (f attr value ) for each record item. returns a list
+  mapRecordFlatten = f : r : map (attr: f attr (builtins.getAttr attr r) ) (attrNames r);
+
+  # to be used with listToAttrs (_a_ttribute _v_alue)
+  # TODO should be renamed to nv because niksnut has renamed the attribute attr to name
+  nv = name : value : { inherit name value; };
+  # attribute set containing one attribute
+  nvs = name : value : listToAttrs [ (nv name value) ];
+  # adds / replaces an attribute of an attribute set
+  setAttr = set : name : v : set // (nvs name v);
+
+  # iterates over a list of attributes collecting the attribute attr if it exists
+  catAttrs = attr : l : fold ( s : l : if (hasAttr attr s) then [(builtins.getAttr attr s)] ++ l else l) [] l;
+
+  mergeAttrs = fold ( x : y : x // y) {};
+
+  # Using f = a : b = b the result is similar to //
+  # merge attributes with custom function handling the case that the attribute
+  # exists in both sets
+  mergeAttrsWithFunc = f : set1 : set2 :
+    fold (n: set : if (__hasAttr n set) 
+                        then setAttr set n (f (__getAttr n set) (__getAttr n set2))
+                        else set )
+           set1 (__attrNames set2);
+
+  # merging two attribute set concatenating the values of same attribute names
+  # eg { a = 7; } {  a = [ 2 3 ]; } becomes { a = [ 7 2 3 ]; }
+  mergeAttrsConcatenateValues = mergeAttrsWithFunc ( a : b : (toList a) ++ (toList b) );
+
+  # returns atribute values as a list 
+  flattenAttrs = set : map ( attr : builtins.getAttr attr set) (attrNames set);
+  mapIf = cond : f :  fold ( x : l : if (cond x) then [(f x)] ++ l else l) [];
+
+# Marc 2nd proposal: (not everything has been tested in detail yet..)
+
+  # usage / example
+  # flagConfig = {
+  # } // (enableDisableFeature "flagName" "configure_feature" extraAttrs;)
+  #
+  # is equal to
+  # flagConfig = {
+  #   flagName = { cfgOption = "--enable-configure_feature"; } // extraAttrs;
+  #   no_flagName = { cfgOption = "--disable-configure_feature"; };
+  enableDisableFeature = flagName : configure_feature : extraAttrs :
+    listToAttrs [ ( nv flagName ({ cfgOption = "--enable-${configure_feature}"; } // extraAttrs ) )
+                  ( nv "no_${flagName}" ({ cfgOption = "--disable-${configure_feature}"; } ) )];
+
+  # calls chooseOptionsByFlags2 with some preprocessing
+  # chooseOptionsByFlags2 returns an attribute set meant to be used to create new derivaitons.
+  # see mkDerivationByConfiguration in all-packages.nix and the examples given below.
+  # You can just copy paste them into all-packages.nix to test them..
+
+  chooseOptionsByFlags = { flagConfig, args, optionals ? [], defaults ? [],
+                           collectExtraPhaseActions ? [] } :
+    let passedOptionals = filter ( x : hasAttr x args ) optionals; # these are in optionals and in args
+        # we simply merge in <optional_name> = { buildInputs = <arg.<optional_name>; pass = <arg.optional_name>; }
+        flagConfigWithOptionals = flagConfig // ( listToAttrs
+          (map ( o : nv o ( { buildInputs = o; pass = nvs o (builtins.getAttr o args); }
+                            // getAttr [o] {} flagConfig )
+               )
+               passedOptionals ) );
+
+    in chooseOptionsByFlags2 flagConfigWithOptionals collectExtraPhaseActions args 
+       ( (getAttr ["flags"] defaults args) ++ passedOptionals);
+
+  chooseOptionsByFlags2 = flagConfig : collectExtraPhaseActions : args : flags :
+    let   
+        # helper function
+        collectFlags = # state : flags :
+              fold ( flag : s : (
+                     if (hasAttr flag s.result) then s # this state has already been visited
+                     else if (! hasAttr flag flagConfig) then throw "unkown flag `${flag}' specified"
+                           else let fDesc = (builtins.getAttr flag flagConfig);
+                                    implied = flatten ( getAttr ["implies"] [] fDesc );
+                                    blocked = flatten ( getAttr ["blocks"] [] fDesc ); 
+                                    # add this flag
+                                    s2 =  s // { result = ( setAttr s.result flag (builtins.getAttr flag flagConfig) );
+                                                 blockedFlagsBy = s.blockedFlagsBy 
+                                                   // listToAttrs (map (b: nv b flag ) blocked); };
+                                    # add implied flags
+                                in collectFlags s2 implied
+                   ));
+
+        # chosen contains flagConfig but only having those attributes elected by flags 
+        # (or by implies attributes of elected attributes)
+        options = let stateOpts = collectFlags { blockedFlagsBy = {}; result = {}; } 
+                                               (flags ++ ( if (hasAttr "mandatory" flagConfig) then ["mandatory"] else [] ));
+                      # these options have not been chosen (neither by flags nor by implies)
+                      unsetOptions = filter ( x : (! hasAttr x stateOpts.result) && (hasAttr ("no_"+x) flagConfig)) 
+                                            ( attrNames flagConfig );
+                      # no add the corresponding no_ attributes as well ..
+                      state = collectFlags stateOpts (map ( x : "no_" + x ) unsetOptions);
+                  in # check for blockings:
+                     assert ( all id ( map ( b: if (hasAttr b state.result) 
+                                             then throw "flag ${b} is blocked by flag ${__getAttr b state.blockedFlagsBy}"
+                                             else true ) 
+                                           (attrNames state.blockedFlagsBy) ) ); 
+                    state.result;
+        flatOptions = flattenAttrs options;
+
+        # helper functions :
+        collectAttrs = attr : catAttrs attr flatOptions;
+        optsConcatStrs = delimiter : attrs : concatStrings 
+                ( intersperse delimiter (flatten ( collectAttrs attrs ) ) );
+
+        ifStringGetArg = x : if (__isAttrs x) then x # ( TODO implement __isString ?)
+                             else nvs x (__getAttr x args);
+          
+    in assert ( all id ( mapRecordFlatten ( attr : r : if ( all id ( flatten (getAttr ["assertion"] [] r ) ) ) 
+                                              then true else throw "assertion failed flag ${attr}" )
+                                         options) );
+      ( rec {
+
+          #foldOptions = attr: f : start: fold f start (catAttrs attr flatOptions);
+
+          # compared to flags flagsSet does also contain the implied flags.. This makes it easy to write assertions. ( assert args.
+          inherit options flatOptions collectAttrs optsConcatStrs;
+
+          buildInputs = map ( attr: if (! hasAttr attr args) then throw "argument ${attr} is missing!" else (builtins.getAttr attr args) )
+                        (flatten  (catAttrs "buildInputs" flatOptions));
+          propagatedBuildInputs = map ( attr: if (! hasAttr attr args) then throw "argument ${attr} is missing!" else (builtins.getAttr attr args) )
+                        (flatten  (catAttrs "propagatedBuildInputs" flatOptions));
+
+          configureFlags = optsConcatStrs " " "cfgOption";
+
+          #flags = listToAttrs (map ( flag: nv flag (hasAttr flag options) ) (attrNames flagConfig) );
+          flags_prefixed = listToAttrs (map ( flag: nv ("flag_set_"+flag) (hasAttr flag options) ) (attrNames flagConfig) );
+
+          pass = mergeAttrs ( map ifStringGetArg ( flatten (collectAttrs "pass") ) );
+      } #  now add additional phase actions (see examples)
+      // listToAttrs ( map ( x : nv x (optsConcatStrs "\n" x) ) collectExtraPhaseActions ) );
 }
+
+/* 
+  TODO: Perhaps it's better to move this documentation / these tests into some extra packages ..
+
+  # ###########################################################################
+  #  configuration tutorial .. examples and tests.. 
+  #  Copy this into all-packages.nix and  try
+
+  # The following derviations will all fail.. 
+  # But they will print the passed options so that you can get to know
+  # how these configurations ought to work.
+  # TODO: There is no nice way to pass an otpion yet.
+  #       I could imagine something like
+  #       flags = [ "flagA" "flagB" { flagC = 4; } ];
+
+  # They are named:
+  # simpleYes, simpleNo, 
+  # defaultsimpleYes, defaultsimpleNo
+  # optionalssimpleYes, optionalssimpleNo
+  # bitingsimpleYes can only be ran with -iA  blockingBiteMonster
+  # assertionsimpleNo
+  # of course you can use -iA and the attribute name as well to select these examples
+
+  # dummy build input
+  whoGetsTheFlagFirst = gnused;
+  whoGetsTheFlagLast = gnumake;
+
+  # simple example demonstrating containing one flag.
+  # features:
+  # * configure options are passed automatically
+  # * buildInputs are collected (they are special, see the setup script)
+  # * they can be passed by additional name as well using pass = { inherit (args) python } 
+  #                                       ( or short (value not attrs) : pass = "python" )
+  # * an attribute named the same way as the flag is added indicating 
+  #   true/ false (flag has been set/ not set)
+  # * extra phase dependend commands can be added
+  #   Its easy to add your own stuff using co.collectAttrs or co.optsConcatStrs 
+  #   ( perhaps this name will change?)
+  simpleFlagYesNoF = namePrefix : extraFlagAttrs : mkDerivationByConfiguration ( {
+    flagConfig = {
+      flag    = { name = namePrefix + "simpleYes"; 
+                  cfgOption = [ "--Yes" "--you-dont-need-a-list" ]; 
+                  buildInputs = [ "whoGetsTheFlagFirst" ]; 
+                  pass = { inherit gnumake; };
+                  extraConfigureCmd = "echo Hello, it worked! ";
+                  blocks = "bitingMonster";
+                };
+      no_flag = { name = namePrefix + "simpleNo"; 
+                  cfgOption = "--no"; 
+                  implies = ["bitingMonster"];
+                };
+      bitingMonster = {
+                  extraConfigureCmd = "echo Ill bite you";
+                };
+      gnutar = { cfgOption="--with-gnutar";
+                  # buildInputs and pass will be added automatically if gnutar is added to optionals
+               };
+      # can be used to check configure options of dependencies
+      # eg testFlag = { assertion = [ arg.desktop.flag_set_wmii (! arg.desktop.flag_set_gnome) (! arg.desktops.flag_set_kde ]; }
+      assertionFlag = { assertion = false; }; # assert is nix language keyword
+                                        
+    }; 
+
+    collectExtraPhaseActions = [ "extraConfigureCmd" ];
+
+    extraAttrs = co : {
+      name = ( __head (co.collectAttrs "name") );
+
+      unpackPhase = "
+       echo my name is 
+       echo \$name
+       echo
+       echo flag given \\(should be 1 or empty string\\) ? 
+       echo \$flag_set_flag
+       echo
+       echo my build inputs are 
+       echo \$buildInputs
+       echo
+       echo my configuration flags are 
+       echo \$configureFlags
+       echo
+       echo what about gnumake? Did it pass?
+       echo \$gnumake
+       echo 
+       echo configurePhase command is
+       echo $\configurePhase
+       echo 
+       echo gnutar passed? \\(optional test\\)
+       echo \$gnutar
+       echo
+       echo dying now
+       echo die_Hopefully_Soon
+      ";
+    configurePhase = co.extraConfigureCmd;
+    };
+  } // extraFlagAttrs ); 
+
+
+  simpleYes = simpleFlagYesNoF "" {} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+    flags = ["flag"];
+  };
+  # note the "I'll bite you" because of the implies attribute
+  simpleNo = simpleFlagYesNoF "" {} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+    flags = [];
+  };
+
+  # specifying defaults by adding a default attribute
+  
+  yesAgainDefault = simpleFlagYesNoF "default" { defaults = [ "flag" ];} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+  };
+  noAgainOverridingDefault = simpleFlagYesNoF "default" { defaults = [ "flag" ];} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+    flags = [];
+  };
+
+  # requested by Michael Raskin: activate flag automatically if dependency is passed:
+  withGnutarOptional = simpleFlagYesNoF "optionals" { optionals = [ "gnutar" ];} {
+    flags = [ "flag" ]; # I only need to pass this to trigger name optionalssimpleYes
+    inherit whoGetsTheFlagFirst lib stdenv;
+    inherit gnutar;
+  };
+  withoutGnutarOptional = simpleFlagYesNoF "optionals" { optionals = [ "gnutar" ];} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+  };
+
+  # blocking example, this shouldn't even start building:
+  blockingBiteMonster = simpleFlagYesNoF "biting" {} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+    flags = [ "flag" "bitingMonster" ];
+  };
+
+  # assertion example this shouldn't even start building:
+  assertion = simpleFlagYesNoF "assertion" {} {
+    inherit whoGetsTheFlagFirst lib stdenv;
+    flags = [ "assertionFlag" ];
+  };
+*/
diff --git a/pkgs/lib/strings-with-deps.nix b/pkgs/lib/strings-with-deps.nix
index 78cded99ef712..4fb4fe150a7cf 100644
--- a/pkgs/lib/strings-with-deps.nix
+++ b/pkgs/lib/strings-with-deps.nix
@@ -1,9 +1,24 @@
+/*
+Usage:
+
+  You define you custom builder script by adding all build steps to a list.
+  for example:
+	builder = writeScript "fsg-4.4-builder"
+		(textClosure [doUnpack addInputs preBuild doMake installPhase doForceShare]);
+
+  a step is defined by noDepEntry, FullDepEntry or PackEntry.
+  To ensure that prerequisite are met those are added before the task itself by
+  textClosureDupList. Duplicated items are removed again.
+
+  See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps
+
+*/
 args: 
 	with args;
 	with lib;
 	let 
 		inherit (builtins)	
-			head tail isList;
+			head tail isList isAttrs;
 in
 rec {
 
@@ -37,12 +52,23 @@ rec {
 			(concatLists (map textClosureDupList arg.deps)) ++ [arg]
 	);
 
-	textClosureList = arg:
+	textClosureDupListOverridable = predefined: arg:
+	(
+		if isList arg then 
+			textClosureDupListOverridable predefined {text = ""; deps = arg;} 
+		else if isAttrs arg then
+			(concatLists (map (textClosureDupListOverridable predefined) arg.deps)) ++ [arg]
+		else
+			textClosureDupListOverridable predefined (getAttr [arg] [] predefined)
+	);
+
+	textClosureListOverridable = predefined: arg:
 		(map	(x : x.text) 
-			(uniqList {inputList = textClosureDupList arg;}));
-	textClosure = arg: concatStringsSep "\n" (textClosureList arg);
+			(uniqList {inputList = textClosureDupListOverridable predefined arg;}));
+	textClosureOverridable = predefined: arg: concatStringsSep "\n" (textClosureListOverridable predefined arg);
 	
-	textClosureMap = f: arg: concatStringsSep "\n" (map f (textClosureList arg));
+	textClosureMapOveridable = f: predefined: arg: 
+		concatStringsSep "\n" (map f (textClosureListOverridable predefined arg));
 
 	noDepEntry = text : {inherit text;deps = [];};
 	FullDepEntry = text : deps: {inherit text deps;};
diff --git a/pkgs/misc/tex/nix/find-includes.pl b/pkgs/misc/tex/nix/find-includes.pl
index 649b16dc35fbf..9e5fd112bac93 100644
--- a/pkgs/misc/tex/nix/find-includes.pl
+++ b/pkgs/misc/tex/nix/find-includes.pl
@@ -59,6 +59,7 @@ while (scalar @workset > 0) {
 	if (/\\input\{(.*)\}/) {
 	    my $fn2 = $1;
             die "absolute path! $fn2" if substr($fn2, 0, 1) eq "/";
+	    push @workset, "$path/$fn2.tex";
 	    push @workset, "$path/$fn2";
 	} elsif (/\\usepackage(\[.*\])?\{(.*)\}/) {
 	    my $fn2 = $2;
diff --git a/pkgs/misc/trac/builder.sh b/pkgs/misc/trac/builder.sh
index a3e97e178a017..76bf061233486 100644
--- a/pkgs/misc/trac/builder.sh
+++ b/pkgs/misc/trac/builder.sh
@@ -1,5 +1,4 @@
 source $stdenv/setup
-source $makeWrapper
 
 unpackPhase
 mkdir -p $out
@@ -7,7 +6,6 @@ cd $name
 $python/bin/python setup.py install --prefix=$out
 
 for i in $(cd $out/bin && ls); do
-	mv $out/bin/$i $out/bin/.orig-$i
-	makeWrapper $out/bin/.orig-$i $out/bin/$i \
-		--set PYTHONPATH "$python/site-packages:$out/lib/python2.4/site-packages:$pysqlite/lib/python2.4/site-packages:$subversion/lib/svn-python:$clearsilver/site-packages"
+    wrapProgram $out/bin/$i \
+        --prefix PYTHONPATH : "$(toPythonPath $python):$(toPythonPath $out):$(toPythonPath $pysqlite):$subversion/lib/svn-python:$clearsilver/site-packages"
 done
diff --git a/pkgs/misc/trac/default.nix b/pkgs/misc/trac/default.nix
index c456c51daff94..b93c36843d329 100644
--- a/pkgs/misc/trac/default.nix
+++ b/pkgs/misc/trac/default.nix
@@ -3,13 +3,12 @@
 assert stdenv.system == "i686-linux";
 
 stdenv.mkDerivation {
-	name = "trac-0.9.5";
-	src = fetchurl {
-		url = "http://ftp.edgewall.com/pub/trac/trac-0.9.5.tar.gz";
-		md5 = "3b7d708eaf905cc6ba2b6b10a09a8cf4";
-	};
-	builder = ./builder.sh;
-	inherit stdenv python subversion clearsilver sqlite pysqlite makeWrapper;
+  name = "trac-0.9.5";
+  src = fetchurl {
+    url = "http://ftp.edgewall.com/pub/trac/trac-0.9.5.tar.gz";
+    md5 = "3b7d708eaf905cc6ba2b6b10a09a8cf4";
+  };
+  builder = ./builder.sh;
+  buildInputs = [makeWrapper];
+  inherit stdenv python subversion clearsilver sqlite pysqlite;
 }
-
-
diff --git a/pkgs/os-specific/linux/atheros/0.9.3.3.nix b/pkgs/os-specific/linux/atheros/0.9.3.3.nix
index d5c207bf18818..419c136bed236 100644
--- a/pkgs/os-specific/linux/atheros/0.9.3.3.nix
+++ b/pkgs/os-specific/linux/atheros/0.9.3.3.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://downloads.sourceforge.net/madwifi/madwifi-0.9.3.3.tar.bz2;
@@ -16,6 +16,7 @@ args : with args;
 			sha256 = "11xpx5g9w7ilagvj60prc3s8a3x0n5n4mr0b7nh0lxwrbjdgjjfg";
 		} else "")*/;
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 doPatch = FullDepEntry (if patchAR2425x86 !="" then ''
 	cd hal
@@ -25,7 +26,7 @@ in
 stdenv.mkDerivation rec {
 	name = "atheros-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doPatch doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doPatch doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Atheros WiFi driver.
diff --git a/pkgs/os-specific/linux/atheros/r2756.nix b/pkgs/os-specific/linux/atheros/r2756.nix
index 8309b78586590..031404b0395f2 100644
--- a/pkgs/os-specific/linux/atheros/r2756.nix
+++ b/pkgs/os-specific/linux/atheros/r2756.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://snapshots.madwifi.org/madwifi-ng/madwifi-ng-r2756-20071018.tar.gz;
@@ -16,6 +16,7 @@ args : with args;
 			sha256 = "11xpx5g9w7ilagvj60prc3s8a3x0n5n4mr0b7nh0lxwrbjdgjjfg";
 		} else "");
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 doPatch = FullDepEntry (if patchAR2425x86 !="" then ''
 	cd hal
@@ -26,7 +27,7 @@ in
 stdenv.mkDerivation rec {
 	name = "atheros-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doPatch doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doPatch doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Atheros WiFi driver.
diff --git a/pkgs/os-specific/linux/atheros/r3122.nix b/pkgs/os-specific/linux/atheros/r3122.nix
index c82b4021544a2..e9fb7bab01a48 100644
--- a/pkgs/os-specific/linux/atheros/r3122.nix
+++ b/pkgs/os-specific/linux/atheros/r3122.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://snapshots.madwifi.org/madwifi-ng/madwifi-ng-r3122-20080109.tar.gz;
@@ -10,10 +10,11 @@ args : with args;
 		configureFlags = [];
 		makeFlags = [''KERNELPATH=${kernel}/lib/modules/*/build'' ''DESTDIR=$out''];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "atheros-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Atheros WiFi driver.
diff --git a/pkgs/os-specific/linux/dmidecode/2.9.nix b/pkgs/os-specific/linux/dmidecode/2.9.nix
index 787846465d849..968ab80a4aff4 100644
--- a/pkgs/os-specific/linux/dmidecode/2.9.nix
+++ b/pkgs/os-specific/linux/dmidecode/2.9.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://download.savannah.gnu.org/releases/dmidecode/dmidecode-2.9.tar.bz2;
@@ -10,10 +10,11 @@ args : with args;
 		configureFlags = [];
 		makeFlags = "prefix=\$out";
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "dmidecode-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [ doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [ doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Tool to decode Desktop Management Interface and SBIOS data.
diff --git a/pkgs/os-specific/linux/dvd+rw-tools/7.0.nix b/pkgs/os-specific/linux/dvd+rw-tools/7.0.nix
index c991389633ca6..658bdbf55fa28 100644
--- a/pkgs/os-specific/linux/dvd+rw-tools/7.0.nix
+++ b/pkgs/os-specific/linux/dvd+rw-tools/7.0.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://fy.chalmers.se/~appro/linux/DVD+RW/tools/dvd+rw-tools-7.0.tar.gz;
@@ -10,6 +10,7 @@ args : with args;
 		configureFlags = [];
 		makeFlags = [" prefix=\$out "];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 	preBuild = FullDepEntry ("
 		sed -e 's@/usr/local@'\$out'@g' -i Makefile.m4 Makefile
@@ -18,7 +19,7 @@ in
 stdenv.mkDerivation rec {
 	name = "dvd+rw-tools-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [preBuild doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [preBuild doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	DVD+RW tools.
diff --git a/pkgs/os-specific/linux/kqemu/1.3.0pre11.nix b/pkgs/os-specific/linux/kqemu/1.3.0pre11.nix
index 3aa2731ac3fb4..20e738e069288 100644
--- a/pkgs/os-specific/linux/kqemu/1.3.0pre11.nix
+++ b/pkgs/os-specific/linux/kqemu/1.3.0pre11.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://fabrice.bellard.free.fr/qemu/kqemu-1.3.0pre11.tar.gz;
@@ -8,11 +8,13 @@ args : with args;
 		buildInputs = [];
 		configureFlags = [''--prefix=$out'' ''--kernel-path=$(ls -d ${kernel}/lib/modules/*/build)''];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
   debugStep = FullDepEntry (''
   	cat config-host.mak
   '') [minInit];
   preConfigure = FullDepEntry ('' 
+  	sed -e 's/`uname -r`/'"$(basename ${kernel}/lib/modules/*)"'/' -i install.sh
   	sed -e '/kernel_path=/akernel_path=$out$kernel_path' -i install.sh
 	sed -e '/depmod/d' -i install.sh
 	cat install.sh
@@ -21,7 +23,7 @@ in
 stdenv.mkDerivation rec {
 	name = "kqemu-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [preConfigure doConfigure debugStep doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [preConfigure doConfigure debugStep doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 		Kernel module for Qemu acceleration
diff --git a/pkgs/os-specific/linux/module-init-tools/aggregator.nix b/pkgs/os-specific/linux/module-init-tools/aggregator.nix
index cfd49cc0813f0..ed30be250d23e 100644
--- a/pkgs/os-specific/linux/module-init-tools/aggregator.nix
+++ b/pkgs/os-specific/linux/module-init-tools/aggregator.nix
@@ -1,10 +1,11 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		addSbinPath = true;
 		src = "";
 		buildInputs = [module_init_tools];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let 
 
 doCollect = FullDepEntry (''
@@ -17,7 +18,7 @@ done
 rm -rf nix-support
 cd lib/modules/
 rm */modules.*
-MODULE_DIR=$PWD/ depmod -a 
+MODULE_DIR=$PWD/ depmod -a *
 cd $out/
 '') [minInit addInputs defEnsureDir];
 in
@@ -25,7 +26,7 @@ stdenv.mkDerivation rec {
 	name = "kernel-modules";
 	inherit moduleSources;
 	builder = writeScript (name + "-builder")
-		(textClosure [doCollect doForceShare doPropagate]);
+		(textClosure localDefs [doCollect doForceShare doPropagate]);
 	meta = {
 		description = "
 		A directory to hold all  the modules, including those 
diff --git a/pkgs/os-specific/linux/sdparm/1.02.nix b/pkgs/os-specific/linux/sdparm/1.02.nix
index 0616ac83563b8..edff04444e061 100644
--- a/pkgs/os-specific/linux/sdparm/1.02.nix
+++ b/pkgs/os-specific/linux/sdparm/1.02.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://sg.torque.net/sg/p/sdparm-1.02.tgz;
@@ -9,10 +9,11 @@ args : with args;
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "sdparm-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	SCSI parameters utility.
diff --git a/pkgs/os-specific/linux/usbutils/default.nix b/pkgs/os-specific/linux/usbutils/default.nix
index b7d2c349e25cd..1f123fadc8793 100644
--- a/pkgs/os-specific/linux/usbutils/default.nix
+++ b/pkgs/os-specific/linux/usbutils/default.nix
@@ -3,17 +3,17 @@
 let
 
   usbids = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/usb.ids.20061212.bz2;
-    sha256 = "112l4fzjn5p3y6fv3x10vbrd36n2v5n04s7pjdlkb2yqv4crp84m";
+    url = http://nix.cs.uu.nl/dist/tarballs/usb.ids.20080115.bz2;
+    sha256 = "0xymp8fpp9pnkj2i4ry8zpsvy18zw14sx03pnz316lpgwc6dx12n";
   };
 
 in
 
 stdenv.mkDerivation {
-  name = "usbutils-0.72";
+  name = "usbutils-0.73";
   src = fetchurl {
-    url = mirror://sourceforge/linux-usb/usbutils-0.72.tar.gz;
-    sha256 = "08s4g4sz7p3a1afvphxd7h5bbfywvp0j611y85wbhwr14i9m6f00";
+    url = mirror://sourceforge/linux-usb/usbutils-0.73.tar.gz;
+    sha256 = "1x27mc2apyipf8fa2ac49rfnkm7f5dwv784b1ncgc5yjiz4prp1f";
   };
   buildInputs = [libusb];
   preBuild = "bunzip2 < ${usbids} > usb.ids";
diff --git a/pkgs/servers/http/apache-modules/tomcat-connectors/builder.sh b/pkgs/servers/http/apache-modules/tomcat-connectors/builder.sh
new file mode 100644
index 0000000000000..70b609e64656a
--- /dev/null
+++ b/pkgs/servers/http/apache-modules/tomcat-connectors/builder.sh
@@ -0,0 +1,8 @@
+source $stdenv/setup
+
+tar xfvz $src
+cd tomcat-connectors-*-src/native
+./configure --with-apxs=$apacheHttpd/bin/apxs --with-java-home=$jdk
+make
+ensureDir $out/modules
+cp apache-2.0/mod_jk.so $out/modules
diff --git a/pkgs/servers/http/apache-modules/tomcat-connectors/default.nix b/pkgs/servers/http/apache-modules/tomcat-connectors/default.nix
new file mode 100644
index 0000000000000..5c33c444c0d66
--- /dev/null
+++ b/pkgs/servers/http/apache-modules/tomcat-connectors/default.nix
@@ -0,0 +1,14 @@
+{stdenv, fetchurl, apacheHttpd, jdk}:
+
+stdenv.mkDerivation {
+  name = "tomcat-connectors-1.2.26";
+  builder = ./builder.sh;
+
+  src = fetchurl {
+    url = http://apache.proserve.nl/tomcat/tomcat-connectors/jk/source/jk-1.2.26/tomcat-connectors-1.2.26-src.tar.gz;
+    md5 = "feaec245136bc4d99a9dde95a00ea93c";
+  };
+
+  inherit apacheHttpd;
+  buildInputs = [apacheHttpd jdk];
+}
diff --git a/pkgs/servers/http/jboss/builder.sh b/pkgs/servers/http/jboss/builder.sh
new file mode 100644
index 0000000000000..1a9e650ebcc15
--- /dev/null
+++ b/pkgs/servers/http/jboss/builder.sh
@@ -0,0 +1,18 @@
+buildInputs="$jdk5"
+source $stdenv/setup
+
+export JDK_HOME=$jdk5
+export JAVA_HOME=$jdk5
+
+tar xfvz $src
+cd jboss-*
+cd build
+sh build.sh
+ensureDir $out
+cp -av output/jboss-*/* $out
+
+# Insert JAVA_HOME variable to make sure the latest JRE is used and not version 5
+sed -i -e "/GREP/aJAVA_HOME=$jdk" $out/bin/run.sh
+
+# Change the deploy directory to the nix profile
+sed -i -e "s|deploy/|/nix/var/nix/profiles/default/server/default/deploy/|" $out/server/default/conf/jboss-service.xml
diff --git a/pkgs/servers/http/jboss/default.nix b/pkgs/servers/http/jboss/default.nix
new file mode 100644
index 0000000000000..279e4bfae71c8
--- /dev/null
+++ b/pkgs/servers/http/jboss/default.nix
@@ -0,0 +1,20 @@
+{ stdenv, fetchurl, jdk5, jdk }:
+
+stdenv.mkDerivation {
+  name = "jboss-4.2.2.GA";
+
+  builder = ./builder.sh;
+  src = 
+    fetchurl {
+      url = http://garr.dl.sourceforge.net/sourceforge/jboss/jboss-4.2.2.GA-src.tar.gz;
+      md5 = "2a626cdccabe712628555676d67ad44a";
+    };
+
+  inherit jdk5 jdk;
+
+  meta = {
+    homepage = "http://www.jboss.org/";
+    description = "JBoss, Open Source J2EE application server";
+    license = "GPL/LGPL";
+  };
+}
diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix
index b9ed02ffd2067..a46f99e454b11 100644
--- a/pkgs/servers/sql/postgresql/default.nix
+++ b/pkgs/servers/sql/postgresql/default.nix
@@ -5,12 +5,12 @@ assert ncurses != null;
 assert readline != null;
 
 stdenv.mkDerivation {
-  name = "postgresql-8.0.6";
+  name = "postgresql-8.2.6";
   builder = ./builder.sh;
 
   src = fetchurl {
-    url = ftp://ftp2.nl.postgresql.org/mirror/postgresql/source/v8.0.6/postgresql-8.0.6.tar.bz2;
-    md5 = "f3b27b8171267f9a87592f931c09f0ee";
+    url = ftp://ftp.de.postgresql.org/mirror/postgresql/source/v8.2.6/postgresql-8.2.6.tar.bz2;
+    sha256="056ixbsfmdwhniryc0mr1kl66jywkqqhqvjdi7i3v4qzh9z34hgf";
   };
 
   inherit readline;
diff --git a/pkgs/servers/xmpp/ejabberd/builder.sh b/pkgs/servers/xmpp/ejabberd/builder.sh
new file mode 100644
index 0000000000000..4abf8da0682e5
--- /dev/null
+++ b/pkgs/servers/xmpp/ejabberd/builder.sh
@@ -0,0 +1,9 @@
+buildInputs="$expat $erlang $zlib $openssl"
+
+source $stdenv/setup
+
+tar xfvz $src
+cd $name/src
+./configure --prefix=$out
+make
+make install
diff --git a/pkgs/servers/xmpp/ejabberd/default.nix b/pkgs/servers/xmpp/ejabberd/default.nix
new file mode 100644
index 0000000000000..8ce1b0912de25
--- /dev/null
+++ b/pkgs/servers/xmpp/ejabberd/default.nix
@@ -0,0 +1,11 @@
+{stdenv, fetchurl, expat, erlang, zlib, openssl}:
+
+stdenv.mkDerivation {
+  name = "ejabberd-1.1.4";
+  builder = ./builder.sh;
+  src = fetchurl {
+    url = http://www.process-one.net/downloads/ejabberd/1.1.4/ejabberd-1.1.4.tar.gz;
+    md5 = "65e9cd346f11a28afbacfe1d7be3a33b";
+  };
+  inherit expat erlang zlib openssl;
+}
diff --git a/pkgs/stdenv/generic/setup-sh-defs.nix b/pkgs/stdenv/generic/setup-sh-defs.nix
deleted file mode 100644
index 9f08030717866..0000000000000
--- a/pkgs/stdenv/generic/setup-sh-defs.nix
+++ /dev/null
@@ -1,902 +0,0 @@
-with (import ../../lib/strings-with-deps.nix (import ../../lib/default-unstable.nix)); 
-
-rec {
-	setStrictMode = noDepEntry "set -e;";
-	setNixGcc = noDepEntry "test -z \$NIX_GCC && NIX_GCC=@gcc@;";
-
-	setPathDelimiter = noDepEntry "
-if [ -z ${system##*cygwin*} ]; then
-  PATH_DELIMITER=;
-else
-  PATH_DELIMITER=;
-fi
-" ;
-
-	
-	initPath = noDepEntry "# Set up the initial path.
-PATH=
-for i in \$NIX_GCC @initialPath@; do
-    PATH=\$PATH\${PATH:+:}\$i/bin
-done
-
-if test \"\$NIX_DEBUG\" = \"1\"; then
-    echo \"Initial path: \$PATH\"
-fi
-";
-
-	execPreHook = FullDepEntry "# Execute the pre-hook.
-export SHELL=@shell@
-if test -z \"\$shell\"; then
-    export shell=@shell@
-fi
-param1=@param1@
-param2=@param2@
-param3=@param3@
-param4=@param4@
-param5=@param5@
-if test -n \"@preHook@\"; then
-    source @preHook@
-fi
-" [];
-
-	checkShellEnv = FullDepEntry "# Check that the pre-hook initialised SHELL.
-if test -z \"\$SHELL\"; then echo \"SHELL not set\"; exit 1; fi
-" [];
-
-	gccSetupHook = FullDepEntry "# Hack: run gcc's setup hook.
-envHooks=()
-if test -f \$NIX_GCC/nix-support/setup-hook; then
-    source \$NIX_GCC/nix-support/setup-hook
-fi
-" [setNixGcc];
-
-    
-	defEnsureDir = FullDepEntry "# Ensure that the given directories exists.
-ensureDir() {
-    local dir
-    for dir in \"\$@\"; do
-        if ! test -x \"\$dir\"; then mkdir -p \"\$dir\"; fi
-    done
-}
-" [];
-
-	defInstallBin = FullDepEntry "
-
-installBin() {
-  ensureDir $out/bin
-  cp "$@" $out/bin
-}
-
-" [];
-
-	defAssertEnvExists = FullDepEntry "
-assertEnvExists(){
-  if test -z "${!1}"; then
-      msg=${2:-error: assertion failed: env var $1 is required}
-      echo $msg >&2; exit 1
-  fi
-}
-" [];
-
-	defFail = FullDepEntry "# Called when some build action fails.  If \$succeedOnFailure is set,
-# create the file `\$out/nix-support/failed' to signal failure, and
-# exit normally.  Otherwise, exit with failure.
-fail() {
-    exitCode=\$?
-    if test \"\$succeedOnFailure\" = 1; then
-        ensureDir \"\$out/nix-support\"
-        touch \"\$out/nix-support/failed\"
-        exit 0
-    else
-        exit \$?
-    fi
-}
-" [];
-
-	runAddInputsHook = FullDepEntry "# Allow the caller to augment buildInputs (it's not always possible to
-# do this before the call to setup.sh, since the PATH is empty at that
-# point; here we have a basic Unix environment).
-eval \"\$addInputsHook\"
-" [defFail];
-
-	defFindInputs = FullDepEntry "# Recursively find all build inputs.
-findInputs()
-{
-    local pkg=\$1
-
-    case \$pkgs in
-        *\ \$pkg\ *)
-            return 0
-            ;;
-    esac
-    
-    pkgs=\"\$pkgs \$pkg \"
-
-    if test -f \$pkg/nix-support/setup-hook; then
-        source \$pkg/nix-support/setup-hook
-    fi
-    
-    if test -f \$pkg/nix-support/propagated-build-inputs; then
-        for i in \$(cat \$pkg/nix-support/propagated-build-inputs); do
-            findInputs \$i
-        done
-    fi
-}
-" [];
-
-	getInputs = FullDepEntry "pkgs=\"\"
-if test -n \"\$buildinputs\"; then
-    buildInputs=\"\$buildinputs\" # compatibility
-fi
-for i in \$buildInputs \$propagatedBuildInputs; do
-    findInputs \$i
-done
-" [defFindInputs];
-
-	defAddToEnv = FullDepEntry "# Set the relevant environment variables to point to the build inputs
-# found above.
-addToEnv()
-{
-    local pkg=\$1
-
-    if test \"\$ignoreFailedInputs\" != \"1\" -a -e \$1/nix-support/failed; then
-        echo \"failed input \$1\" >&2
-        fail
-    fi
-
-    if test -d \$1/bin; then
-        export _PATH=\$_PATH\${_PATH:+:}\$1/bin
-    fi
-
-    for i in \"\${envHooks[@]}\"; do
-        \$i \$pkg
-    done
-}
-" [defFail];
-
-	preparePackageEnv = FullDepEntry "for i in \$pkgs; do
-    addToEnv \$i
-done
-" [getInputs defAddToEnv];
-
-	putOutInRpath = FullDepEntry "# Add the output as an rpath.
-if test \"\$NIX_NO_SELF_RPATH\" != \"1\"; then
-    export NIX_LDFLAGS=\"-rpath \$out/lib \$NIX_LDFLAGS\"
-fi
-" [initPath];
-
-	setupStripping = FullDepEntry "# Strip debug information by default.
-if test -z \"\$NIX_STRIP_DEBUG\"; then
-    export NIX_STRIP_DEBUG=1
-    export NIX_CFLAGS_STRIP=\"-g0 -Wl,--strip-debug\"
-fi
-" [initPath];
-
-	checkNixEnv = FullDepEntry "# Do we know where the store is?  This is required for purity checking.
-if test -z \"\$NIX_STORE\"; then
-    echo \"Error: you have an old version of Nix that does not set the\" \
-        \"NIX_STORE variable.  Please upgrade.\" >&2
-    exit 1
-fi
-
-
-# We also need to know the root of the build directory for purity checking.
-if test -z \"\$NIX_BUILD_TOP\"; then
-    echo \"Error: you have an old version of Nix that does not set the\" \
-        \"NIX_BUILD_TOP variable.  Please upgrade.\" >&2
-    exit 1
-fi
-" [initPath];
-
-	setTZ = noDepEntry "# Set the TZ (timezone) environment variable, otherwise commands like
-# `date' will complain (e.g., `Tue Mar 9 10:01:47 Local time zone must
-# be set--see zic manual page 2004').
-export TZ=UTC
-" ;
-
-	setPrefix = FullDepEntry "# Set the prefix.  This is generally \$out, but it can be overriden,
-# for instance if we just want to perform a test build/install to a
-# temporary location and write a build report to \$out.
-if test -z \"\$prefix\"; then
-    prefix=\"\$out\";
-fi
-
-if test \"\$useTempPrefix\" = \"1\"; then
-    prefix=\"\$NIX_BUILD_TOP/tmp_prefix\";
-fi
-" [checkNixEnv];
-
-	runPostHook = FullDepEntry "# Execute the post-hook.
-if test -n \"@postHook@\"; then
-    source @postHook@
-fi
-" [setTZ setPrefix execPreHook gccSetupHook preparePackageEnv];
-
-	finalSetPath = FullDepEntry "PATH=\$_PATH\${_PATH:+:}\$PATH
-if test \"\$NIX_DEBUG\" = \"1\"; then
-    echo \"Final path: \$PATH\"
-fi
-" [runPostHook];
-
-	defSubstitute = FullDepEntry "######################################################################
-# Textual substitution functions.
-
-
-# Some disgusting hackery to escape replacements in Sed substitutions.
-# We should really have a tool that replaces literal values by other
-# literal values, without any need for escaping.
-escapeSed() {
-    local s=\"\$1\"
-    # The `tr' hack is to escape newlines.  Sed handles newlines very
-    # badly, so we just replace newlines with the magic character 0xff
-    # (377 octal).  So don't use that character in replacements :-P
-    echo -n \"\$1\" | tr '\012' '\377' | sed -e 's^\\^\\\\^g' -e 's^\xff^\\n^g' -e 's/\^/\\^/g' -e 's/&/\\&/g'
-}
-
-
-substitute() {
-    local input=\"\$1\"
-    local output=\"\$2\"
-
-    local -a params=(\"\$@\")
-
-    local sedScript=\$NIX_BUILD_TOP/.sedargs
-    rm -f \$sedScript
-    touch \$sedScript
-
-    local n p pattern replacement varName
-    
-    for ((n = 2; n < \${#params[*]}; n += 1)); do
-        p=\${params[\$n]}
-
-        if test \"\$p\" = \"--replace\"; then
-            pattern=\"\${params[\$((n + 1))]}\"
-            replacement=\"\${params[\$((n + 2))]}\"
-            n=\$((n + 2))
-        fi
-
-        if test \"\$p\" = \"--subst-var\"; then
-            varName=\"\${params[\$((n + 1))]}\"
-            pattern=\"@\$varName@\"
-            replacement=\"\${!varName}\"
-            n=\$((n + 1))
-        fi
-
-        if test \"\$p\" = \"--subst-var-by\"; then
-            pattern=\"@\${params[\$((n + 1))]}@\"
-            replacement=\"\${params[\$((n + 2))]}\"
-            n=\$((n + 2))
-        fi
-
-        replacement=\"\$(escapeSed \"\$replacement\")\"
-
-        echo \"s^\$pattern^\$replacement^g\" >> \$sedScript
-    done
-
-    sed -f \$sedScript < \"\$input\" > \"\$output\".tmp
-    if test -x \"\$output\"; then
-        chmod +x \"\$output\".tmp
-    fi
-    mv -f \"\$output\".tmp \"\$output\"
-}
-
-
-substituteInPlace() {
-    local fileName=\"\$1\"
-    shift
-    substitute \"\$fileName\" \"\$fileName\" \"\$@\"
-}
-
-
-substituteAll() {
-    local input=\"\$1\"
-    local output=\"\$2\"
-    
-    # Select all environment variables that start with a lowercase character.
-    for envVar in \$(env | sed \"s/^[^a-z].*//\" | sed \"s/^\([^=]*\)=.*/\1/\"); do
-        if test \"\$NIX_DEBUG\" = \"1\"; then
-            echo \"\$envVar -> \${!envVar}\"
-        fi
-        args=\"\$args --subst-var \$envVar\"
-    done
-
-    substitute \"\$input\" \"\$output\" \$args
-}  
-" [initPath];
-
-	defNest = NoDepEntry "######################################################################
-# What follows is the generic builder.
-
-
-nestingLevel=0
-
-startNest() {
-    nestingLevel=\$((\$nestingLevel + 1))
-    echo -en \"\e[\$1p\"
-}
-
-stopNest() {
-    nestingLevel=\$((\$nestingLevel - 1))
-    echo -en \"\e[q\"
-}
-
-header() {
-    startNest \"\$2\"
-    echo \"\$1\"
-}
-
-# Make sure that even when we exit abnormally, the original nesting
-# level is properly restored.
-closeNest() {
-    while test \$nestingLevel -gt 0; do
-        stopNest
-    done
-}
-
-trap \"closeNest\" EXIT
-" ;
-
-
-	defDumpVars = FullDepEntry "# This function is useful for debugging broken Nix builds.  It dumps
-# all environment variables to a file `env-vars' in the build
-# directory.  If the build fails and the `-K' option is used, you can
-# then go to the build directory and source in `env-vars' to reproduce
-# the environment used for building.
-dumpVars() {
-    if test \"\$noDumpEnvVars\" != \"1\"; then
-        export > \$NIX_BUILD_TOP/env-vars
-    fi
-}
-" [checkNixEnv];
-
-
-	defStartStopLog = FullDepEntry  "# Redirect stdout/stderr to a named pipe connected to a `tee' process
-# that writes the specified file (and also to our original stdout).
-# The original stdout is saved in descriptor 3.
-startLog() {
-    local logFile=\${logNr}_\$1
-    logNr=\$((logNr + 1))
-    if test \"\$logPhases\" = 1; then
-        ensureDir \$logDir
-
-        exec 3>&1
-
-        if test \"\$dontLogThroughTee\" != 1; then
-            # This required named pipes (fifos).
-            logFifo=\$NIX_BUILD_TOP/log_fifo
-            test -p \$logFifo || mkfifo \$logFifo
-            startLogWrite \"\$logDir/\$logFile\" \"\$logFifo\"
-            exec > \$logFifo 2>&1
-        else
-            exec > \$logDir/\$logFile 2>&1
-        fi
-    fi
-}
-
-# Factored into a separate function so that it can be overriden.
-startLogWrite() {
-    tee \"\$1\" < \"\$2\" &
-    logWriterPid=\$!
-}
-
-# Restore the original stdout/stderr.
-stopLog() {
-    if test \"\$logPhases\" = 1; then
-        exec >&3 2>&1
-
-        # Wait until the tee process has died.  Otherwise output from
-        # different phases may be mixed up.
-        if test -n \"\$logWriterPid\"; then
-            wait \$logWriterPid
-            logWriterPid=
-            rm \$logFifo
-        fi
-    fi
-}
-
-
-" [setLogVars checkNixEnv ];
-
-
-	setLogVars = FullDepEntry "if test -z \"\$logDir\"; then
-    logDir=\$out/log
-fi
-
-logNr=0
-" [initPath];
-
-	defStripHash = FullDepEntry "# Utility function: return the base name of the given path, with the
-# prefix `HASH-' removed, if present.
-stripHash() {
-    strippedName=\$(basename \$1);
-    if echo \"\$strippedName\" | grep -q '^[a-z0-9]\{32\}-'; then
-        strippedName=\$(echo \"\$strippedName\" | cut -c34-)
-    fi
-}
-" [initPath];
-
-	defUnpack = FullDepEntry "
-unpackFile() {
-    local file=\$1
-    local cmd
-
-    header \"unpacking source archive \$file\" 3
-
-    case \$file in
-        *.tar)
-            tar xvf \$file || fail
-            ;;
-        *.tar.gz | *.tgz | *.tar.Z)
-            gunzip < \$file | tar xvf - || fail
-            ;;
-        *.tar.bz2 | *.tbz2)
-            bunzip2 < \$file | tar xvf - || fail
-            ;;
-        *.zip)
-            unzip \$file || fail
-            ;;
-        *)
-            if test -d \"\$file\"; then
-                stripHash \$file
-                cp -prvd \$file \$strippedName || fail
-            else
-                if test -n \"\$findUnpacker\"; then
-                    \$findUnpacker \$1;
-                fi
-                if test -z \"\$unpackCmd\"; then
-                    echo \"source archive \$file has unknown type\"
-                    exit 1
-                fi
-                eval \"\$unpackCmd\" || fail
-            fi
-            ;;
-    esac
-
-    stopNest
-}
-" [preparePackageEnv];
-
-	defUnpackW = FullDepEntry "
-unpackW() {
-    if test -n \"\$unpackPhase\"; then
-        eval \"\$unpackPhase\"
-        return
-    fi
-
-    if test -z \"\$srcs\"; then
-        if test -z \"\$src\"; then
-            echo 'variable \$src or \$srcs should point to the source'
-            exit 1
-        fi
-        srcs=\"\$src\"
-    fi
-
-    # To determine the source directory created by unpacking the
-    # source archives, we record the contents of the current
-    # directory, then look below which directory got added.  Yeah,
-    # it's rather hacky.
-    local dirsBefore=\"\"
-    for i in *; do
-        if test -d \"\$i\"; then
-            dirsBefore=\"\$dirsBefore \$i \"
-        fi
-    done
-
-    # Unpack all source archives.
-    for i in \$srcs; do
-        unpackFile \$i
-    done
-
-    # Find the source directory.
-    if test -n \"\$setSourceRoot\"; then
-        eval \"\$setSourceRoot\"
-    else
-        sourceRoot=
-        for i in *; do
-            if test -d \"\$i\"; then
-                case \$dirsBefore in
-                    *\ \$i\ *)
-                        ;;
-                    *)
-                        if test -n \"\$sourceRoot\"; then
-                            echo \"unpacker produced multiple directories\"
-                            exit 1
-                        fi
-                        sourceRoot=\$i
-                        ;;
-                esac
-            fi
-        done
-    fi
-
-    if test -z \"\$sourceRoot\"; then
-        echo \"unpacker appears to have produced no directories\"
-        exit 1
-    fi
-
-    echo \"source root is \$sourceRoot\"
-
-    # By default, add write permission to the sources.  This is often
-    # necessary when sources have been copied from other store
-    # locations.
-    if test \"dontMakeSourcesWritable\" != 1; then
-        chmod -R +w \$sourceRoot
-    fi
-
-    eval \"\$postUnpack\"
-}
-" [defUnpack];
-
-
-
-defUnpackPhase = FullDepEntry "
-unpackPhase() {
-    sourceRoot=. # don't change to user dir homeless shelter if custom unpackSource does'nt set sourceRoot
-    header \"unpacking sources\"
-    startLog \"unpack\"
-    unpackW
-    stopLog
-    stopNest
-    cd \$sourceRoot
-}
-" [unpackW];
-
-
-	defPatchW = FullDepEntry "
-patchW() {
-    if test -n \"\$patchPhase\"; then
-        eval \"\$patchPhase\"
-        return
-    fi
-
-    if test -z \"\$patchFlags\"; then
-        patchFlags=\"-p1\"
-    fi
-
-    for i in \$patches; do
-        header \"applying patch \$i\" 3
-        local uncompress=cat
-        case \$i in
-            *.gz)
-                uncompress=gunzip
-                ;;
-            *.bz2)
-                uncompress=bunzip2
-                ;;
-        esac
-        \$uncompress < \$i | patch \$patchFlags || fail
-        stopNest
-    done
-}
-" [getInputs]
-
-	defPatchPhase = FullDepEntry "
-patchPhase() {
-    if test -z \"\$patchPhase\" -a -z \"\$patches\"; then return; fi
-    header \"patching sources\"
-    startLog \"patch\"
-    patchW
-    stopLog
-    stopNest
-}
-" [defPatchW];
-
-	defFixLibTool = FullDepEntry "fixLibtool() {
-    sed 's^eval sys_lib_.*search_path=.*^^' < \$1 > \$1.tmp
-    mv \$1.tmp \$1
-}
-" [initPath];
-
-	defConfigureW = FullDepEntry "
-configureW() {
-    if test -n \"\$configurePhase\"; then
-        eval \"\$configurePhase\"
-        return
-    fi
-
-    eval \"\$preConfigure\"
-
-    if test -z \"\$configureScript\"; then
-        configureScript=./configure
-        if ! test -x \$configureScript; then
-            echo \"no configure script, doing nothing\"
-            return
-        fi
-    fi
-
-    if test -z \"\$dontFixLibtool\"; then
-        for i in \$(find . -name \"ltmain.sh\"); do
-            echo \"fixing libtool script \$i\"
-            fixLibtool \$i
-        done
-    fi
-
-    if test -z \"\$dontAddPrefix\"; then
-        configureFlags=\"--prefix=\$prefix \$configureFlags\"
-    fi
-
-    echo \"configure flags: \$configureFlags \${configureFlagsArray[@]}\"
-    \$configureScript \$configureFlags\"\${configureFlagsArray[@]}\" || fail
-
-    eval \"\$postConfigure\"
-}
-" [initPath];
-
-
-	defConfigurePhase = FullDepEntry "
-configurePhase() {
-    header \"configuring\"
-    startLog \"configure\"
-    configureW
-    stopLog
-    stopNest
-}
-" [defConfigureW];
-
-	defBuildW = FullDepEntry "
-buildW() {
-    if test -n \"\$buildPhase\"; then
-        eval \"\$buildPhase\"
-        return
-    fi
-
-    eval \"\$preBuild\"
-    
-    echo \"make flags: \$makeFlags \${makeFlagsArray[@]} \$buildFlags \${buildFlagsArray[@]}\"
-    make \
-        \$makeFlags \"\${makeFlagsArray[@]}\" \
-        \$buildFlags \"\${buildFlagsArray[@]}\" || fail
-
-    eval \"\$postBuild\"
-}
-" [initPath];
-
-	defBuildPhase = FullDepEntry "
-buildPhase() {
-    if test \"\$dontBuild\" = 1; then
-        return
-    fi
-    header \"building\"
-    startLog \"build\"
-    buildW
-    stopLog
-    stopNest
-}
-" [defBuildW];
-
-
-	defCheckW = FullDepEntry "
-checkW() {
-    if test -n \"\$checkPhase\"; then
-        eval \"\$checkPhase\"
-        return
-    fi
-
-    if test -z \"\$checkTarget\"; then
-        checkTarget=\"check\"
-    fi
-
-    echo \"check flags: \$makeFlags \${makeFlagsArray[@]} \$checkFlags \${checkFlagsArray[@]}\"
-    make \
-        \$makeFlags \"\${makeFlagsArray[@]}\" \
-        \$checkFlags \"\${checkFlagsArray[@]}\" \$checkTarget || fail
-}
-" [initPath];
-
-
-	defCheckPhase = FullDepEntry "
-checkPhase() {
-    if test \"\$doCheck\" != 1; then
-        return
-    fi
-    header \"checking\"
-    startLog \"check\"
-    checkW
-    stopLog
-    stopNest
-}
-" [checkPhase];
-
-
-	defPatchElf = FullDepEntry "
-patchELF() {
-    # Patch all ELF executables and shared libraries.
-    header \"patching ELF executables and libraries\"
-    find \"\$prefix\" \( \
-        \( -type f -a -name \"*.so*\" \) -o \
-        \( -type f -a -perm +0100 \) \
-        \) -print -exec patchelf --shrink-rpath {} \;
-    stopNest
-}
-" [initPath defNest];
-
-
-	defInstallW = FullDepEntry "
-installW() {
-    if test -n \"\$installPhase\"; then
-        eval \"\$installPhase\"
-        return
-    fi
-
-    eval \"\$preInstall\"
-
-    ensureDir \"\$prefix\"
-
-    if test -z \"\$installCommand\"; then
-        if test -z \"\$installTargets\"; then
-            installTargets=install
-        fi
-        echo \"install flags: \$installTargets \$makeFlags \${makeFlagsArray[@]} \$installFlags \${installFlagsArray[@]}\"
-        make \$installTargets \
-            \$makeFlags \"\${makeFlagsArray[@]}\" \
-            \$installFlags \"\${installFlagsArray[@]}\" || fail
-    else
-        eval \"\$installCommand\"
-    fi
-
-    eval \"\$postInstall\"
-}
-" [initPath];
-
-	
-	defInstallPhase = FullDepEntry "
-installPhase() {
-    if test \"\$dontInstall\" = 1; then
-        return
-    fi
-    header \"installing\"
-    startLog \"install\"
-    installW
-    stopLog
-    stopNest
-}
-" [defInstallW defNest defStartStopLog];
-
-
-	defFixupW = FullDepEntry "
-
-# The fixup phase performs generic, package-independent, Nix-related
-# stuff, like running patchelf and setting the
-# propagated-build-inputs.  It should rarely be overriden.
-fixupW() {
-    if test -n "$fixupPhase"; then
-        eval "$fixupPhase"
-        return
-    fi
-
-    eval "$preFixup"
-
- 	forceShare=${forceShare:=man doc info}
- 	if test -n "$forceShare"; then
- 		for d in $forceShare; do
- 			if test -d "$prefix/$d"; then
- 				if test -d "$prefix/share/$d"; then
- 					echo "Both $d/ and share/$d/ exists!"
- 				else
-					echo Fixing location of $dir/ subdirectory
- 					ensureDir $prefix/share
-					if test -w $prefix/share; then
-	 					mv -v $prefix/$d $prefix/share
- 						ln -sv share/$d $prefix
-					fi
- 				fi
-			else
-				echo "No $d/ subdirectory, skipping."
- 			fi
- 		done;
- 	fi
-
-
-# TODO : strip _only_ ELF executables, and return || fail here...
-    if test -z "$dontStrip"; then
-		echo "Stripping debuging symbols from files in"
-		stripDirs "${stripDebugList:-lib}" -S
-		echo "Stripping all symbols from files in"
-		stripDirs "${stripAllList:-bin sbin}" -s
-    fi
-
-    if test "$havePatchELF" = 1 -a -z "$dontPatchELF"; then
-        patchELF "$prefix"
-    fi
-
-    if test -n "$propagatedBuildInputs"; then
-        ensureDir "$out/nix-support"
-        echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
-    fi
-
-	if test -n "$setupHook"; then
-		ensureDir "$out/nix-support"
-		substituteAll "$setupHook" "$out/nix-support/setup-hook"
-	fi
-
-    eval "$postFixup"
-}
-" [defPatchElf initPath];
-
-
-	defFixupPhase = FullDepEntry "
-fixupPhase() {
-    if test \"\$dontFixup\" = 1; then
-        return
-    fi
-    header \"post-installation fixup\"
-    startLog \"fixup\"
-    fixupW
-    stopLog
-    stopNest
-}
-" [defFixupW defNest defStartStopLog];
-
-
-	defDistW = FullDepEntry "
-distW() {
-    if test -n \"\$distPhase\"; then
-        eval \"\$distPhase\"
-        return
-    fi
-
-    eval \"\$preDist\"
-    
-    if test -z \"\$distTarget\"; then
-        distTarget=\"dist\"
-    fi
-
-    echo \"dist flags: \$distFlags \${distFlagsArray[@]}\"
-    make \$distFlags \"\${distFlagsArray[@]}\" \$distTarget || fail
-
-    if test \"\$dontCopyDist\" != 1; then
-        ensureDir \"\$out/tarballs\"
-
-        if test -z \"\$tarballs\"; then
-            tarballs=\"*.tar.gz\"
-        fi
-
-        # Note: don't quote \$tarballs, since we explicitly permit
-        # wildcards in there.
-        cp -pvd \$tarballs \$out/tarballs
-    fi
-
-    eval \"\$postDist\"
-}
-" [initPath ];
-
-
-	defDistPhase = FullDepEntry "
-distPhase() {
-    if test \"\$doDist\" != 1; then
-        return
-    fi
-    header \"creating distribution\"
-    startLog \"dist\"
-    distW
-    stopLog
-    stopNest
-}
-" [defDistW defNest defStartStopLog];
-
-	defGenericBuild = FullDepEntry "
-genericBuild() {
-    header \"building \$out\"
-
-    if test -n \"\$buildCommand\"; then
-        eval \"\$buildCommand\"
-        return
-    fi
-
-    if test -z \"\$phases\"; then
-        phases=\"unpackPhase patchPhase configurePhase buildPhase checkPhase \
-            installPhase fixupPhase distPhase\";
-    fi
-
-    for i in \$phases; do
-        dumpVars
-        eval \"\$i\"
-    done
-    
-    stopNest
-}
-" [defUnpackPhase defBuildPhase defInstallPhase];
-
-doDumpVars = FullDepEntry "
-dumpVars
-" [defDumpVars];
diff --git a/pkgs/tools/misc/grub/default.nix b/pkgs/tools/misc/grub/default.nix
index 1b7f052dfdf31..87ba35566c00e 100644
--- a/pkgs/tools/misc/grub/default.nix
+++ b/pkgs/tools/misc/grub/default.nix
@@ -11,22 +11,24 @@ stdenv.mkDerivation {
     url = ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz;
     md5 = "cd3f3eb54446be6003156158d51f4884";
   };
-  
-  patches = [
-    # Patch to add primitive splash screen support (not the fancy SUSE gfxmenu stuff).
-    # With this you can set splashimage=foo.xpm.gz in menu.lst to get
-    # a 640x480, 14-colour background.
-    (fetchurl {
-      url = "http://cvs.archlinux.org/cgi-bin/viewcvs.cgi/*checkout*/system/grub-gfx/grub-0.97-graphics.patch?rev=HEAD&cvsroot=AUR&only_with_tag=CURRENT&content-type=text/plain";
-      sha256 = "0m6min9cbj71kvp0kxkxdq8dx2dwm3dj0rd5sjz5xdl13ihaj5hy";
-    })
-  ];
+
+  # Lots of patches from Gentoo, in particular splash screen support
+  # (not the fancy SUSE gfxmenu stuff though).  Also a fix for boot
+  # failures on systems with more than 2 GiB RAM.
+  gentooPatches = fetchurl {
+    url = mirror://gentoo/distfiles/grub-0.97-patches-1.4.tar.bz2;
+    sha256 = "1nki5q1b61ahxcmnw6mq7b8ghcysri4lj7q6dx8iqixrvrpxj399";
+  };
 
   # Autoconf/automake required for the splashimage patch.
   buildInputs = [autoconf automake];
 
   preConfigure = ''
+    unpackFile $gentooPatches
+    for i in patch/*.patch; do
+      echo "applying patch $i"
+      patch -p1 < $i || patch -p0 < $i
+    done
     autoreconf
   '';
-  
 }
diff --git a/pkgs/tools/misc/mc/builder.sh b/pkgs/tools/misc/mc/builder.sh
new file mode 100644
index 0000000000000..28b5d68b55aaf
--- /dev/null
+++ b/pkgs/tools/misc/mc/builder.sh
@@ -0,0 +1,7 @@
+source $stdenv/setup
+
+tar xfvz $src
+cd mc-*
+./configure --prefix=$out --with-screen=ncurses
+make
+make install
diff --git a/pkgs/tools/misc/mc/default.nix b/pkgs/tools/misc/mc/default.nix
new file mode 100644
index 0000000000000..9400cbbf44364
--- /dev/null
+++ b/pkgs/tools/misc/mc/default.nix
@@ -0,0 +1,11 @@
+{stdenv, fetchurl, pkgconfig, glib, ncurses, libX11}:
+
+stdenv.mkDerivation {
+  name = "mc-4.6.1";
+  src = fetchurl {
+    url = http://www.ibiblio.org/pub/Linux/utils/file/managers/mc/mc-4.6.1.tar.gz;
+    md5 = "18b20db6e40480a53bac2870c56fc3c4";
+  };
+  buildInputs = [pkgconfig glib ncurses libX11];
+  builder = ./builder.sh;
+}
diff --git a/pkgs/tools/misc/relfs/cvs.2007.12.01.nix b/pkgs/tools/misc/relfs/cvs.2007.12.01.nix
index cffa01b9b95f0..aa0ee22416902 100644
--- a/pkgs/tools/misc/relfs/cvs.2007.12.01.nix
+++ b/pkgs/tools/misc/relfs/cvs.2007.12.01.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 	src = /* put a fetchurl here */
 	fetchcvs {
 		url = ":pserver:anonymous@relfs.cvs.sourceforge.net:/cvsroot/relfs";
@@ -12,6 +12,7 @@ args : with args;
 			e2fsprogs gnomevfs pkgconfig GConf];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 let build = FullDepEntry ("
 	cd deps 
 	sed -e 's/^CPP/#&/ ; s/^# CPP=gcc/CPP=gcc/' -i Makefile.camlidl
@@ -41,7 +42,7 @@ in
 stdenv.mkDerivation rec {
 	name = "relfs-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [build doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [build doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Relational FS over FUSE.
diff --git a/pkgs/tools/networking/ntp/default.nix b/pkgs/tools/networking/ntp/default.nix
index 57d2ee8ab71c5..f96d14e83c0ba 100644
--- a/pkgs/tools/networking/ntp/default.nix
+++ b/pkgs/tools/networking/ntp/default.nix
@@ -3,14 +3,14 @@
 assert stdenv.isLinux -> libcap != null;
  
 stdenv.mkDerivation {
-  name = "ntp-4.2.4p3";
+  name = "ntp-4.2.4p4";
   src = fetchurl {
-    url = http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.4p3.tar.gz;
-    sha256 = "077y1hw6v0qnp3j3w3pcxgsc76waswqhwsbzfj3jqc79jfh65jv9";
+    url = http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.4p4.tar.gz;
+    sha256 = "0im89i51ap7aqlhxq5isz5xg4h8w8ahwdhir8la3c83h3p47fcmv";
   };
-  configureFlags = "
+  configureFlags = ''
     --without-crypto
     ${if stdenv.isLinux then "--enable-linuxcaps" else ""}
-  ";
+  '';
   buildInputs = if stdenv.isLinux then [libcap] else [];
 }
diff --git a/pkgs/tools/networking/p2p/bittorrent/builder.sh b/pkgs/tools/networking/p2p/bittorrent/builder.sh
index 633f53ebd43da..8097995dfbda5 100644
--- a/pkgs/tools/networking/p2p/bittorrent/builder.sh
+++ b/pkgs/tools/networking/p2p/bittorrent/builder.sh
@@ -1,5 +1,4 @@
 source $stdenv/setup
-source $makeWrapper
 
 # Workaround for:
 #  File "...-python-2.4.4/lib/python2.4/posixpath.py", line 62, in join
@@ -20,12 +19,9 @@ installPhase() {
 
     # Create wrappers that set the environment correctly.
     for i in $(cd $out/bin && ls); do
-        # Note: the GUI apps except to be in a directory called `bin',
-        # so don't move them. 
-        mv $out/bin/$i $out/bin/.orig-$i
-        makeWrapper $out/bin/.orig-$i $out/bin/$i \
+        wrapProgram $out/bin/$i \
             --set PYTHONPATH "$(toPythonPath $out):$PYTHONPATH"
     done
 }
 
-genericBuild
\ No newline at end of file
+genericBuild
diff --git a/pkgs/tools/networking/p2p/bittorrent/default.nix b/pkgs/tools/networking/p2p/bittorrent/default.nix
index 3894cbd36d413..cfddd48a342e5 100644
--- a/pkgs/tools/networking/p2p/bittorrent/default.nix
+++ b/pkgs/tools/networking/p2p/bittorrent/default.nix
@@ -6,18 +6,16 @@
 assert gui -> wxPython != null;
 
 stdenv.mkDerivation {
-  name = "bittorrent-5.0.7";
+  name = "bittorrent-5.2.0";
   builder = ./builder.sh;
   
   src = fetchurl {
-    url = http://download.bittorrent.com/dl/BitTorrent-5.0.7.tar.gz;
-    sha256 = "09m2qlhzbc6j1hf6fniri0hh6cy6ccgwi2sph65bpjrc417l94gj";
+    url = http://download.bittorrent.com/dl/BitTorrent-5.2.0.tar.gz;
+    sha256 = "0lg54x5y2k1cb7vpj7hanlnvzqa2k3v24qq0g6fsycjk4n8dky02";
   };
   
-  buildInputs = [python pycrypto twisted]
-    ++ (if gui then [wxPython] else []);
-
-  inherit makeWrapper;
+  buildInputs = [python pycrypto twisted makeWrapper]
+    ++ stdenv.lib.optional gui wxPython;
 
   meta = {
     description = "The original client for the BitTorrent peer-to-peer file sharing protocol";
diff --git a/pkgs/tools/package-management/nix/unstable.nix b/pkgs/tools/package-management/nix/unstable.nix
index 51bcb9ef298a4..79d46ce8e8457 100644
--- a/pkgs/tools/package-management/nix/unstable.nix
+++ b/pkgs/tools/package-management/nix/unstable.nix
@@ -3,14 +3,14 @@
 , stateDir ? "/nix/var"
 }:
 
-let version = "0.12pre10069"; in
+let version = "0.12pre10154"; in
 
 stdenv.mkDerivation {
   name = "nix-${version}";
   
   src = fetchurl {
     url = "http://nix.cs.uu.nl/dist/nix/nix-${version}/nix-${version}.tar.bz2";
-    md5 = "bf05ebe9463f0453beae2c43f05ac13d";
+    md5 = "9e5833e34ade23852a1270d0f2a98ce2";
   };
 
   buildInputs = [perl curl openssl];
diff --git a/pkgs/tools/system/gdmap/0.7.5.nix b/pkgs/tools/system/gdmap/0.7.5.nix
index 354ebb966a1c8..062f63566a6b4 100644
--- a/pkgs/tools/system/gdmap/0.7.5.nix
+++ b/pkgs/tools/system/gdmap/0.7.5.nix
@@ -1,5 +1,5 @@
 args : with args;
-	with builderDefs {
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 		fetchurl {
 			url = http://dfn.dl.sourceforge.net/sourceforge/gdmap/gdmap-0.7.5.tar.gz;
@@ -9,10 +9,11 @@ args : with args;
 		buildInputs = [gtk pkgconfig libxml2 intltool];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "gdmap"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [doConfigure doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [doConfigure doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	Recursive rectangle map of disk usage.	
diff --git a/pkgs/tools/system/pciutils/default.nix b/pkgs/tools/system/pciutils/default.nix
index 84bd24195ce2d..5dd6757477766 100644
--- a/pkgs/tools/system/pciutils/default.nix
+++ b/pkgs/tools/system/pciutils/default.nix
@@ -1,16 +1,16 @@
 {stdenv, fetchurl, zlib}:
 
 stdenv.mkDerivation {
-  name = "pciutils-2.2.5";
+  name = "pciutils-2.2.8";
   builder = ./builder.sh;
   src = fetchurl {
-    url = mirror://kernel/software/utils/pciutils/pciutils-2.2.5.tar.bz2;
-    sha256 = "1zlamdax1i8cf3kvzg7dh7nshvvzlhvkwlxdmym0hbnmbf0p100p";
+    url = mirror://kernel/software/utils/pciutils/pciutils-2.2.8.tar.bz2;
+    sha256 = "0hgri2ancnjl56ld2flb9w606dyvr5gly8gsz3bzl71r8s464qsq";
   };
   buildInputs = [zlib];
 
   pciids = fetchurl {
-    url = http://nix.cs.uu.nl/dist/tarballs/pci.ids.20070226.bz2;
-    sha256 = "1wrpq4dxm03v5jvvdlvwl8nrkj3hspgifkw5czmd647lzikp13qc";
+    url = http://nix.cs.uu.nl/dist/tarballs/pci.ids.20080118.bz2;
+    sha256 = "0dl6psdac62llbklxn4dvkzbw1j1sdadw9i4l36vpd6mvqa7lz0a";
   };
 }
diff --git a/pkgs/tools/system/which/default.nix b/pkgs/tools/system/which/default.nix
index 482d495ba83a4..67ddaa94295a9 100644
--- a/pkgs/tools/system/which/default.nix
+++ b/pkgs/tools/system/which/default.nix
@@ -1,10 +1,10 @@
-{stdenv, fetchurl}: stdenv.mkDerivation {
-  name = "which-2.17";
+args: with args;
+stdenv.mkDerivation {
+  name = "which-2.19";
   src = fetchurl {
-    url = http://ftp.gnu.org/gnu/which/which-2.17.tar.gz;
-    sha256 = "1nnnbn83da8481blmcyv96gm15ccsilr93fmgmwdlzj8a72fjvqp";
+    url = mirror://gnu/which/which-2.19.tar.gz;
+    sha256 = "0lnd8mfpc0r1r2ch54vl3vc6r0fnzfl33sqdda2aq62iyrsbhybx";
   };
-}
-
-
 
+  buildInputs = [readline];
+}
diff --git a/pkgs/tools/typesetting/lhs2tex/default.nix b/pkgs/tools/typesetting/lhs2tex/default.nix
index fc0ce40f8e56c..f071f67fe97ac 100644
--- a/pkgs/tools/typesetting/lhs2tex/default.nix
+++ b/pkgs/tools/typesetting/lhs2tex/default.nix
@@ -3,12 +3,12 @@
 assert tetex == polytable.tetex;
 
 stdenv.mkDerivation {
-  name = "lhs2tex-1.12";
+  name = "lhs2tex-1.13pre3";
   builder = ./builder.sh;
   
   src = fetchurl {
-    url = http://www.informatik.uni-bonn.de/~loeh/lhs2tex/lhs2tex-1.12.tar.bz2;
-    md5 = "1bc982e96f19201aaf1c39c1d4b5e358";
+    url = "http://www.cs.uu.nl/~andres/lhs2tex/lhs2tex-1.13pre3.tar.bz2";
+    sha256 = "8ddc9bd150c20c33518d747fee95577ec8f587146532cda12b8034adc847826c";
   };
 
   buildInputs = [tetex ghc];
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 0e04bd8c01d94..f159e6a1a559f 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -124,7 +124,8 @@ rec {
   lib = library;
 
   library = import ../lib;
-  lib_unstable = import ../lib/default-unstable.nix;
+   # TODO remove
+   # lib_unstable = import ../lib/default-unstable.nix;
 
   # Return an attribute from the Nixpkgs configuration file, or
   # a default value if the attribute doesn't exist.
@@ -199,7 +200,7 @@ rec {
     args: with args.lib; with args;
     if ( builtins.isAttrs extraAttrs ) then builtins.throw "the argument extraAttrs needs to be a function beeing passed co, but attribute set passed "
     else
-    let co = lib_unstable.chooseOptionsByFlags { inherit args flagConfig optionals defaults collectExtraPhaseActions; }; in
+    let co = lib.chooseOptionsByFlags { inherit args flagConfig optionals defaults collectExtraPhaseActions; }; in
       args.stdenv.mkDerivation ( 
       {
         inherit (co) configureFlags buildInputs /*flags*/;
@@ -212,7 +213,7 @@ rec {
 			(import ../build-support/checker) 
 			opts config); in
 			(if (result=="") then x else
-			abort result)
+			abort ("Unknown option specified: " + result))
 		else x);
 
 	builderDefs = lib.sumArgs (import ./builder-defs.nix) {
@@ -280,7 +281,12 @@ rec {
       inherit stdenv curl;
     });
 
-  makeWrapper = ../build-support/make-wrapper/make-wrapper.sh;
+  makeSetupHook = script: runCommand "hook" {} ''
+    ensureDir $out/nix-support
+    cp ${script} $out/nix-support/setup-hook
+  '';
+
+  makeWrapper = makeSetupHook ../build-support/make-wrapper/make-wrapper.sh;
 
   # Run the shell command `buildCommand' to produce a store object
   # named `name'.  The attributes in `env' are added to the
@@ -608,6 +614,12 @@ rec {
      inherit fetchurl stdenv;
   };
 
+  mc = import ../tools/misc/mc {
+     inherit fetchurl stdenv pkgconfig ncurses;
+     inherit (gtkLibs) glib;
+     inherit (xlibs) libX11;
+  };
+
   mjpegtools = import ../tools/video/mjpegtools {
     inherit fetchurl stdenv libjpeg;
     inherit (xlibs) libX11;
@@ -806,7 +818,7 @@ rec {
   };
 
   which = import ../tools/system/which {
-    inherit fetchurl stdenv;
+    inherit fetchurl stdenv readline;
   };
 
   wv = import ../tools/misc/wv {
@@ -991,8 +1003,12 @@ rec {
     profiledCompiler = true;
   });
 
+  /* doesn't work yet
+
   # This new ghc stuff is under heavy development and might change ! 
 
+  # usage: see ghcPkgUtil.sh - use setup-new2 because of PATH_DELIMITER
+  # depreceated -> use functions defined in builderDefs
   ghcPkgUtil = runCommand "ghcPkgUtil-internal" 
      { ghcPkgUtil = ../development/libraries/haskell/generic/ghcPkgUtil.sh; }
      "mkdir -p $out/nix-support; cp $ghcPkgUtil \$out/nix-support/setup-hook;";
@@ -1000,9 +1016,8 @@ rec {
   ghcsAndLibs = 
     assert builtins ? listToAttrs;
     recurseIntoAttrs (import ../development/compilers/ghcs {
-      inherit ghcboot fetchurl recurseIntoAttrs perl gnum4 gmp readline stdenv;
+      inherit ghcboot fetchurl recurseIntoAttrs perl gnum4 gmp readline stdenv lib;
       inherit ghcPkgUtil;
-      lib = lib_unstable;
     });
 
   # creates ghc-X-wl wich adds the passed libraries to the env var GHC_PACKAGE_PATH
@@ -1011,6 +1026,22 @@ rec {
     inherit ghcPackagedLibs ghc name suffix libraries ghcPkgUtil stdenv;
   };
 
+  # this will change in the future 
+  ghc68_extra_libs =
+    ghc : let
+    deriv = name : goSrcDir : deps : 
+      let bd = builderDefs {
+          goSrcDir = "ghc-* /libraries";
+          src = ghc.extra_src;
+        } null; in
+      stdenv.mkDerivation rec {
+        inherit name;
+	builder = bd.writeScript (name + "-builder")
+		(bd.textClosure [builderDefs.haskellBuilderDefs]);
+      };
+    # using nvs to be able to use mtl-1.1.0.0 as name 
+  in lib.nvs "mtl-1.1.0.0" (deriv "mtl-1.1.0.0" "libraries/mtl" [ (__getAttr "base-3.0.1.0"  ghc.core_libs) ]);
+
   # the wrappers basically does one thing: It defines GHC_PACKAGE_PATH before calling ghc{i,-pkg}
   # So you can have different wrappers with different library combinations
   # So installing ghc libraries isn't done by nix-env -i package but by adding the lib to the libraries list below
@@ -1018,27 +1049,31 @@ rec {
     let ghc = ghcsAndLibs.ghc68.ghc; in
     createGhcWrapper rec {
       ghcPackagedLibs = true;
-      name = "ghc68_wrapper";
-      suffix = "68wrapper";
-      libraries = map ( a : __getAttr a ghcsAndLibs.ghc68.core_libs ) 
-        [ "old-locale-1.0" "old-time-1.0" "filepath-1.0" "directory-1.0" "array-0.1" "containers-0.1" 
-          "hpc-0.5" "bytestring-0.9" "pretty-1.0" "packedstring-0.1" "template-haskell-0.1" 
-          "unix-2.0" "process-1.0" "readline-1.0" "Cabal-1.2.0" "random-1.0" "haskell98-1.0" "ghc-6.8.0.20071004"
-          "array-0.1" "bytestring-0.9" "containers-0.1" "directory-1.0" "filepath-1.0"
-          "ghc-6.8.0.20071004" "haskell98-1.0" "hpc-0.5" "old-locale-1.0" "old-time-1.0" 
-          "packedstring-0.1" "pretty-1.0" "process-1.0" "random-1.0"
-          "readline-1.0" "rts-1.0" "template-haskell-0.1" "unix-2.0"
-        ];
+      name = "ghc${ghc.version}_wrapper";
+      suffix = "${ghc.version}wrapper";
+      libraries = map ( a : __getAttr a ghcsAndLibs.ghc68.core_libs ) [ 
+            "old-locale-1.0.0.0" "old-time-1.0.0.0" "filepath-1.1.0.0" "directory-1.0.0.0" "array-0.1.0.0" "containers-0.1.0.1" 
+            "hpc-0.5.0.0" "bytestring-0.9.0.1" "pretty-1.0.0.0" "packedstring-0.1.0.0" "template-haskell-2.2.0.0" 
+            "unix-2.3.0.0" "process-1.0.0.0" "readline-1.0.1.0" "Cabal-1.2.3.0" "random-1.0.0.0" "haskell98-1.0.1.0" "ghc-${ghc.version}"
+            "array-0.1.0.0" "bytestring-0.9.0.1" "containers-0.1.0.1" "directory-1.0.0.0" "filepath-1.1.0.0"
+            "ghc-${ghc.version}" "haskell98-1.0.1.0" "hpc-0.5.0.0" "old-locale-1.0.0.0" "old-time-1.0.0.0" 
+            "packedstring-0.1.0.0" "pretty-1.0.0.0" "process-1.0.0.0" "random-1.0.0.0"
+            "readline-1.0.1.0" "rts-1.0" "unix-2.3.0.0" "base-3.0.1.0"
+          ] ++ map ( a : __getAttr a (ghc68_extra_libs ghcsAndLibs.ghc68 ) ) [
+            "mtl-1.1.0.0"
+          ];
         # (flatten ghcsAndLibs.ghc68.core_libs);
       inherit ghc;
   };
 
+  */
+
   # ghc66boot = import ../development/compilers/ghc-6.6-boot {
   #  inherit fetchurl stdenv perl readline;
   #  m4 = gnum4;
   #};
 
-  ghc = ghc661;
+  ghc = ghc68;
 
   ghc68 = import ../development/compilers/ghc-6.8 {
     inherit fetchurl stdenv readline perl gmp ncurses;
@@ -1078,7 +1113,8 @@ rec {
   */
 
   helium = import ../development/compilers/helium {
-    inherit fetchurl stdenv ghc;
+    inherit fetchurl stdenv;
+    ghc = ghc661;
   };
 
   #TODO add packages http://cvs.haskell.org/Hugs/downloads/2006-09/packages/ and test
@@ -1093,6 +1129,12 @@ rec {
       inherit fetchurl stdenv;
     };
 
+  jdk5 =
+    assert system == "i686-linux";
+    import ../development/compilers/jdk/default-5.nix {
+      inherit fetchurl stdenv unzip;
+    };
+
   jdk       = jdkdistro true  false;
   jre       = jdkdistro false false;
 
@@ -1221,6 +1263,10 @@ rec {
     inherit (xlibs) libX11 libXau libXt;
   };
 
+  erlang = import ../development/interpreters/erlang {
+    inherit fetchurl perl gnum4 ncurses openssl stdenv;
+  };
+
   guile = import ../development/interpreters/guile {
     inherit fetchurl stdenv ncurses readline libtool gmp;
   };
@@ -1256,8 +1302,7 @@ rec {
   # perhaps this can be done setting php_value in apache don't have time to investigate any further ?
   # This expression is a quick hack now. But perhaps it helps you adding the configuration flags you need?
   php = (import ../development/interpreters/php_configurable) {
-   inherit mkDerivationByConfiguration stdenv mysql;
-   lib = lib_unstable;
+   inherit mkDerivationByConfiguration stdenv mysql lib;
    inherit fetchurl flex bison apacheHttpd; # gettext;
    inherit libxml2;
    flags = [ "xdebug" "mysql" "mysqli" "pdo_mysql" "libxml2" "apxs2" ];
@@ -1342,6 +1387,10 @@ rec {
   ### DEVELOPMENT / TOOLS
 
 
+  alex = import ../development/tools/parsing/alex {
+    inherit cabal perl;
+  };
+
   antlr = import ../development/tools/parsing/antlr/antlr-2.7.6.nix {
     inherit fetchurl stdenv jre;
   };
@@ -1452,8 +1501,16 @@ rec {
     inherit fetchurl stdenv;
   };
 
-  happy = import ../development/tools/parsing/happy {
-    inherit fetchurl stdenv perl ghc;
+  haddock = import ../development/tools/documentation/haddock {
+    inherit cabal;
+  };
+
+  # happy = import ../development/tools/parsing/happy {
+  #   inherit fetchurl stdenv perl ghc;
+  # };
+
+  happy = import ../development/tools/parsing/happy/happy-1.17.nix {
+    inherit cabal perl;
   };
 
   help2man = import ../development/tools/misc/help2man {
@@ -1564,9 +1621,7 @@ rec {
   };
 
   uuagc = import ../development/tools/haskell/uuagc {
-    inherit fetchurl stdenv;
-    ghc = ghc66;
-    uulib = uulib66;
+    inherit cabal uulib;
   };
 
   gdb = import ../development/tools/misc/gdb {
@@ -1784,10 +1839,9 @@ rec {
 
 
   fltk20 = (import ../development/libraries/fltk) {
-    inherit mkDerivationByConfiguration x11;
+    inherit mkDerivationByConfiguration x11 lib;
     inherit fetchurl stdenv mesa mesaHeaders libpng libjpeg zlib ;
     flags = [ "useNixLibs" "threads" "shared" "gl" ];
-    lib = lib_unstable;
   };
 
   cfitsio = import ../development/libraries/cfitsio {
@@ -1822,8 +1876,7 @@ rec {
   };
 
   geos = import ../development/libraries/geos {
-    lib = lib_unstable;
-    inherit fetchurl fetchsvn stdenv mkDerivationByConfiguration autoconf automake libtool swig which;
+    inherit fetchurl fetchsvn stdenv mkDerivationByConfiguration autoconf automake libtool swig which lib;
     use_svn = stdenv.system == "x86_64-linux";
     python = python;
     # optional features:  
@@ -1848,6 +1901,11 @@ rec {
     };
   };
 
+  glew = import ../development/libraries/glew {
+    inherit fetchurl stdenv mesa x11 libtool;
+    inherit (xlibs) libXmu libXi;
+  };
+
   glibc = useFromStdenv (stdenv ? glibc) stdenv.glibc
     (import ../development/libraries/glibc-2.7 {
       inherit fetchurl stdenv kernelHeaders;
@@ -2078,8 +2136,7 @@ rec {
   } null;
 
   libdv = import ../development/libraries/libdv {
-    lib = lib_unstable;
-    inherit fetchurl stdenv mkDerivationByConfiguration;
+    inherit fetchurl stdenv lib mkDerivationByConfiguration;
   };
 
   libdrm = import ../development/libraries/libdrm {
@@ -2661,25 +2718,59 @@ rec {
 
   ### DEVELOPMENT / LIBRARIES / HASKELL
 
+  binary = import ../development/libraries/haskell/binary {
+    inherit cabal; 
+  };
+
+  # cabal is a utility function to build cabal-based
+  # Haskell packages
+  cabal68 = import ../development/libraries/haskell/cabal/cabal.nix {
+    inherit stdenv fetchurl;
+    ghc = ghc68;
+  };
+  cabal = cabal68;
+
+  Crypto = import ../development/libraries/haskell/Crypto {
+    inherit cabal;
+  };
+
   gtk2hs = import ../development/libraries/haskell/gtk2hs {
     inherit pkgconfig stdenv fetchurl cairo;
     inherit (gnome) gtk glib GConf libglade libgtkhtml gtkhtml;
     ghc = ghc661;
   };
 
-  uulib64 = import ../development/libraries/haskell/uulib { # !!! remove?
-    inherit stdenv fetchurl ghc;
+  pcreLight = import ../development/libraries/haskell/pcre-light {
+    inherit cabal pcre;
   };
 
-  uulib66 = import ../development/libraries/haskell/uulib-ghc-6.6 { # !!! ugh
-    inherit stdenv fetchurl autoconf;
-    ghc = ghc66;
+  uulib = import ../development/libraries/haskell/uulib {
+    inherit cabal;
   };
 
   wxHaskell = import ../development/libraries/haskell/wxHaskell {
-    inherit stdenv fetchurl unzip ghc wxGTK;
+    inherit stdenv fetchurl unzip wxGTK;
+    ghc = ghc661;
+  };
+
+  # wxHaskell68 = lowPrio (appendToName "ghc68" (import ../development/libraries/haskell/wxHaskell {
+  #   inherit stdenv fetchurl unzip wxGTK;
+  #   ghc = ghc68;
+  # }));
+
+  X11 = import ../development/libraries/haskell/X11 {
+    inherit cabal;
+    inherit (xlibs) libX11 libXinerama libXext;
+    xineramaSupport = true;
   };
 
+  vty = import ../development/libraries/haskell/vty {
+    inherit cabal;
+  };
+
+  zlibHaskell = import ../development/libraries/haskell/zlib {
+    inherit cabal zlib;
+  };
 
   ### DEVELOPMENT / PERL MODULES
 
@@ -2980,10 +3071,18 @@ rec {
     inherit fetchurl stdenv ;
   };
 
+  ejabberd = import ../servers/xmpp/ejabberd {
+    inherit fetchurl stdenv expat erlang zlib openssl;
+  };
+
   ircdHybrid = import ../servers/irc/ircd-hybrid {
 		inherit fetchurl stdenv openssl zlib;
 	};
 
+  jboss = import ../servers/http/jboss {
+    inherit fetchurl stdenv jdk5 jdk;
+  };
+
   jetty = import ../servers/http/jetty {
     inherit fetchurl stdenv unzip;
   };
@@ -2992,6 +3091,10 @@ rec {
     inherit fetchurl stdenv apacheHttpd python;
   };
 
+  tomcat_connectors = import ../servers/http/apache-modules/tomcat-connectors {
+    inherit fetchurl stdenv apacheHttpd jdk;
+  };
+
   mysql4 = import ../servers/sql/mysql {
     inherit fetchurl stdenv ncurses zlib perl;
     ps = procps; /* !!! Linux only */
@@ -3029,8 +3132,7 @@ rec {
   };
 
   squid = import ../servers/squid {
-    inherit fetchurl stdenv mkDerivationByConfiguration perl;
-    lib = lib_unstable;
+    inherit fetchurl stdenv mkDerivationByConfiguration perl lib;
   };
 
   tomcat5 = import ../servers/http/tomcat {
@@ -3670,6 +3772,10 @@ rec {
     inherit fetchurl stdenv unzip;
   };
 
+  bazaar = import ../applications/version-management/bazaar {
+    inherit fetchurl stdenv python makeWrapper;
+  };
+
   # commented out because it's using the new configuration style proposal which is unstable
   #biew = import ../applications/misc/biew {
   #  inherit lib stdenv fetchurl ncurses;
@@ -3682,10 +3788,9 @@ rec {
     openal = openalSoft;
   };
   blender = import ../applications/misc/blender {
-    inherit cmake mesa gettext freetype SDL libtiff fetchurl glibc scons x11
+    inherit cmake mesa gettext freetype SDL libtiff fetchurl glibc scons x11 lib
       libjpeg libpng zlib stdenv /* smpeg  sdl */;
     inherit (xlibs) inputproto libXi;
-    lib = lib_unstable;
     python = builtins.getAttr "2.5" python_alts;
     freealut = freealut_soft;
     openal = openalSoft;
@@ -3706,6 +3811,10 @@ rec {
     inherit fetchurl stdenv pkgconfig bmp;
   };
 
+  bvi = import ../applications/editors/bvi {
+    inherit fetchurl stdenv ncurses;
+  };
+
   cdparanoiaIII = import ../applications/audio/cdparanoia {
     inherit fetchurl stdenv;
   };
@@ -3800,7 +3909,7 @@ rec {
   };
 
   cvs2svn = import ../applications/version-management/cvs2svn {
-    inherit fetchurl stdenv python bsddb3 makeWrapper;
+    inherit fetchurl stdenv python makeWrapper;
   };
 
   d4x = import ../applications/misc/d4x {
@@ -3809,7 +3918,8 @@ rec {
   };
   
   darcs = import ../applications/version-management/darcs {
-    inherit fetchurl stdenv ghc zlib ncurses curl;
+    inherit fetchurl stdenv zlib ncurses curl;
+    ghc = ghc661;
   };
 
   dia = import ../applications/graphics/dia {
@@ -4479,11 +4589,10 @@ rec {
   };
 
   vim_configurable = import ../applications/editors/vim/configurable.nix {
-    inherit fetchurl stdenv ncurses pkgconfig mkDerivationByConfiguration;
+    inherit fetchurl stdenv ncurses pkgconfig mkDerivationByConfiguration lib;
     inherit (xlibs) libX11 libXext libSM libXpm
         libXt libXaw libXau libXmu;
     inherit (gtkLibs) glib gtk;
-    lib = lib_unstable;
     features = "huge"; # one of  tiny, small, normal, big or huge
     # optional features by passing
     # python 
@@ -4582,6 +4691,11 @@ rec {
     stdenv = overrideGCC stdenv gcc34; # due to problems with gcc 4.x
   };
 
+  xmonad = import ../applications/window-managers/xmonad {
+    inherit stdenv fetchurl ghc X11;
+    inherit (xlibs) xmessage;
+  };
+
   xpdf = import ../applications/misc/xpdf {
     inherit fetchurl stdenv x11 freetype t1lib;
     motif = lesstif;
@@ -4633,11 +4747,10 @@ rec {
   # doesn't compile yet - in case someone else want's to continue .. 
   /*
   qgis_svn = import ../applications/misc/qgis_svn {
-    lib = lib_unstable;
-    inherit mkDerivationByConfiguration fetchsvn flex
+    inherit mkDerivationByConfiguration fetchsvn flex lib
             ncurses fetchurl perl cmake gdal geos proj x11
             gsl libpng zlib stdenv
-            sqlite glibc fontconfig freetype;
+            sqlite glibc fontconfig freetype / * use libc from stdenv ? - to lazy now - Marc * /;
     inherit (xlibs) libSM libXcursor libXinerama libXrandr libXrender;
     inherit (xorg) libICE;
     qt = qt4;
@@ -4722,6 +4835,17 @@ rec {
     inherit fetchurl stdenv SDL zlib mpeg2dec;
   };
 
+  # You still can override by passing more arguments.
+  spaceOrbitFun = lib.sumArgs (selectVersion ../games/orbit ) {
+    inherit fetchurl stdenv builderDefs 
+      mesa freeglut;
+    inherit (gnome) esound;
+    inherit (xlibs) libXt libX11 libXmu libXi libXext;
+    version = "1.01";
+  };
+
+  spaceOrbit = spaceOrbitFun null;
+
   /*tpm = import ../games/thePenguinMachine {
     inherit stdenv fetchurl pil pygame SDL; 
     python24 = python;
diff --git a/pkgs/top-level/build-for-release.nix b/pkgs/top-level/build-for-release.nix
index e5f8e3a466cf1..6787f91a07206 100644
--- a/pkgs/top-level/build-for-release.nix
+++ b/pkgs/top-level/build-for-release.nix
@@ -5,7 +5,6 @@ let {
   i686LinuxPkgs = {inherit (allPackages {system = "i686-linux";})
     aterm
     nixUnstable
-    pan
     subversion
     ;
   };
@@ -14,7 +13,6 @@ let {
     aterm
     gcc
     nixUnstable
-    pan
     subversion
     ;    
   };
diff --git a/pkgs/top-level/builder-defs.nix b/pkgs/top-level/builder-defs.nix
index aa53c9ba15750..af89fd037028b 100644
--- a/pkgs/top-level/builder-defs.nix
+++ b/pkgs/top-level/builder-defs.nix
@@ -20,7 +20,12 @@ args: with args; with stringsWithDeps; with lib;
 
 		else (abort "unknown archive type : ${s}"));
 
+	pathDelimiter = if args ? pathDelimiter then args.pathDelimiter else
+		if __currentSystem == "i686-mingw" then ";" else ":";
+
 	defAddToSearchPath = FullDepEntry ("
+		export PATH_DELIMITER='${pathDelimiter}';
+
 		addToSearchPathWithCustomDelimiter() {
 			local delimiter=\$1
 			local varName=\$2
@@ -40,7 +45,7 @@ args: with args; with stringsWithDeps; with lib;
 		{
 			addToSearchPathWithCustomDelimiter \"\${PATH_DELIMITER}\" \"\$@\"
 		}
-	") [defNest];
+	") ["defNest"];
 
 	defNest = noDepEntry ("
 		nestingLevel=0
@@ -95,7 +100,7 @@ args: with args; with stringsWithDeps; with lib;
 		prefix=${if args ? prefix then (toString args.prefix) else "\$out"}
 
 		"
-	else "")) [defNest defAddToSearchPath];
+	else "")) ["defNest" "defAddToSearchPath"];
 		
 	addInputs = FullDepEntry ("
 		# Recursively find all build inputs.
@@ -161,7 +166,7 @@ args: with args; with stringsWithDeps; with lib;
 		fi
 
 		PATH=\$_PATH\${_PATH:+:}\$PATH
-	") [minInit];
+	") ["minInit"];
 	
 	defEnsureDir = FullDepEntry ("
 		# Ensure that the given directories exists.
@@ -171,7 +176,7 @@ args: with args; with stringsWithDeps; with lib;
 			if ! test -x \"\$dir\"; then mkdir -p \"\$dir\"; fi
 		    done
 		}
-	") [minInit];
+	") ["minInit"];
 
 	toSrcDir = s : FullDepEntry ((if (archiveType s) == "tar" then "
 		tar xvf '${s}'
@@ -200,11 +205,11 @@ args: with args; with stringsWithDeps; with lib;
 		cd \$(basename ${s} .bz2)
 	" else (abort "unknown archive type : ${s}"))+
 		(if args ? goSrcDir then args.goSrcDir else "")
-	) [minInit];
+	) ["minInit"];
 
 	doConfigure = FullDepEntry ("
 		./configure --prefix=\"\$prefix\" ${toString configureFlags}
-	") [minInit addInputs doUnpack];
+	") ["minInit" "addInputs" "doUnpack"];
 
 	doAutotools = FullDepEntry ("
 		mkdir -p config
@@ -214,21 +219,21 @@ args: with args; with stringsWithDeps; with lib;
 		autoheader || true; 
 		automake --add-missing --copy
 		autoconf
-	")[minInit addInputs doUnpack];
+	")["minInit" "addInputs" "doUnpack"];
 
 	doMake = FullDepEntry ("	
 		make ${toString makeFlags}
-	") [minInit addInputs doUnpack];
+	") ["minInit" "addInputs" "doUnpack"];
 
 	doUnpack = toSrcDir (toString src);
 
 	installPythonPackage = FullDepEntry ("
 		python setup.py install --prefix=\"\$prefix\" 
-		") [minInit addInputs doUnpack];
+		") ["minInit" "addInputs" "doUnpack"];
 
 	doMakeInstall = FullDepEntry ("
 		make ${toString (getAttr ["makeFlags"] "" args)} "+
-			"${toString (getAttr ["installFlags"] "" args)} install") [doMake];
+			"${toString (getAttr ["installFlags"] "" args)} install") ["doMake"];
 
 	doForceShare = FullDepEntry (" 
 		ensureDir \"\$prefix/share\"
@@ -238,7 +243,7 @@ args: with args; with stringsWithDeps; with lib;
 				ln -sv share/\$d \"\$prefix\"
 			fi;
 		done;
-	") [minInit defEnsureDir];
+	") ["minInit" "defEnsureDir"];
 
 	doDump = n: noDepEntry "echo Dump number ${n}; set";
 
@@ -250,7 +255,7 @@ args: with args; with stringsWithDeps; with lib;
 
 	doPatch = FullDepEntry (concatStringsSep ";"
 		(map toPatchCommand patches)
-	) [minInit doUnpack];
+	) ["minInit" "doUnpack"];
 
 	envAdderInner = s: x: if x==null then s else y: 
 		a: envAdderInner (s+"echo export ${x}='\"'\"\$${x}:${y}\";'\"'\n") a;
@@ -268,12 +273,12 @@ args: with args; with stringsWithDeps; with lib;
 		(${envAdderList env}
 		echo '\"'\"${cmd}-orig\"'\"' '\"'\\\$@'\"' \n)  > \"${cmd}\"";
 
-	doWrap = cmd: FullDepEntry (wrapEnv cmd (getAttr ["wrappedEnv"] [] args)) [minInit];
+	doWrap = cmd: FullDepEntry (wrapEnv cmd (getAttr ["wrappedEnv"] [] args)) ["minInit"];
 
 	doPropagate = FullDepEntry ("
 		ensureDir \$out/nix-support
 		echo '${toString (getAttr ["propagatedBuildInputs"] [] args)}' >\$out/nix-support/propagated-build-inputs
-	") [minInit defEnsureDir];
+	") ["minInit" "defEnsureDir"];
 
 	/*debug = x:(__trace x x);
 	debugX = x:(__trace (__toXML x) x);*/
@@ -283,7 +288,7 @@ args: with args; with stringsWithDeps; with lib;
 	replaceScripts = l:(concatStringsSep "\n" (pairMap replaceInScript l));
 	doReplaceScripts = FullDepEntry (replaceScripts (getAttr ["shellReplacements"] [] args)) [minInit];
 	makeNest = x:(if x==defNest.text then x else "startNest\n" + x + "\nstopNest\n");
-	textClosure = textClosureMap makeNest;
+	textClosure = textClosureMapOveridable makeNest;
 
 	inherit noDepEntry FullDepEntry PackEntry;
 
@@ -317,4 +322,69 @@ args: with args; with stringsWithDeps; with lib;
 
 	surroundWithCommands = x : before : after : {deps=x.deps; text = before + "\n" +
 		x.text + "\n" + after ;};
+
+
+        # some haskell stuff  - untested!
+        # --------------------------------------------------------
+        # creates a setup hook
+        # adding the package database 
+        # nix-support/package.conf to GHC_PACKAGE_PATH
+        # if not already contained
+        # using nix-support because user does'nt want to have it in it's
+        # nix-profile I think?
+        defSetupHookRegisteringPackageDatabase = noDepEntry (
+          "\nsetupHookRegisteringPackageDatabase(){" +
+          "\n  ensureDir $out/nix-support;" +
+          "\n  if test -n \"$1\"; then" +
+          "\n    local pkgdb=$1" +
+          "\n  else" +
+          "\n    local pkgdb=$out/nix-support/package.conf" +
+          "\n  fi" +
+          "\n  cat >> $out/nix-support/setup-hook << EOF" +
+          "\n    " +
+          "\n    echo \$GHC_PACKAGE_PATH | grep -l $pkgdb &> /dev/null || \" "+
+          "\n      export GHC_PACKAGE_PATH=\$GHC_PACKAGE_PATH\${GHC_PACKAGE_PATH:+$PATH_DELIMITER}$pkgdb;" +
+          "\nEOF" +
+          "\n}");
+
+        # Either rungghc or compile setup.hs 
+        # / which one is better ? runghc had some trouble with ghc-6.6.1
+        defCabalSetupCmd = noDepEntry "
+          CABAL_SETUP=\"runghc setup.hs\"
+        ";
+        
+        # create an empty package database in which the new library can be registered. 
+        defCreateEmptyPackageDatabaseAndSetupHook = FullDepEntry "
+          createEmptyPackageDatabaseAndSetupHook(){
+            ensureDir $out/nix-support;
+            PACKAGE_DB=$out/nix-support/package.conf;
+            echo '[]' > \"$PACKAGE_DB\";
+            setupHookRegisteringPackageDatabase
+        }" [defSetupHookRegisteringPackageDatabase];
+
+        # Cabal does only support --user ($HOME/.ghc/** ) and --global (/nix/store/*-ghc/lib/...) 
+        # But we need kind of --custom=my-package-db
+        # by accident cabal does support using multiple databases passed by GHC_PACKAGE_PATH
+        # 
+        # Options:
+        # 1) create a local package db containing all dependencies
+        # 2) create a single db file for each package merging them using GHC_PACKAGE_PATH=db1:db2 
+        # (no trailing : which would mean add global and user db)
+        # I prefer 2) (Marc Weber) so the most convinient way is
+        # using ./setup copy to install
+        # and   ./setup register --gen-script to install to our local database 
+        # after replacing /usr/lib etc with our pure $out path
+        cabalBuild = FullDepEntry 
+          (if (args ? subdir) then "cd ${args.subdir}" else "")+ "
+          createEmptyPackageDatabaseAndSetupHook
+          ghc --make setup.hs -o setup
+          \$CABAL_SETUP configure
+          \$CABAL_SETUP build
+          \$CABAL_SETUP copy --dest-dir=\$out
+          \$CABAL_SETUP register --gen-script
+          sed -e 's=/usr/local/lib=\$out=g' \\
+              -i register.sh
+          GHC_PACKAGE_PATH=\$PACKAGE_DB ./register.sh
+        " [defCreateEmptyPackageDatabaseAndSetupHook defCabalSetupCmd];
+
 }) // args
diff --git a/pkgs/top-level/template-composing+config.nix b/pkgs/top-level/template-composing+config.nix
index df751f693f238..7ff4f3f9d5024 100644
--- a/pkgs/top-level/template-composing+config.nix
+++ b/pkgs/top-level/template-composing+config.nix
@@ -1,4 +1,4 @@
-args : with args; with builderDefs (args // {
+args : with args; let localDefs = builderDefs (args // {
 		src = /* put a fetchurl here */
 		(abort "Specify source");
 		useConfig = true;
@@ -10,10 +10,11 @@ args : with args; with builderDefs (args // {
 		configFlags = [
 		];
 	}) null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
 	name = "${(abort "Specify name")}"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [(abort "Check phases") doMakeInstall doForceShare doPropagate]);
+		(textClosure localDefs [(abort "Check phases") doMakeInstall doForceShare doPropagate]);
 	meta = {
 		description = "
 	${(abort "Specify description")}
diff --git a/pkgs/top-level/template-composing-builder.nix b/pkgs/top-level/template-composing-builder.nix
index 8117b156879b1..276bdc762dcac 100644
--- a/pkgs/top-level/template-composing-builder.nix
+++ b/pkgs/top-level/template-composing-builder.nix
@@ -1,14 +1,16 @@
-args : with args;
-	with builderDefs {
+args : with args; with builderDefs {src="";} null;
+	let localDefs = builderDefs {
 		src = /* put a fetchurl here */
 
 		buildInputs = [];
 		configureFlags = [];
 	} null; /* null is a terminator for sumArgs */
+	in with localDefs;
 stdenv.mkDerivation rec {
-	name = "${abort "Specify name"}";
+	name = "${abort "Specify name"}-"+version;
 	builder = writeScript (name + "-builder")
-		(textClosure [(abort "Specify phases - defined here or in builderDefs") doForceShare doPropagate]);
+		(textClosure localDefs 
+			[(abort "Specify phases - defined here or in builderDefs") doForceShare doPropagate]);
 	meta = {
 		description = "
 		${abort "Write a description"}