##// END OF EJS Templates
nix: expose python
marcink -
r4760:e29f166c python3
parent child Browse files
Show More
@@ -1,292 +1,295 b''
1 1 # Nix environment for the community edition
2 2 #
3 3 # This shall be as lean as possible, just producing the enterprise-ce
4 4 # derivation. For advanced tweaks to pimp up the development environment we use
5 5 # "shell.nix" so that it does not have to clutter this file.
6 6 #
7 7 # Configuration, set values in "~/.nixpkgs/config.nix".
8 8 # example
9 9 # {
10 10 # # Thoughts on how to configure the dev environment
11 11 # rc = {
12 12 # codeInternalUrl = "https://usr:token@code.rhodecode.com/internal";
13 13 # sources = {
14 14 # rhodecode-vcsserver = "/home/user/work/rhodecode-vcsserver";
15 15 # rhodecode-enterprise-ce = "/home/user/work/rhodecode-enterprise-ce";
16 16 # rhodecode-enterprise-ee = "/home/user/work/rhodecode-enterprise-ee";
17 17 # };
18 18 # };
19 19 # }
20 20
21 21 args@
22 22 { system ? builtins.currentSystem
23 23 , pythonPackages ? "python27Packages"
24 24 , pythonExternalOverrides ? self: super: {}
25 25 , doCheck ? false
26 26 , ...
27 27 }:
28 28
29 29 let
30 30 pkgs_ = args.pkgs or (import <nixpkgs> { inherit system; });
31 31 in
32 32
33 33 let
34 34 pkgs = import <nixpkgs> {
35 35 overlays = [
36 36 (import ./pkgs/overlays.nix)
37 37 ];
38 38 inherit
39 39 (pkgs_)
40 40 system;
41 41 };
42 42
43 43 # Works with the new python-packages, still can fallback to the old
44 44 # variant.
45 45 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
46 46 self: basePythonPackages.override (a: { inherit self; }));
47 47
48 48 # Evaluates to the last segment of a file system path.
49 49 basename = path: with pkgs.lib; last (splitString "/" path);
50 50 startsWith = prefix: full: let
51 51 actualPrefix = builtins.substring 0 (builtins.stringLength prefix) full;
52 52 in actualPrefix == prefix;
53 53
54 54 # source code filter used as arugment to builtins.filterSource.
55 55 src-filter = path: type: with pkgs.lib;
56 56 let
57 57 ext = last (splitString "." path);
58 58 parts = last (splitString "/" path);
59 59 in
60 60 !builtins.elem (basename path) [
61 61 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
62 62 "node_modules" "node_binaries"
63 63 "build" "data" "result" "tmp"] &&
64 64 !builtins.elem ext ["egg-info" "pyc"] &&
65 65 !startsWith "result" (basename path);
66 66
67 67 sources =
68 68 let
69 69 inherit
70 70 (pkgs.lib)
71 71 all
72 72 isString
73 73 attrValues;
74 74
75 75 sourcesConfig = pkgs.config.rc.sources or {};
76 76 in
77 77 # Ensure that sources are configured as strings. Using a path
78 78 # would result in a copy into the nix store.
79 79 assert all isString (attrValues sourcesConfig);
80 80 sourcesConfig;
81 81
82 82 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
83 83 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
84 84
85 85 nodeEnv = import ./pkgs/node-default.nix {
86 86 inherit
87 87 pkgs
88 88 system;
89 89 };
90 90 nodeDependencies = nodeEnv.shell.nodeDependencies;
91 91
92 92 rhodecode-testdata-src = sources.rhodecode-testdata or (
93 93 pkgs.fetchhg {
94 94 url = "https://code.rhodecode.com/upstream/rc_testdata";
95 95 rev = "v0.10.0";
96 96 sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0";
97 97 });
98 98
99 99 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
100 100 inherit
101 101 doCheck
102 102 pkgs
103 103 pythonPackages;
104 104 };
105 105
106 106 pythonLocalOverrides = self: super: {
107 107 rhodecode-enterprise-ce =
108 108 let
109 109 linkNodePackages = ''
110 110 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
111 111
112 112 echo "[BEGIN]: Link node packages and binaries"
113 113 # johbo: Linking individual packages allows us to run "npm install"
114 114 # inside of a shell to try things out. Re-entering the shell will
115 115 # restore a clean environment.
116 116 rm -fr node_modules
117 117 mkdir node_modules
118 118 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
119 119 export NODE_PATH=./node_modules
120 120
121 121 rm -fr node_binaries
122 122 mkdir node_binaries
123 123 ln -s ${nodeDependencies}/bin/* node_binaries/
124 124 echo "[DONE ]: Link node packages and binaries"
125 125 '';
126 126
127 127 releaseName = "RhodeCodeEnterpriseCE-${version}";
128 128 in super.rhodecode-enterprise-ce.override (attrs: {
129 129 inherit
130 130 doCheck
131 131 version;
132 132
133 133 name = "rhodecode-enterprise-ce-${version}";
134 134 releaseName = releaseName;
135 135 src = rhodecode-enterprise-ce-src;
136 136 dontStrip = true; # prevent strip, we don't need it.
137 137
138 138 # expose following attributed outside
139 139 passthru = {
140 140 inherit
141 141 rhodecode-testdata
142 142 linkNodePackages
143 143 myPythonPackagesUnfix
144 144 pythonLocalOverrides
145 145 pythonCommunityOverrides;
146 146
147 147 pythonPackages = self;
148 148 };
149 149
150 150 buildInputs =
151 151 attrs.buildInputs or [] ++ [
152 152 rhodecode-testdata
153 153 ];
154 154
155 155 #NOTE: option to inject additional propagatedBuildInputs
156 156 propagatedBuildInputs =
157 157 attrs.propagatedBuildInputs or [] ++ [
158 158
159 159 ];
160 160
161 161 preBuild = ''
162 162 export NIX_PATH=nixpkgs=${pkgs.path}
163 163 export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
164 164
165 165 echo "[BEGIN]: Building frontend assets"
166 166 ${linkNodePackages}
167 167 make web-build
168 168 rm -fr node_modules
169 169 rm -fr node_binaries
170 170 echo "[DONE ]: Building frontend assets"
171 171 '';
172 172
173 173 # Add bin directory to path so that tests can find 'rhodecode'.
174 174 preCheck = ''
175 175 echo "Expanding PATH with $out/bin directory"
176 176 export PATH="$out/bin:$PATH"
177 177 '';
178 178
179 179 # custom check phase for testing
180 180 checkPhase = ''
181 181 runHook preCheck
182 182 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
183 183 runHook postCheck
184 184 '';
185 185
186 186 postCheck = ''
187 187 echo "Cleanup of rhodecode/tests"
188 188 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
189 189 '';
190 190
191 191 postInstall = ''
192 192 # check required files
193 193 STATIC_CHECK="/robots.txt /502.html
194 194 /js/scripts.min.js /js/rhodecode-components.js
195 195 /css/style.css /css/style-polymer.css /css/style-ipython.css"
196 196
197 197 for file in $STATIC_CHECK;
198 198 do
199 199 if [ ! -f rhodecode/public/$file ]; then
200 200 echo "Missing $file"
201 201 exit 1
202 202 fi
203 203 done
204 204
205 205 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
206 206 mkdir -p $out/nix-support/rccontrol
207 207 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
208 208 echo "[DONE ]: enterprise-ce meta information for rccontrol written"
209 209
210 210 mkdir -p $out/etc
211 211 cp configs/production.ini $out/etc
212 212 echo "[DONE ]: saved enterprise-ce production.ini into $out/etc"
213 213
214 214 cp -Rf rhodecode/config/rcextensions $out/etc/rcextensions.tmpl
215 215 echo "[DONE ]: saved enterprise-ce rcextensions into $out/etc/rcextensions.tmpl"
216 216
217 217 # python based programs need to be wrapped
218 218 mkdir -p $out/bin
219 219
220 # expose python
221 ln -s ${self.python}/bin/python $out/bin/
222
220 223 # required binaries from dependencies
221 224 ln -s ${self.supervisor}/bin/supervisorctl $out/bin/
222 225 ln -s ${self.supervisor}/bin/supervisord $out/bin/
223 226 ln -s ${self.pastescript}/bin/paster $out/bin/
224 227 ln -s ${self.channelstream}/bin/channelstream $out/bin/
225 228 ln -s ${self.celery}/bin/celery $out/bin/
226 229 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
227 230 ln -s ${self.pyramid}/bin/prequest $out/bin/
228 231 ln -s ${self.pyramid}/bin/pserve $out/bin/
229 232
230 233 echo "[DONE ]: created symlinks into $out/bin"
231 234 DEPS="$out/bin/supervisorctl \
232 235 $out/bin/supervisord \
233 236 $out/bin/paster \
234 237 $out/bin/channelstream \
235 238 $out/bin/celery \
236 239 $out/bin/gunicorn \
237 240 $out/bin/prequest \
238 241 $out/bin/pserve"
239 242
240 243 # wrap only dependency scripts, they require to have full PYTHONPATH set
241 244 # to be able to import all packages
242 245 for file in $DEPS;
243 246 do
244 247 wrapProgram $file \
245 248 --prefix PATH : $PATH \
246 249 --prefix PYTHONPATH : $PYTHONPATH \
247 250 --set PYTHONHASHSEED random
248 251 done
249 252
250 253 echo "[DONE ]: enterprise-ce binary wrapping"
251 254 # rhodecode-tools don't need wrapping
252 255 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
253 256
254 257 # expose sources of CE
255 258 ln -s $out $out/etc/rhodecode_enterprise_ce_source
256 259
257 260 # expose static files folder
258 261 cp -Rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/public/ $out/etc/static
259 262 chmod 755 -R $out/etc/static
260 263
261 264 '';
262 265
263 266 });
264 267 };
265 268
266 269
267 270 basePythonPackages = with builtins;
268 271 if isAttrs pythonPackages then
269 272 pythonPackages
270 273 else
271 274 getAttr pythonPackages pkgs;
272 275
273 276 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
274 277 inherit pkgs;
275 278 inherit (pkgs) fetchurl fetchgit fetchhg;
276 279 };
277 280
278 281 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
279 282 inherit pkgs basePythonPackages;
280 283 };
281 284
282 285 # Apply all overrides and fix the final package set
283 286 myPythonPackagesUnfix = with pkgs.lib;
284 287 (extends pythonExternalOverrides
285 288 (extends pythonLocalOverrides
286 289 (extends pythonCommunityOverrides
287 290 (extends pythonGeneratedPackages
288 291 basePythonPackagesUnfix))));
289 292
290 293 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
291 294
292 295 in myPythonPackages.rhodecode-enterprise-ce
General Comments 0
You need to be logged in to leave comments. Login now