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