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