##// END OF EJS Templates
packaging: only wrap external dependency scripts....
marcink -
r3122:6e8dcf31 default
parent child Browse files
Show More
@@ -1,260 +1,272 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@internal-code.rhodecode.com";
12 # codeInternalUrl = "https://usr:token@internal-code.rhodecode.com";
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 { pythonPackages ? "python27Packages"
22 { pythonPackages ? "python27Packages"
23 , pythonExternalOverrides ? self: super: {}
23 , pythonExternalOverrides ? self: super: {}
24 , doCheck ? false
24 , doCheck ? false
25 , ...
25 , ...
26 }:
26 }:
27
27
28 let
28 let
29 # Use nixpkgs from args or import them. We use this indirect approach
29 # Use nixpkgs from args or import them. We use this indirect approach
30 # through args to be able to use the name `pkgs` for our customized packages.
30 # through args to be able to use the name `pkgs` for our customized packages.
31 # Otherwise we will end up with an infinite recursion.
31 # Otherwise we will end up with an infinite recursion.
32 pkgs = args.pkgs or (import <nixpkgs> { });
32 pkgs = args.pkgs or (import <nixpkgs> { });
33
33
34 # Works with the new python-packages, still can fallback to the old
34 # Works with the new python-packages, still can fallback to the old
35 # variant.
35 # variant.
36 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
36 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
37 self: basePythonPackages.override (a: { inherit self; }));
37 self: basePythonPackages.override (a: { inherit self; }));
38
38
39 # Evaluates to the last segment of a file system path.
39 # Evaluates to the last segment of a file system path.
40 basename = path: with pkgs.lib; last (splitString "/" path);
40 basename = path: with pkgs.lib; last (splitString "/" path);
41
41
42 # source code filter used as arugment to builtins.filterSource.
42 # source code filter used as arugment to builtins.filterSource.
43 src-filter = path: type: with pkgs.lib;
43 src-filter = path: type: with pkgs.lib;
44 let
44 let
45 ext = last (splitString "." path);
45 ext = last (splitString "." path);
46 in
46 in
47 !builtins.elem (basename path) [
47 !builtins.elem (basename path) [
48 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
48 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
49 "bower_components" "node_modules"
49 "bower_components" "node_modules"
50 "build" "data" "result" "tmp"] &&
50 "build" "data" "result" "tmp"] &&
51 !builtins.elem ext ["egg-info" "pyc"] &&
51 !builtins.elem ext ["egg-info" "pyc"] &&
52 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
52 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
53 # it would still be good to restore it since we want to ignore "result-*".
53 # it would still be good to restore it since we want to ignore "result-*".
54 !hasPrefix "result" path;
54 !hasPrefix "result" path;
55
55
56 sources =
56 sources =
57 let
57 let
58 inherit (pkgs.lib) all isString attrValues;
58 inherit (pkgs.lib) all isString attrValues;
59 sourcesConfig = pkgs.config.rc.sources or {};
59 sourcesConfig = pkgs.config.rc.sources or {};
60 in
60 in
61 # Ensure that sources are configured as strings. Using a path
61 # Ensure that sources are configured as strings. Using a path
62 # would result in a copy into the nix store.
62 # would result in a copy into the nix store.
63 assert all isString (attrValues sourcesConfig);
63 assert all isString (attrValues sourcesConfig);
64 sourcesConfig;
64 sourcesConfig;
65
65
66 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
66 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
67 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
67 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
68
68
69 buildBowerComponents = pkgs.buildBowerComponents;
69 buildBowerComponents = pkgs.buildBowerComponents;
70 nodeEnv = import ./pkgs/node-default.nix {
70 nodeEnv = import ./pkgs/node-default.nix {
71 inherit pkgs;
71 inherit pkgs;
72 };
72 };
73 nodeDependencies = nodeEnv.shell.nodeDependencies;
73 nodeDependencies = nodeEnv.shell.nodeDependencies;
74
74
75 bowerComponents = buildBowerComponents {
75 bowerComponents = buildBowerComponents {
76 name = "enterprise-ce-${version}";
76 name = "enterprise-ce-${version}";
77 generated = ./pkgs/bower-packages.nix;
77 generated = ./pkgs/bower-packages.nix;
78 src = rhodecode-enterprise-ce-src;
78 src = rhodecode-enterprise-ce-src;
79 };
79 };
80
80
81 rhodecode-testdata-src = sources.rhodecode-testdata or (
81 rhodecode-testdata-src = sources.rhodecode-testdata or (
82 pkgs.fetchhg {
82 pkgs.fetchhg {
83 url = "https://code.rhodecode.com/upstream/rc_testdata";
83 url = "https://code.rhodecode.com/upstream/rc_testdata";
84 rev = "v0.10.0";
84 rev = "v0.10.0";
85 sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0";
85 sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0";
86 });
86 });
87
87
88 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
88 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
89 inherit
89 inherit
90 doCheck
90 doCheck
91 pkgs
91 pkgs
92 pythonPackages;
92 pythonPackages;
93 };
93 };
94
94
95 pythonLocalOverrides = self: super: {
95 pythonLocalOverrides = self: super: {
96 rhodecode-enterprise-ce =
96 rhodecode-enterprise-ce =
97 let
97 let
98 linkNodeAndBowerPackages = ''
98 linkNodeAndBowerPackages = ''
99 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
99 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
100
100
101 echo "[BEGIN]: Link node packages"
101 echo "[BEGIN]: Link node packages"
102 rm -fr node_modules
102 rm -fr node_modules
103 mkdir node_modules
103 mkdir node_modules
104 # johbo: Linking individual packages allows us to run "npm install"
104 # johbo: Linking individual packages allows us to run "npm install"
105 # inside of a shell to try things out. Re-entering the shell will
105 # inside of a shell to try things out. Re-entering the shell will
106 # restore a clean environment.
106 # restore a clean environment.
107 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
107 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
108 echo "[DONE]: Link node packages"
108 echo "[DONE]: Link node packages"
109
109
110 echo "[BEGIN]: Link bower packages"
110 echo "[BEGIN]: Link bower packages"
111 rm -fr bower_components
111 rm -fr bower_components
112 mkdir bower_components
112 mkdir bower_components
113 ln -s ${bowerComponents}/bower_components/* bower_components/
113 ln -s ${bowerComponents}/bower_components/* bower_components/
114 echo "[DONE]: Link bower packages"
114 echo "[DONE]: Link bower packages"
115 '';
115 '';
116
116
117 releaseName = "RhodeCodeEnterpriseCE-${version}";
117 releaseName = "RhodeCodeEnterpriseCE-${version}";
118 in super.rhodecode-enterprise-ce.override (attrs: {
118 in super.rhodecode-enterprise-ce.override (attrs: {
119 inherit
119 inherit
120 doCheck
120 doCheck
121 version;
121 version;
122
122
123 name = "rhodecode-enterprise-ce-${version}";
123 name = "rhodecode-enterprise-ce-${version}";
124 releaseName = releaseName;
124 releaseName = releaseName;
125 src = rhodecode-enterprise-ce-src;
125 src = rhodecode-enterprise-ce-src;
126 dontStrip = true; # prevent strip, we don't need it.
126 dontStrip = true; # prevent strip, we don't need it.
127
127
128 # expose following attributed outside
128 # expose following attributed outside
129 passthru = {
129 passthru = {
130 inherit
130 inherit
131 rhodecode-testdata
131 rhodecode-testdata
132 bowerComponents
132 bowerComponents
133 linkNodeAndBowerPackages
133 linkNodeAndBowerPackages
134 myPythonPackagesUnfix
134 myPythonPackagesUnfix
135 pythonLocalOverrides
135 pythonLocalOverrides
136 pythonCommunityOverrides;
136 pythonCommunityOverrides;
137
137
138 pythonPackages = self;
138 pythonPackages = self;
139 };
139 };
140
140
141 buildInputs =
141 buildInputs =
142 attrs.buildInputs or [] ++ [
142 attrs.buildInputs or [] ++ [
143 rhodecode-testdata
143 rhodecode-testdata
144 pkgs.nodePackages.bower
144 pkgs.nodePackages.bower
145 pkgs.nodePackages.grunt-cli
145 pkgs.nodePackages.grunt-cli
146 ];
146 ];
147
147
148 #NOTE: option to inject additional propagatedBuildInputs
148 #NOTE: option to inject additional propagatedBuildInputs
149 propagatedBuildInputs =
149 propagatedBuildInputs =
150 attrs.propagatedBuildInputs or [] ++ [
150 attrs.propagatedBuildInputs or [] ++ [
151
151
152 ];
152 ];
153
153
154 LC_ALL = "en_US.UTF-8";
154 LC_ALL = "en_US.UTF-8";
155 LOCALE_ARCHIVE =
155 LOCALE_ARCHIVE =
156 if pkgs.stdenv.isLinux
156 if pkgs.stdenv.isLinux
157 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
157 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
158 else "";
158 else "";
159
159
160 # Add bin directory to path so that tests can find 'rhodecode'.
160 # Add bin directory to path so that tests can find 'rhodecode'.
161 preCheck = ''
161 preCheck = ''
162 export PATH="$out/bin:$PATH"
162 export PATH="$out/bin:$PATH"
163 '';
163 '';
164
164
165 # custom check phase for testing
165 # custom check phase for testing
166 checkPhase = ''
166 checkPhase = ''
167 runHook preCheck
167 runHook preCheck
168 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
168 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
169 runHook postCheck
169 runHook postCheck
170 '';
170 '';
171
171
172 postCheck = ''
172 postCheck = ''
173 echo "Cleanup of rhodecode/tests"
173 echo "Cleanup of rhodecode/tests"
174 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
174 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
175 '';
175 '';
176
176
177 preBuild = ''
177 preBuild = ''
178 echo "Building frontend assets"
178 echo "Building frontend assets"
179 ${linkNodeAndBowerPackages}
179 ${linkNodeAndBowerPackages}
180 grunt
180 grunt
181 rm -fr node_modules
181 rm -fr node_modules
182 '';
182 '';
183
183
184 postInstall = ''
184 postInstall = ''
185 # check required files
185 # check required files
186 if [ ! -f rhodecode/public/js/scripts.js ]; then
186 if [ ! -f rhodecode/public/js/scripts.js ]; then
187 echo "Missing scripts.js"
187 echo "Missing scripts.js"
188 exit 1
188 exit 1
189 fi
189 fi
190 if [ ! -f rhodecode/public/css/style.css ]; then
190 if [ ! -f rhodecode/public/css/style.css ]; then
191 echo "Missing style.css"
191 echo "Missing style.css"
192 exit 1
192 exit 1
193 fi
193 fi
194
194
195 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
195 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
196 mkdir -p $out/nix-support/rccontrol
196 mkdir -p $out/nix-support/rccontrol
197 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
197 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
198 echo "[DONE]: enterprise-ce meta information for rccontrol written"
198 echo "[DONE]: enterprise-ce meta information for rccontrol written"
199
199
200 mkdir -p $out/etc
200 mkdir -p $out/etc
201 cp configs/production.ini $out/etc
201 cp configs/production.ini $out/etc
202 echo "[DONE]: saved enterprise-ce production.ini into $out/etc"
202 echo "[DONE]: saved enterprise-ce production.ini into $out/etc"
203
203
204 # python based programs need to be wrapped
204 # python based programs need to be wrapped
205 mkdir -p $out/bin
205 mkdir -p $out/bin
206
206
207 # required binaries from dependencies
207 # required binaries from dependencies
208 #ln -s ${self.python}/bin/python $out/bin
208 ln -s ${self.supervisor}/bin/supervisorctl $out/bin/
209 ln -s ${self.pyramid}/bin/* $out/bin/
209 ln -s ${self.supervisor}/bin/supervisord $out/bin/
210 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
211 ln -s ${self.supervisor}/bin/supervisor* $out/bin/
212 ln -s ${self.pastescript}/bin/paster $out/bin/
210 ln -s ${self.pastescript}/bin/paster $out/bin/
213 ln -s ${self.channelstream}/bin/channelstream $out/bin/
211 ln -s ${self.channelstream}/bin/channelstream $out/bin/
214 ln -s ${self.celery}/bin/celery $out/bin/
212 ln -s ${self.celery}/bin/celery $out/bin/
215 echo "[DONE]: created symlinks into $out/bin"
213 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
214 ln -s ${self.pyramid}/bin/prequest $out/bin/
215 ln -s ${self.pyramid}/bin/pserve $out/bin/
216
216
217 for file in $out/bin/*;
217 echo "[DONE]: created symlinks into $out/bin"
218 DEPS="$out/bin/supervisorctl \
219 $out/bin/supervisord \
220 $out/bin/paster \
221 $out/bin/channelstream \
222 $out/bin/celery \
223 $out/bin/gunicorn \
224 $out/bin/prequest \
225 $out/bin/pserve"
226
227 # wrap only dependency scripts, they require to have full PYTHONPATH set
228 # to be able to import all packages
229 for file in $DEPS;
218 do
230 do
219 wrapProgram $file \
231 wrapProgram $file \
220 --prefix PATH : $PATH \
232 --prefix PATH : $PATH \
221 --prefix PYTHONPATH : $PYTHONPATH \
233 --prefix PYTHONPATH : $PYTHONPATH \
222 --set PYTHONHASHSEED random
234 --set PYTHONHASHSEED random
223 done
235 done
224
236
225 echo "[DONE]: enterprise-ce binary wrapping"
237 echo "[DONE]: enterprise-ce binary wrapping"
226
238
227 # rhodecode-tools don't need wrapping
239 # rhodecode-tools don't need wrapping
228 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
240 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
229
241
230 '';
242 '';
231 });
243 });
232
244
233 };
245 };
234
246
235 basePythonPackages = with builtins;
247 basePythonPackages = with builtins;
236 if isAttrs pythonPackages then
248 if isAttrs pythonPackages then
237 pythonPackages
249 pythonPackages
238 else
250 else
239 getAttr pythonPackages pkgs;
251 getAttr pythonPackages pkgs;
240
252
241 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
253 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
242 inherit pkgs;
254 inherit pkgs;
243 inherit (pkgs) fetchurl fetchgit fetchhg;
255 inherit (pkgs) fetchurl fetchgit fetchhg;
244 };
256 };
245
257
246 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
258 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
247 inherit pkgs basePythonPackages;
259 inherit pkgs basePythonPackages;
248 };
260 };
249
261
250 # Apply all overrides and fix the final package set
262 # Apply all overrides and fix the final package set
251 myPythonPackagesUnfix = with pkgs.lib;
263 myPythonPackagesUnfix = with pkgs.lib;
252 (extends pythonExternalOverrides
264 (extends pythonExternalOverrides
253 (extends pythonLocalOverrides
265 (extends pythonLocalOverrides
254 (extends pythonCommunityOverrides
266 (extends pythonCommunityOverrides
255 (extends pythonGeneratedPackages
267 (extends pythonGeneratedPackages
256 basePythonPackagesUnfix))));
268 basePythonPackagesUnfix))));
257
269
258 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
270 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
259
271
260 in myPythonPackages.rhodecode-enterprise-ce
272 in myPythonPackages.rhodecode-enterprise-ce
General Comments 0
You need to be logged in to leave comments. Login now