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