##// END OF EJS Templates
nix: Link node modules based on node2nix
johbo -
r708:caa19e67 default
parent child Browse files
Show More
@@ -1,229 +1,218 b''
1 1 # Nix environment for the community edition
2 2 #
3 3 # This shall be as lean as possible, just producing the Enterprise
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 { pkgs ? (import <nixpkgs> {})
8 8 , pythonPackages ? "python27Packages"
9 9 , pythonExternalOverrides ? self: super: {}
10 10 , doCheck ? true
11 11 }:
12 12
13 13 let pkgs_ = pkgs; in
14 14
15 15 let
16 16 pkgs = pkgs_.overridePackages (self: super: {
17 17 # Override subversion derivation to
18 18 # - activate python bindings
19 19 # - set version to 1.8
20 20 subversion = super.subversion18.override {
21 21 httpSupport = true;
22 22 pythonBindings = true;
23 23 python = self.python27Packages.python;
24 24 };
25 25 });
26 26
27 27 inherit (pkgs.lib) fix extends;
28 28
29 29 basePythonPackages = with builtins; if isAttrs pythonPackages
30 30 then pythonPackages
31 31 else getAttr pythonPackages pkgs;
32 32
33 33 elem = builtins.elem;
34 34 basename = path: with pkgs.lib; last (splitString "/" path);
35 35 startsWith = prefix: full: let
36 36 actualPrefix = builtins.substring 0 (builtins.stringLength prefix) full;
37 37 in actualPrefix == prefix;
38 38
39 39 src-filter = path: type: with pkgs.lib;
40 40 let
41 41 ext = last (splitString "." path);
42 42 in
43 43 !elem (basename path) [
44 44 ".git" ".hg" "__pycache__" ".eggs" "node_modules"
45 45 "build" "data" "tmp"] &&
46 46 !elem ext ["egg-info" "pyc"] &&
47 47 !startsWith "result" path;
48 48
49 49 sources = pkgs.config.rc.sources or {};
50 50 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
51 51
52 # Load the generated node packages
53 nodePackages = pkgs.callPackage "${pkgs.path}/pkgs/top-level/node-packages.nix" rec {
54 self = nodePackages;
55 generated = pkgs.callPackage ./pkgs/node-packages.nix { inherit self; };
52 nodeEnv = import ./pkgs/node-default.nix {
53 inherit pkgs;
56 54 };
57
58 # TODO: Should be taken automatically out of the generates packages.
59 # apps.nix has one solution for this, although I'd prefer to have the deps
60 # from package.json mapped in here.
61 nodeDependencies = with nodePackages; [
62 grunt
63 grunt-contrib-concat
64 grunt-contrib-jshint
65 grunt-contrib-less
66 grunt-contrib-watch
67 jshint
68 ];
55 nodeDependencies = nodeEnv.shell.nodeDependencies;
69 56
70 57 pythonGeneratedPackages = self: basePythonPackages.override (a: {
71 58 inherit self;
72 59 })
73 60 // (scopedImport {
74 61 self = self;
75 62 super = basePythonPackages;
76 63 inherit pkgs;
77 64 inherit (pkgs) fetchurl fetchgit;
78 65 } ./pkgs/python-packages.nix);
79 66
80 67 pythonOverrides = import ./pkgs/python-packages-overrides.nix {
81 68 inherit
82 69 basePythonPackages
83 70 pkgs;
84 71 };
85 72
86 73 pythonLocalOverrides = self: super: {
87 74 rhodecode-enterprise-ce =
88 75 let
89 76 version = builtins.readFile ./rhodecode/VERSION;
90 77 linkNodeModules = ''
91 78 echo "Link node packages"
92 # TODO: check if this adds stuff as a dependency, closure size
93 79 rm -fr node_modules
94 mkdir -p node_modules
95 ${pkgs.lib.concatMapStrings (dep: ''
96 ln -sfv ${dep}/lib/node_modules/${dep.pkgName} node_modules/
97 '') nodeDependencies}
80 mkdir node_modules
81
82 # johbo: Linking individual packages allows us to run "npm install"
83 # inside of a shell to try things out. Re-entering the shell will
84 # restore a clean environment.
85 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
86
98 87 echo "DONE: Link node packages"
99 88 '';
100 89 in super.rhodecode-enterprise-ce.override (attrs: {
101 90
102 91 inherit
103 92 doCheck
104 93 version;
105 94 name = "rhodecode-enterprise-ce-${version}";
106 95 releaseName = "RhodeCodeEnterpriseCE-${version}";
107 96 src = rhodecode-enterprise-ce-src;
108 97
109 98 buildInputs =
110 99 attrs.buildInputs ++
111 100 (with self; [
112 101 pkgs.nodePackages.grunt-cli
113 102 pkgs.subversion
114 103 pytest-catchlog
115 104 rhodecode-testdata
116 105 ]);
117 106
118 107 propagatedBuildInputs = attrs.propagatedBuildInputs ++ (with self; [
119 108 rhodecode-tools
120 109 ]);
121 110
122 111 # TODO: johbo: Make a nicer way to expose the parts. Maybe
123 112 # pkgs/default.nix?
124 113 passthru = {
125 114 inherit
126 115 linkNodeModules
127 116 myPythonPackagesUnfix
128 117 pythonLocalOverrides;
129 118 pythonPackages = self;
130 119 };
131 120
132 121 LC_ALL = "en_US.UTF-8";
133 122 LOCALE_ARCHIVE =
134 123 if pkgs.stdenv ? glibc
135 124 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
136 125 else "";
137 126
138 127 # Somewhat snappier setup of the development environment
139 128 # TODO: move into shell.nix
140 129 # TODO: think of supporting a stable path again, so that multiple shells
141 130 # can share it.
142 131 shellHook = ''
143 132 tmp_path=$(mktemp -d)
144 133 export PATH="$tmp_path/bin:$PATH"
145 134 export PYTHONPATH="$tmp_path/${self.python.sitePackages}:$PYTHONPATH"
146 135 mkdir -p $tmp_path/${self.python.sitePackages}
147 136 python setup.py develop --prefix $tmp_path --allow-hosts ""
148 137 '' + linkNodeModules;
149 138
150 139 preCheck = ''
151 140 export PATH="$out/bin:$PATH"
152 141 '';
153 142
154 143 postCheck = ''
155 144 rm -rf $out/lib/${self.python.libPrefix}/site-packages/pytest_pylons
156 145 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
157 146 '';
158 147
159 148 preBuild = linkNodeModules + ''
160 149 grunt
161 150 rm -fr node_modules
162 151 '';
163 152
164 153 postInstall = ''
165 154 # python based programs need to be wrapped
166 155 ln -s ${self.supervisor}/bin/supervisor* $out/bin/
167 156 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
168 157 ln -s ${self.PasteScript}/bin/paster $out/bin/
169 158 ln -s ${self.channelstream}/bin/channelstream $out/bin/
170 159 ln -s ${self.pyramid}/bin/* $out/bin/ #*/
171 160
172 161 # rhodecode-tools
173 162 # TODO: johbo: re-think this. Do the tools import anything from enterprise?
174 163 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
175 164
176 165 # note that condition should be restricted when adding further tools
177 166 for file in $out/bin/*; do #*/
178 167 wrapProgram $file \
179 168 --prefix PYTHONPATH : $PYTHONPATH \
180 169 --prefix PATH : $PATH \
181 170 --set PYTHONHASHSEED random
182 171 done
183 172
184 173 mkdir $out/etc
185 174 cp configs/production.ini $out/etc
186 175
187 176 echo "Writing meta information for rccontrol to nix-support/rccontrol"
188 177 mkdir -p $out/nix-support/rccontrol
189 178 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
190 179 echo "DONE: Meta information for rccontrol written"
191 180
192 181 # TODO: johbo: Make part of ac-tests
193 182 if [ ! -f rhodecode/public/js/scripts.js ]; then
194 183 echo "Missing scripts.js"
195 184 exit 1
196 185 fi
197 186 if [ ! -f rhodecode/public/css/style.css ]; then
198 187 echo "Missing style.css"
199 188 exit 1
200 189 fi
201 190 '';
202 191
203 192 });
204 193
205 194 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
206 195 inherit
207 196 doCheck
208 197 pkgs
209 198 pythonPackages;
210 199 };
211 200
212 201 };
213 202
214 203 rhodecode-testdata-src = sources.rhodecode-testdata or (
215 204 pkgs.fetchhg {
216 205 url = "https://code.rhodecode.com/upstream/rc_testdata";
217 206 rev = "v0.8.0";
218 207 sha256 = "0hy1ba134rq2f9si85yx7j4qhc9ky0hjzdk553s3q026i7km809m";
219 208 });
220 209
221 210 # Apply all overrides and fix the final package set
222 211 myPythonPackagesUnfix =
223 212 (extends pythonExternalOverrides
224 213 (extends pythonLocalOverrides
225 214 (extends pythonOverrides
226 215 pythonGeneratedPackages)));
227 216 myPythonPackages = (fix myPythonPackagesUnfix);
228 217
229 218 in myPythonPackages.rhodecode-enterprise-ce
General Comments 0
You need to be logged in to leave comments. Login now