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