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