summary refs log tree commit diff
path: root/pkgs/top-level/builder-defs.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/top-level/builder-defs.nix')
-rw-r--r--pkgs/top-level/builder-defs.nix100
1 files changed, 85 insertions, 15 deletions
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