##// END OF EJS Templates
nix: Move shell hook: default.nix -> shell.nix and set custom prompt....
Martin Bornhold -
r1130:328807b4 default
parent child Browse files
Show More
@@ -1,250 +1,238 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 args@
7 args@
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
13
14 let
14 let
15
15
16 # Use nixpkgs from args or import them. We use this indirect approach
16 # Use nixpkgs from args or import them. We use this indirect approach
17 # through args to be able to use the name `pkgs` for our customized packages.
17 # through args to be able to use the name `pkgs` for our customized packages.
18 # Otherwise we will end up with an infinite recursion.
18 # Otherwise we will end up with an infinite recursion.
19 nixpkgs = args.pkgs or (import <nixpkgs> { });
19 nixpkgs = args.pkgs or (import <nixpkgs> { });
20
20
21 # johbo: Interim bridge which allows us to build with the upcoming
21 # johbo: Interim bridge which allows us to build with the upcoming
22 # nixos.16.09 branch (unstable at the moment of writing this note) and the
22 # nixos.16.09 branch (unstable at the moment of writing this note) and the
23 # current stable nixos-16.03.
23 # current stable nixos-16.03.
24 backwardsCompatibleFetchgit = { ... }@args:
24 backwardsCompatibleFetchgit = { ... }@args:
25 let
25 let
26 origSources = nixpkgs.fetchgit args;
26 origSources = nixpkgs.fetchgit args;
27 in
27 in
28 nixpkgs.lib.overrideDerivation origSources (oldAttrs: {
28 nixpkgs.lib.overrideDerivation origSources (oldAttrs: {
29 NIX_PREFETCH_GIT_CHECKOUT_HOOK = ''
29 NIX_PREFETCH_GIT_CHECKOUT_HOOK = ''
30 find $out -name '.git*' -print0 | xargs -0 rm -rf
30 find $out -name '.git*' -print0 | xargs -0 rm -rf
31 '';
31 '';
32 });
32 });
33
33
34 # Create a customized version of nixpkgs which should be used throughout the
34 # Create a customized version of nixpkgs which should be used throughout the
35 # rest of this file.
35 # rest of this file.
36 pkgs = nixpkgs.overridePackages (self: super: {
36 pkgs = nixpkgs.overridePackages (self: super: {
37 fetchgit = backwardsCompatibleFetchgit;
37 fetchgit = backwardsCompatibleFetchgit;
38 });
38 });
39
39
40 # Evaluates to the last segment of a file system path.
40 # Evaluates to the last segment of a file system path.
41 basename = path: with pkgs.lib; last (splitString "/" path);
41 basename = path: with pkgs.lib; last (splitString "/" path);
42
42
43 # source code filter used as arugment to builtins.filterSource.
43 # source code filter used as arugment to builtins.filterSource.
44 src-filter = path: type: with pkgs.lib;
44 src-filter = path: type: with pkgs.lib;
45 let
45 let
46 ext = last (splitString "." path);
46 ext = last (splitString "." path);
47 in
47 in
48 !builtins.elem (basename path) [
48 !builtins.elem (basename path) [
49 ".git" ".hg" "__pycache__" ".eggs"
49 ".git" ".hg" "__pycache__" ".eggs"
50 "bower_components" "node_modules"
50 "bower_components" "node_modules"
51 "build" "data" "result" "tmp"] &&
51 "build" "data" "result" "tmp"] &&
52 !builtins.elem ext ["egg-info" "pyc"] &&
52 !builtins.elem ext ["egg-info" "pyc"] &&
53 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
53 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
54 # it would still be good to restore it since we want to ignore "result-*".
54 # it would still be good to restore it since we want to ignore "result-*".
55 !hasPrefix "result" path;
55 !hasPrefix "result" path;
56
56
57 basePythonPackages = with builtins; if isAttrs pythonPackages
57 basePythonPackages = with builtins; if isAttrs pythonPackages
58 then pythonPackages
58 then pythonPackages
59 else getAttr pythonPackages pkgs;
59 else getAttr pythonPackages pkgs;
60
60
61 buildBowerComponents =
61 buildBowerComponents =
62 pkgs.buildBowerComponents or
62 pkgs.buildBowerComponents or
63 (import ./pkgs/backport-16.03-build-bower-components.nix { inherit pkgs; });
63 (import ./pkgs/backport-16.03-build-bower-components.nix { inherit pkgs; });
64
64
65 sources = pkgs.config.rc.sources or {};
65 sources = pkgs.config.rc.sources or {};
66 version = builtins.readFile ./rhodecode/VERSION;
66 version = builtins.readFile ./rhodecode/VERSION;
67 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
67 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
68
68
69 nodeEnv = import ./pkgs/node-default.nix {
69 nodeEnv = import ./pkgs/node-default.nix {
70 inherit pkgs;
70 inherit pkgs;
71 };
71 };
72 nodeDependencies = nodeEnv.shell.nodeDependencies;
72 nodeDependencies = nodeEnv.shell.nodeDependencies;
73
73
74 bowerComponents = buildBowerComponents {
74 bowerComponents = buildBowerComponents {
75 name = "enterprise-ce-${version}";
75 name = "enterprise-ce-${version}";
76 generated = ./pkgs/bower-packages.nix;
76 generated = ./pkgs/bower-packages.nix;
77 src = rhodecode-enterprise-ce-src;
77 src = rhodecode-enterprise-ce-src;
78 };
78 };
79
79
80 pythonGeneratedPackages = self: basePythonPackages.override (a: {
80 pythonGeneratedPackages = self: basePythonPackages.override (a: {
81 inherit self;
81 inherit self;
82 })
82 })
83 // (scopedImport {
83 // (scopedImport {
84 self = self;
84 self = self;
85 super = basePythonPackages;
85 super = basePythonPackages;
86 inherit pkgs;
86 inherit pkgs;
87 inherit (pkgs) fetchurl fetchgit;
87 inherit (pkgs) fetchurl fetchgit;
88 } ./pkgs/python-packages.nix);
88 } ./pkgs/python-packages.nix);
89
89
90 pythonOverrides = import ./pkgs/python-packages-overrides.nix {
90 pythonOverrides = import ./pkgs/python-packages-overrides.nix {
91 inherit
91 inherit
92 basePythonPackages
92 basePythonPackages
93 pkgs;
93 pkgs;
94 };
94 };
95
95
96 pythonLocalOverrides = self: super: {
96 pythonLocalOverrides = self: super: {
97 rhodecode-enterprise-ce =
97 rhodecode-enterprise-ce =
98 let
98 let
99 linkNodeAndBowerPackages = ''
99 linkNodeAndBowerPackages = ''
100 echo "Export RhodeCode CE path"
100 echo "Export RhodeCode CE path"
101 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
101 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
102 echo "Link node packages"
102 echo "Link node packages"
103 rm -fr node_modules
103 rm -fr node_modules
104 mkdir node_modules
104 mkdir node_modules
105 # johbo: Linking individual packages allows us to run "npm install"
105 # johbo: Linking individual packages allows us to run "npm install"
106 # inside of a shell to try things out. Re-entering the shell will
106 # inside of a shell to try things out. Re-entering the shell will
107 # restore a clean environment.
107 # restore a clean environment.
108 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
108 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
109
109
110 echo "DONE: Link node packages"
110 echo "DONE: Link node packages"
111
111
112 echo "Link bower packages"
112 echo "Link bower packages"
113 rm -fr bower_components
113 rm -fr bower_components
114 mkdir bower_components
114 mkdir bower_components
115
115
116 ln -s ${bowerComponents}/bower_components/* bower_components/
116 ln -s ${bowerComponents}/bower_components/* bower_components/
117 echo "DONE: Link bower packages"
117 echo "DONE: Link bower packages"
118 '';
118 '';
119 in super.rhodecode-enterprise-ce.override (attrs: {
119 in super.rhodecode-enterprise-ce.override (attrs: {
120
120
121 inherit
121 inherit
122 doCheck
122 doCheck
123 version;
123 version;
124 name = "rhodecode-enterprise-ce-${version}";
124 name = "rhodecode-enterprise-ce-${version}";
125 releaseName = "RhodeCodeEnterpriseCE-${version}";
125 releaseName = "RhodeCodeEnterpriseCE-${version}";
126 src = rhodecode-enterprise-ce-src;
126 src = rhodecode-enterprise-ce-src;
127
127
128 buildInputs =
128 buildInputs =
129 attrs.buildInputs ++
129 attrs.buildInputs ++
130 (with self; [
130 (with self; [
131 pkgs.nodePackages.bower
131 pkgs.nodePackages.bower
132 pkgs.nodePackages.grunt-cli
132 pkgs.nodePackages.grunt-cli
133 pkgs.subversion
133 pkgs.subversion
134 pytest-catchlog
134 pytest-catchlog
135 rhodecode-testdata
135 rhodecode-testdata
136 ]);
136 ]);
137
137
138 propagatedBuildInputs = attrs.propagatedBuildInputs ++ (with self; [
138 propagatedBuildInputs = attrs.propagatedBuildInputs ++ (with self; [
139 rhodecode-tools
139 rhodecode-tools
140 ]);
140 ]);
141
141
142 # TODO: johbo: Make a nicer way to expose the parts. Maybe
142 # TODO: johbo: Make a nicer way to expose the parts. Maybe
143 # pkgs/default.nix?
143 # pkgs/default.nix?
144 passthru = {
144 passthru = {
145 inherit
145 inherit
146 bowerComponents
146 bowerComponents
147 linkNodeAndBowerPackages
147 linkNodeAndBowerPackages
148 myPythonPackagesUnfix
148 myPythonPackagesUnfix
149 pythonLocalOverrides;
149 pythonLocalOverrides;
150 pythonPackages = self;
150 pythonPackages = self;
151 };
151 };
152
152
153 LC_ALL = "en_US.UTF-8";
153 LC_ALL = "en_US.UTF-8";
154 LOCALE_ARCHIVE =
154 LOCALE_ARCHIVE =
155 if pkgs.stdenv ? glibc
155 if pkgs.stdenv ? glibc
156 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
156 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
157 else "";
157 else "";
158
158
159 # Somewhat snappier setup of the development environment
160 # TODO: move into shell.nix
161 # TODO: think of supporting a stable path again, so that multiple shells
162 # can share it.
163 shellHook = ''
164 tmp_path=$(mktemp -d)
165 export PATH="$tmp_path/bin:$PATH"
166 export PYTHONPATH="$tmp_path/${self.python.sitePackages}:$PYTHONPATH"
167 mkdir -p $tmp_path/${self.python.sitePackages}
168 python setup.py develop --prefix $tmp_path --allow-hosts ""
169 '' + linkNodeAndBowerPackages;
170
171 preCheck = ''
159 preCheck = ''
172 export PATH="$out/bin:$PATH"
160 export PATH="$out/bin:$PATH"
173 '';
161 '';
174
162
175 postCheck = ''
163 postCheck = ''
176 rm -rf $out/lib/${self.python.libPrefix}/site-packages/pytest_pylons
164 rm -rf $out/lib/${self.python.libPrefix}/site-packages/pytest_pylons
177 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
165 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
178 '';
166 '';
179
167
180 preBuild = linkNodeAndBowerPackages + ''
168 preBuild = linkNodeAndBowerPackages + ''
181 grunt
169 grunt
182 rm -fr node_modules
170 rm -fr node_modules
183 '';
171 '';
184
172
185 postInstall = ''
173 postInstall = ''
186 # python based programs need to be wrapped
174 # python based programs need to be wrapped
187 ln -s ${self.supervisor}/bin/supervisor* $out/bin/
175 ln -s ${self.supervisor}/bin/supervisor* $out/bin/
188 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
176 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
189 ln -s ${self.PasteScript}/bin/paster $out/bin/
177 ln -s ${self.PasteScript}/bin/paster $out/bin/
190 ln -s ${self.channelstream}/bin/channelstream $out/bin/
178 ln -s ${self.channelstream}/bin/channelstream $out/bin/
191 ln -s ${self.pyramid}/bin/* $out/bin/ #*/
179 ln -s ${self.pyramid}/bin/* $out/bin/ #*/
192
180
193 # rhodecode-tools
181 # rhodecode-tools
194 # TODO: johbo: re-think this. Do the tools import anything from enterprise?
182 # TODO: johbo: re-think this. Do the tools import anything from enterprise?
195 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
183 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
196
184
197 # note that condition should be restricted when adding further tools
185 # note that condition should be restricted when adding further tools
198 for file in $out/bin/*; do #*/
186 for file in $out/bin/*; do #*/
199 wrapProgram $file \
187 wrapProgram $file \
200 --prefix PYTHONPATH : $PYTHONPATH \
188 --prefix PYTHONPATH : $PYTHONPATH \
201 --prefix PATH : $PATH \
189 --prefix PATH : $PATH \
202 --set PYTHONHASHSEED random
190 --set PYTHONHASHSEED random
203 done
191 done
204
192
205 mkdir $out/etc
193 mkdir $out/etc
206 cp configs/production.ini $out/etc
194 cp configs/production.ini $out/etc
207
195
208 echo "Writing meta information for rccontrol to nix-support/rccontrol"
196 echo "Writing meta information for rccontrol to nix-support/rccontrol"
209 mkdir -p $out/nix-support/rccontrol
197 mkdir -p $out/nix-support/rccontrol
210 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
198 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
211 echo "DONE: Meta information for rccontrol written"
199 echo "DONE: Meta information for rccontrol written"
212
200
213 # TODO: johbo: Make part of ac-tests
201 # TODO: johbo: Make part of ac-tests
214 if [ ! -f rhodecode/public/js/scripts.js ]; then
202 if [ ! -f rhodecode/public/js/scripts.js ]; then
215 echo "Missing scripts.js"
203 echo "Missing scripts.js"
216 exit 1
204 exit 1
217 fi
205 fi
218 if [ ! -f rhodecode/public/css/style.css ]; then
206 if [ ! -f rhodecode/public/css/style.css ]; then
219 echo "Missing style.css"
207 echo "Missing style.css"
220 exit 1
208 exit 1
221 fi
209 fi
222 '';
210 '';
223
211
224 });
212 });
225
213
226 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
214 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
227 inherit
215 inherit
228 doCheck
216 doCheck
229 pkgs
217 pkgs
230 pythonPackages;
218 pythonPackages;
231 };
219 };
232
220
233 };
221 };
234
222
235 rhodecode-testdata-src = sources.rhodecode-testdata or (
223 rhodecode-testdata-src = sources.rhodecode-testdata or (
236 pkgs.fetchhg {
224 pkgs.fetchhg {
237 url = "https://code.rhodecode.com/upstream/rc_testdata";
225 url = "https://code.rhodecode.com/upstream/rc_testdata";
238 rev = "v0.9.0";
226 rev = "v0.9.0";
239 sha256 = "0k0ccb7cncd6mmzwckfbr6l7fsymcympwcm948qc3i0f0m6bbg1y";
227 sha256 = "0k0ccb7cncd6mmzwckfbr6l7fsymcympwcm948qc3i0f0m6bbg1y";
240 });
228 });
241
229
242 # Apply all overrides and fix the final package set
230 # Apply all overrides and fix the final package set
243 myPythonPackagesUnfix = with pkgs.lib;
231 myPythonPackagesUnfix = with pkgs.lib;
244 (extends pythonExternalOverrides
232 (extends pythonExternalOverrides
245 (extends pythonLocalOverrides
233 (extends pythonLocalOverrides
246 (extends pythonOverrides
234 (extends pythonOverrides
247 pythonGeneratedPackages)));
235 pythonGeneratedPackages)));
248 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
236 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
249
237
250 in myPythonPackages.rhodecode-enterprise-ce
238 in myPythonPackages.rhodecode-enterprise-ce
@@ -1,57 +1,70 b''
1 { pkgs ? (import <nixpkgs> {})
1 { pkgs ? (import <nixpkgs> {})
2 , vcsserverPath ? "./../rhodecode-vcsserver"
2 , vcsserverPath ? "./../rhodecode-vcsserver"
3 , vcsserverNix ? "shell.nix"
3 , vcsserverNix ? "shell.nix"
4 , doCheck ? true
4 , doCheck ? true
5 }:
5 }:
6
6
7 let
7 let
8
8
9 # Convert vcsserverPath to absolute path.
9 # Convert vcsserverPath to absolute path.
10 vcsserverAbsPath =
10 vcsserverAbsPath =
11 if pkgs.lib.strings.hasPrefix "/" vcsserverPath then
11 if pkgs.lib.strings.hasPrefix "/" vcsserverPath then
12 builtins.toPath "${vcsserverPath}"
12 builtins.toPath "${vcsserverPath}"
13 else
13 else
14 builtins.toPath ("${builtins.getEnv "PWD"}/${vcsserverPath}");
14 builtins.toPath ("${builtins.getEnv "PWD"}/${vcsserverPath}");
15
15
16 # Import vcsserver if nix file exists, otherwise set it to null.
16 # Import vcsserver if nix file exists, otherwise set it to null.
17 vcsserver =
17 vcsserver =
18 let
18 let
19 nixFile = "${vcsserverAbsPath}/${vcsserverNix}";
19 nixFile = "${vcsserverAbsPath}/${vcsserverNix}";
20 in
20 in
21 if pkgs.lib.pathExists "${nixFile}" then
21 if pkgs.lib.pathExists "${nixFile}" then
22 builtins.trace
22 builtins.trace
23 "Using local vcsserver from ${nixFile}"
23 "Using local vcsserver from ${nixFile}"
24 import "${nixFile}" {inherit pkgs;}
24 import "${nixFile}" {inherit pkgs;}
25 else
25 else
26 null;
26 null;
27
27
28 hasVcsserver = !isNull vcsserver;
28 hasVcsserver = !isNull vcsserver;
29
29
30 enterprise = import ./default.nix {
30 enterprise-ce = import ./default.nix {
31 inherit pkgs doCheck;
31 inherit pkgs doCheck;
32 };
32 };
33
33
34 pythonPackages = enterprise.pythonPackages;
34 ce-pythonPackages = enterprise-ce.pythonPackages;
35
35
36 in enterprise.override (attrs: {
36 in enterprise-ce.override (attrs: {
37 # Avoid that we dump any sources into the store when entering the shell and
37 # Avoid that we dump any sources into the store when entering the shell and
38 # make development a little bit more convenient.
38 # make development a little bit more convenient.
39 src = null;
39 src = null;
40
40
41 buildInputs =
41 buildInputs =
42 attrs.buildInputs ++
42 attrs.buildInputs ++
43 pkgs.lib.optionals (hasVcsserver) vcsserver.propagatedNativeBuildInputs ++
43 pkgs.lib.optionals (hasVcsserver) vcsserver.propagatedNativeBuildInputs ++
44 (with pythonPackages; [
44 (with ce-pythonPackages; [
45 bumpversion
45 bumpversion
46 invoke
46 invoke
47 ipdb
47 ipdb
48 ]);
48 ]);
49
49
50 shellHook = attrs.shellHook +
50 # Somewhat snappier setup of the development environment
51 # TODO: think of supporting a stable path again, so that multiple shells
52 # can share it.
53 postShellHook = ''
54 # Custom prompt to distinguish from other dev envs.
55 export PS1="\n\[\033[1;32m\][CE-shell:\w]$\[\033[0m\] "
56
57 tmp_path=$(mktemp -d)
58 export PATH="$tmp_path/bin:$PATH"
59 export PYTHONPATH="$tmp_path/${ce-pythonPackages.python.sitePackages}:$PYTHONPATH"
60 mkdir -p $tmp_path/${ce-pythonPackages.python.sitePackages}
61 python setup.py develop --prefix $tmp_path --allow-hosts ""
62 '' + enterprise-ce.linkNodeAndBowerPackages +
51 pkgs.lib.strings.optionalString (hasVcsserver) ''
63 pkgs.lib.strings.optionalString (hasVcsserver) ''
52 # Setup the vcsserver development egg.
64 # Setup the vcsserver development egg.
53 pushd ${vcsserverAbsPath}
65 pushd ${vcsserverAbsPath}
54 python setup.py develop --prefix $tmp_path --allow-hosts ""
66 python setup.py develop --prefix $tmp_path --allow-hosts ""
55 popd
67 popd
56 '';
68 '';
69
57 })
70 })
General Comments 0
You need to be logged in to leave comments. Login now