@@ -1,165 +0,0 @@
1−{ pkgs, stdenv } :
2−
3−let inherit (pkgs) stdenv runCommand perl lib;
4−
5−in
6−
7−{
8− /*
9− Usage example creating a derivation installing ruby, sup and a lib:
10−
11− packageOverrides = {
12− rubyCollection = collection {
13− name = "ruby";
14− list = let l = rubyPackages; in
15− [ pkgs.ruby l.chronic l.sup ];
16− };
17− }
18− */
19− collection = {list, name} : runCommand "collection-${name}" {} ''
20− mkdir -p $out/nix-support
21− printWords ${builtins.toString list} > $out/nix-support/propagated-user-env-packages
22− '';
23−
24− /* creates a derivation symlinking references C/C++ libs into one include and lib directory called $out/cdt-envs/${name}
25− then you can
26− ln -s ~/.nix-profile/cdt-envs/name ./nix-deps
27− and add .nix-deps/{libs,includes} to IDE's such as Eclipse/ Netbeans etc.
28− To update replace library versions just replace the symlink
29− */
30− cdtEnv = { name, buildInputs }:
31− stdenv.mkDerivation {
32− name = "cdt-env-${name}";
33− inherit buildInputs;
34− phases = "installPhase";
35− installPhase = ''
36− set -x
37− # requires bash4
38− PATH=$PATH:${pkgs.pkgconfig}/bin
39−
40− perlScript=$(dirname $(dirname ${builtins.getEnv "NIXPKGS_ALL"}))/build-support/buildenv/builder.pl
41− # now collect includes and lib paths
42−
43− # probably the nix hooks work best, so reuse them by reading NIX_CFLAGS_COMPILE and NIX_LDFLAGS
44−
45− PKG_CONFIG_KNOWN_PACKAGES=$(pkg-config --list-all | sed 's/ .*//')
46−
47− declare -A INCLUDE_PATHS
48− declare -A LIB_PATHS
49− declare -A LIBS
50− declare -A CFLAGS_OTHER
51−
52− PKG_CONFIG_LIBS="$(pkg-config --libs $PKG_CONFIG_KNOWN_PACKAGES)"
53− PKG_CONFIG_CFLAGS="$(pkg-config --cflags $PKG_CONFIG_KNOWN_PACKAGES)"
54−
55− for i in $NIX_CFLAGS_COMPILE $PKG_CONFIG_CFLAGS; do
56− echo i is $i
57− case $i in
58− -I*) INCLUDE_PATHS["''${i/-I/}"]= ;;
59− *) CFLAGS_OTHER["''${i}"]= ;;
60− esac
61− echo list is now ''${!INCLUDE_PATHS[@]}
62− done
63−
64− for i in $NIX_LDFLAGS $PKG_CONFIG_LIBS; do
65− case $i in
66− -L*)
67− LIB_PATHS["''${i/-L/}"]= ;;
68− esac
69− done
70−
71− for i in $NIX_LDFLAGS $PKG_CONFIG_LIBS; do
72− echo chekcing $i
73− case $i in
74− -l*) LIBS["''${i}"]= ;;
75− esac;
76− done
77−
78− # build output env
79−
80− target="$out/cdt-envs/${name}"
81−
82− link(){
83− echo "link !!!!"
84− echo $1
85− echo $2
86− (
87− export out="$1"
88− export paths="$2"
89−
90− export ignoreCollisions=1
91− export manifest=
92− export pathsToLink=/
93− ${perl}/bin/perl $perlScript
94− )
95− }
96−
97− mkdir -p $target/{include,lib}
98− link $target/lib "$(echo "''${!LIB_PATHS[@]}")"
99− link $target/include "$(echo "''${!INCLUDE_PATHS[@]}")"
100− echo "''${!LIBS[@]}" > $target/libs
101− echo "''${!CFLAGS_OTHER[@]}" > $target/cflags-other
102− echo "''${PKG_CONFIG_PATH}" > $target/PKG_CONFIG_PATH
103− echo "''${PATH}" > $target/PATH
104− '';
105− };
106−
107−
108− # build a debug version of a package
109− debugVersion = pkg: lib.overrideDerivation pkg (attrs: {
110−
111− prePhases = ["debugPhase"] ++ lib.optionals (attrs ? prePhases) attrs.prePhases;
112− postPhases = ["objectsPhase"] ++ lib.optionals (attrs ? postPhases) attrs.postPhases;
113−
114− dontStrip = true;
115−
116− CFLAGS="-ggdb -O0";
117− CXXFLAGS="-ggdb -O0";
118−
119− debugPhase = ''
120− s=$out/src
121− mkdir -p $s; cd $s;
122− export TMP=$s
123− export TEMP=$s
124−
125− for var in CFLAGS CXXFLAGS NIX_CFLAGS_COMPILE; do
126− declare -x "$var=''${!var} -ggdb -O0"
127− done
128− echo "file should tell that executable has not been stripped"
129− '';
130−
131− objectsPhase = ''
132− cd $out/src
133− find . -name "*.o" -exec rm {} \;
134− '';
135− });
136−
137− # build an optimized ersion of a package but with symbols and source
138− symbolsVersion = pkg: lib.overrideDerivation pkg (attrs: {
139−
140− prePhases = ["debugPhase"] ++ lib.optionals (attrs ? prePhases) attrs.prePhases;
141− postPhases = ["objectsPhase"] ++ lib.optionals (attrs ? postPhases) attrs.postPhases;
142−
143− dontStrip = true;
144−
145− CFLAGS="-g -O2";
146− CXXFLAGS="-g -O2";
147−
148− debugPhase = ''
149− s=$out/src
150− mkdir -p $s; cd $s;
151− export TMP=$s
152− export TEMP=$s
153−
154− for var in CFLAGS CXXFLAGS NIX_CFLAGS_COMPILE; do
155− declare -x "$var=''${!var} -g -O2"
156− done
157− echo "file should tell that executable has not been stripped"
158− '';
159−
160− objectsPhase = ''
161− cd $out/src
162− find . -name "*.o" -exec rm {} \;
163− '';
164− });
165−}