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