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