##// END OF EJS Templates
nix: further nix changes
marcink -
r4761:ffe072a3 python3
parent child Browse files
Show More
@@ -1,295 +1,302 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 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
82 83 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
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 pythonWithEnv =
129 self.python.buildEnv.override {
130 extraLibs = [ ] ++ self.rhodecode-enterprise-ce.propagatedBuildInputs;
131 ignoreCollisions = true;
132 #--set PYTHONHASHSEED random TODO
133 };
128 134 in super.rhodecode-enterprise-ce.override (attrs: {
129 135 inherit
130 136 doCheck
131 137 version;
132 138
133 139 name = "rhodecode-enterprise-ce-${version}";
134 140 releaseName = releaseName;
135 141 src = rhodecode-enterprise-ce-src;
136 142 dontStrip = true; # prevent strip, we don't need it.
137 143
138 144 # expose following attributed outside
139 145 passthru = {
140 146 inherit
141 147 rhodecode-testdata
142 148 linkNodePackages
143 149 myPythonPackagesUnfix
144 150 pythonLocalOverrides
145 151 pythonCommunityOverrides;
146 152
147 153 pythonPackages = self;
154 rc_pkgs = pkgs;
148 155 };
149 156
150 157 buildInputs =
151 158 attrs.buildInputs or [] ++ [
152 159 rhodecode-testdata
153 160 ];
154 161
155 162 #NOTE: option to inject additional propagatedBuildInputs
156 163 propagatedBuildInputs =
157 164 attrs.propagatedBuildInputs or [] ++ [
158 165
159 166 ];
160 167
161 168 preBuild = ''
162 169 export NIX_PATH=nixpkgs=${pkgs.path}
163 170 export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
164 171
165 172 echo "[BEGIN]: Building frontend assets"
166 173 ${linkNodePackages}
167 174 make web-build
168 175 rm -fr node_modules
169 176 rm -fr node_binaries
170 177 echo "[DONE ]: Building frontend assets"
171 178 '';
172 179
173 180 # Add bin directory to path so that tests can find 'rhodecode'.
174 181 preCheck = ''
175 182 echo "Expanding PATH with $out/bin directory"
176 183 export PATH="$out/bin:$PATH"
177 184 '';
178 185
179 186 # custom check phase for testing
180 187 checkPhase = ''
181 188 runHook preCheck
182 189 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
183 190 runHook postCheck
184 191 '';
185 192
186 193 postCheck = ''
187 194 echo "Cleanup of rhodecode/tests"
188 195 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
189 196 '';
190 197
191 198 postInstall = ''
192 199 # check required files
193 200 STATIC_CHECK="/robots.txt /502.html
194 201 /js/scripts.min.js /js/rhodecode-components.js
195 202 /css/style.css /css/style-polymer.css /css/style-ipython.css"
196 203
197 204 for file in $STATIC_CHECK;
198 205 do
199 206 if [ ! -f rhodecode/public/$file ]; then
200 207 echo "Missing $file"
201 208 exit 1
202 209 fi
203 210 done
204 211
205 212 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
206 213 mkdir -p $out/nix-support/rccontrol
207 214 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
208 215 echo "[DONE ]: enterprise-ce meta information for rccontrol written"
209 216
210 217 mkdir -p $out/etc
211 218 cp configs/production.ini $out/etc
212 219 echo "[DONE ]: saved enterprise-ce production.ini into $out/etc"
213 220
221 echo "saving env in $out/etc/env_vars.txt"
222 touch $out/etc/env_vars.txt
223 echo "# RhodeCode build env vars" >> $out/etc/env_vars.txt
224 echo "LOCALE_ARCHIVE=\"${pkgs.glibcLocales}/lib/locale/locale-archive\"" >> $out/etc/env_vars.txt
225 echo "LC_ALL=\"en_US.UTF-8\"" >> $out/etc/env_vars.txt
226
214 227 cp -Rf rhodecode/config/rcextensions $out/etc/rcextensions.tmpl
215 228 echo "[DONE ]: saved enterprise-ce rcextensions into $out/etc/rcextensions.tmpl"
216 229
217 230 # python based programs need to be wrapped
218 231 mkdir -p $out/bin
219 232
220 233 # expose python
221 ln -s ${self.python}/bin/python $out/bin/
234 ln -s ${pythonWithEnv}/bin/python $out/bin/
222 235
223 236 # required binaries from dependencies
224 ln -s ${self.supervisor}/bin/supervisorctl $out/bin/
225 ln -s ${self.supervisor}/bin/supervisord $out/bin/
226 ln -s ${self.pastescript}/bin/paster $out/bin/
227 ln -s ${self.channelstream}/bin/channelstream $out/bin/
228 ln -s ${self.celery}/bin/celery $out/bin/
229 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
230 ln -s ${self.pyramid}/bin/prequest $out/bin/
231 ln -s ${self.pyramid}/bin/pserve $out/bin/
237 ln -s ${pythonWithEnv}/bin/supervisorctl $out/bin/
238 ln -s ${pythonWithEnv}/bin/supervisord $out/bin/
239 ln -s ${pythonWithEnv}/bin/paster $out/bin/
240 ln -s ${pythonWithEnv}/bin/channelstream $out/bin/
241 ln -s ${pythonWithEnv}/bin/celery $out/bin/
242 ln -s ${pythonWithEnv}/bin/gunicorn $out/bin/
243 ln -s ${pythonWithEnv}/bin/prequest $out/bin/
244 ln -s ${pythonWithEnv}/bin/pserve $out/bin/
232 245
233 246 echo "[DONE ]: created symlinks into $out/bin"
234 DEPS="$out/bin/supervisorctl \
235 $out/bin/supervisord \
236 $out/bin/paster \
237 $out/bin/channelstream \
238 $out/bin/celery \
239 $out/bin/gunicorn \
240 $out/bin/prequest \
241 $out/bin/pserve"
247 DEPS="
248 "
242 249
243 250 # wrap only dependency scripts, they require to have full PYTHONPATH set
244 251 # to be able to import all packages
245 252 for file in $DEPS;
246 253 do
247 254 wrapProgram $file \
248 255 --prefix PATH : $PATH \
249 256 --prefix PYTHONPATH : $PYTHONPATH \
250 257 --set PYTHONHASHSEED random
251 258 done
252 259
253 260 echo "[DONE ]: enterprise-ce binary wrapping"
261
254 262 # rhodecode-tools don't need wrapping
255 263 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
256 264
257 # expose sources of CE
258 ln -s $out $out/etc/rhodecode_enterprise_ce_source
259
260 265 # expose static files folder
261 266 cp -Rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/public/ $out/etc/static
262 267 chmod 755 -R $out/etc/static
263 268
269 # expose sources of rhodecode-enterprise-ce
270 ln -s $out $out/etc/rhodecode_enterprise_ce_source
264 271 '';
265 272
266 273 });
267 274 };
268 275
269 276
270 277 basePythonPackages = with builtins;
271 278 if isAttrs pythonPackages then
272 279 pythonPackages
273 280 else
274 281 getAttr pythonPackages pkgs;
275 282
276 283 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
277 284 inherit pkgs;
278 285 inherit (pkgs) fetchurl fetchgit fetchhg;
279 286 };
280 287
281 288 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
282 289 inherit pkgs basePythonPackages;
283 290 };
284 291
285 292 # Apply all overrides and fix the final package set
286 293 myPythonPackagesUnfix = with pkgs.lib;
287 294 (extends pythonExternalOverrides
288 295 (extends pythonLocalOverrides
289 296 (extends pythonCommunityOverrides
290 297 (extends pythonGeneratedPackages
291 298 basePythonPackagesUnfix))));
292 299
293 300 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
294 301
295 302 in myPythonPackages.rhodecode-enterprise-ce
@@ -1,17 +1,25 b''
1 1 { pkgs
2 2 , pythonPackages
3 3 }:
4 4
5 5 rec {
6 6 pip2nix-src = pkgs.fetchzip {
7 7 url = https://github.com/johbo/pip2nix/archive/51e6fdae34d0e8ded9efeef7a8601730249687a6.tar.gz;
8 8 sha256 = "02a4jjgi7lsvf8mhrxsd56s9a3yg20081rl9bgc2m84w60v2gbz2";
9 9 };
10 10
11 11 pip2nix = import pip2nix-src {
12 12 inherit
13 13 pkgs
14 14 pythonPackages;
15 15 };
16 16
17 pip-tools = pythonPackages.pip-tools;
18
19 setuptools = pythonPackages.setuptools;
20
21 wheel = pythonPackages.wheel;
22
23 pip = pythonPackages.pip;
24
17 25 }
@@ -1,71 +1,73 b''
1 1 { pkgs ? (import <nixpkgs> {})
2 2 , pythonPackages ? "python27Packages"
3 3 }:
4 4
5 5 with pkgs.lib;
6 6
7 7 let
8 8 _pythonPackages = pythonPackages;
9 9
10 10 in
11 11
12 12 let
13 13 pythonPackages = getAttr _pythonPackages pkgs;
14 14
15 15 pip2nix = import ./nix-common/pip2nix.nix {
16 16 inherit
17 17 pkgs
18 18 pythonPackages;
19 19 };
20 20
21 21 in
22 22
23 23 pkgs.stdenv.mkDerivation {
24 24 name = "pip2nix-generated";
25 25
26 26 buildInputs = [
27 27 # Allows to generate python packages
28 28 pip2nix.pip2nix
29 pythonPackages.pip-tools
29 pip2nix.pip
30 pip2nix.pip-tools
31
30 32 # compile using ffi
31 33 pkgs.libffi
32 34
33 35 pythonPackages.cython
34 36
35 37 # Allows to generate node dependencies
36 38 pkgs.nodePackages.node2nix
37 39
38 40 # We need mysql_config to be around
39 41 pkgs.libmysqlclient
40 42
41 43 # We need postgresql to be around
42 44 pkgs.postgresql
43 45
44 46 # we need the below for saml
45 47 pkgs.libxml2
46 48 pkgs.libxslt
47 49 pkgs.xmlsec
48 50
49 51 # Curl is needed for pycurl
50 52 pkgs.curl
51 53 ];
52 54
53 55 shellHook = ''
54 56 runHook preShellHook
55 57 runHook postShellHook
56 58 '';
57 59
58 60 preShellHook = ''
59 61 echo "Starting Generate Shell"
60 62 # set unpack source date to 1980 to fix ZIP problems that does not support <1980
61 63 export SOURCE_DATE_EPOCH=315532800
62 64 export TMPDIR=/tmp
63 65 export LOCALE_ARCHIVE="${pkgs.glibcLocales}/lib/locale/locale-archive"
64 66 export LC_ALL="en_US.UTF-8"
67 export PYCURL_SSL_LIBRARY=openssl
68
65 69 # Custom prompt to distinguish from other dev envs.
66 70 export PS1="\n\[\033[1;32m\][pip2nix-generate-shell]$\[\033[0m\] "
67 71
68 export PYCURL_SSL_LIBRARY=openssl
69
70 72 '';
71 73 }
General Comments 0
You need to be logged in to leave comments. Login now