##// END OF EJS Templates
packaging: new wrapping logic on binary scripts:...
marcink -
r567:956bb6e4 default
parent child Browse files
Show More
@@ -1,178 +1,185 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 rhodecode-vcsserver
3 # This shall be as lean as possible, just producing the rhodecode-vcsserver
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 ? false
10 , doCheck ? false
11 , ...
11 , ...
12 }:
12 }:
13
13
14 let pkgs_ = (import <nixpkgs> {}); in
14 let pkgs_ = (import <nixpkgs> {}); in
15
15
16 let
16 let
17
17
18 # TODO: Currently we ignore the passed in pkgs, instead we should use it
18 # TODO: Currently we ignore the passed in pkgs, instead we should use it
19 # somehow as a base and apply overlays to it.
19 # somehow as a base and apply overlays to it.
20 pkgs = import <nixpkgs> {
20 pkgs = import <nixpkgs> {
21 overlays = [
21 overlays = [
22 (import ./pkgs/overlays.nix)
22 (import ./pkgs/overlays.nix)
23 ];
23 ];
24 inherit (pkgs_)
24 inherit (pkgs_)
25 system;
25 system;
26 };
26 };
27
27
28 # Works with the new python-packages, still can fallback to the old
28 # Works with the new python-packages, still can fallback to the old
29 # variant.
29 # variant.
30 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
30 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
31 self: basePythonPackages.override (a: { inherit self; }));
31 self: basePythonPackages.override (a: { inherit self; }));
32
32
33 # Evaluates to the last segment of a file system path.
33 # Evaluates to the last segment of a file system path.
34 basename = path: with pkgs.lib; last (splitString "/" path);
34 basename = path: with pkgs.lib; last (splitString "/" path);
35
35
36 # source code filter used as arugment to builtins.filterSource.
36 # source code filter used as arugment to builtins.filterSource.
37 src-filter = path: type: with pkgs.lib;
37 src-filter = path: type: with pkgs.lib;
38 let
38 let
39 ext = last (splitString "." path);
39 ext = last (splitString "." path);
40 in
40 in
41 !builtins.elem (basename path) [
41 !builtins.elem (basename path) [
42 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
42 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
43 "bower_components" "node_modules"
43 "bower_components" "node_modules"
44 "build" "data" "result" "tmp"] &&
44 "build" "data" "result" "tmp"] &&
45 !builtins.elem ext ["egg-info" "pyc"] &&
45 !builtins.elem ext ["egg-info" "pyc"] &&
46 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
46 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
47 # it would still be good to restore it since we want to ignore "result-*".
47 # it would still be good to restore it since we want to ignore "result-*".
48 !hasPrefix "result" path;
48 !hasPrefix "result" path;
49
49
50 sources =
50 sources =
51 let
51 let
52 inherit (pkgs.lib) all isString attrValues;
52 inherit (pkgs.lib) all isString attrValues;
53 sourcesConfig = pkgs.config.rc.sources or {};
53 sourcesConfig = pkgs.config.rc.sources or {};
54 in
54 in
55 # Ensure that sources are configured as strings. Using a path
55 # Ensure that sources are configured as strings. Using a path
56 # would result in a copy into the nix store.
56 # would result in a copy into the nix store.
57 assert all isString (attrValues sourcesConfig);
57 assert all isString (attrValues sourcesConfig);
58 sourcesConfig;
58 sourcesConfig;
59
59
60 version = builtins.readFile "${rhodecode-vcsserver-src}/vcsserver/VERSION";
60 version = builtins.readFile "${rhodecode-vcsserver-src}/vcsserver/VERSION";
61 rhodecode-vcsserver-src = builtins.filterSource src-filter ./.;
61 rhodecode-vcsserver-src = builtins.filterSource src-filter ./.;
62
62
63 pythonLocalOverrides = self: super: {
63 pythonLocalOverrides = self: super: {
64 rhodecode-vcsserver =
64 rhodecode-vcsserver =
65 let
65 let
66 releaseName = "RhodeCodeVCSServer-${version}";
66 releaseName = "RhodeCodeVCSServer-${version}";
67 in super.rhodecode-vcsserver.override (attrs: {
67 in super.rhodecode-vcsserver.override (attrs: {
68 inherit
68 inherit
69 doCheck
69 doCheck
70 version;
70 version;
71
71
72 name = "rhodecode-vcsserver-${version}";
72 name = "rhodecode-vcsserver-${version}";
73 releaseName = releaseName;
73 releaseName = releaseName;
74 src = rhodecode-vcsserver-src;
74 src = rhodecode-vcsserver-src;
75 dontStrip = true; # prevent strip, we don't need it.
75 dontStrip = true; # prevent strip, we don't need it.
76
76
77 # expose following attributed outside
77 # expose following attributed outside
78 passthru = {
78 passthru = {
79 pythonPackages = self;
79 pythonPackages = self;
80 };
80 };
81
81
82 propagatedBuildInputs =
82 propagatedBuildInputs =
83 attrs.propagatedBuildInputs or [] ++ [
83 attrs.propagatedBuildInputs or [] ++ [
84 pkgs.git
84 pkgs.git
85 pkgs.subversion
85 pkgs.subversion
86 ];
86 ];
87
87
88 # set some default locale env variables
88 # set some default locale env variables
89 LC_ALL = "en_US.UTF-8";
89 LC_ALL = "en_US.UTF-8";
90 LOCALE_ARCHIVE =
90 LOCALE_ARCHIVE =
91 if pkgs.stdenv.isLinux
91 if pkgs.stdenv.isLinux
92 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
92 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
93 else "";
93 else "";
94
94
95 # Add bin directory to path so that tests can find 'vcsserver'.
95 # Add bin directory to path so that tests can find 'vcsserver'.
96 preCheck = ''
96 preCheck = ''
97 export PATH="$out/bin:$PATH"
97 export PATH="$out/bin:$PATH"
98 '';
98 '';
99
99
100 # custom check phase for testing
100 # custom check phase for testing
101 checkPhase = ''
101 checkPhase = ''
102 runHook preCheck
102 runHook preCheck
103 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=vcsserver --cov-report=term-missing vcsserver
103 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=vcsserver --cov-report=term-missing vcsserver
104 runHook postCheck
104 runHook postCheck
105 '';
105 '';
106
106
107 postCheck = ''
107 postCheck = ''
108 echo "Cleanup of vcsserver/tests"
108 echo "Cleanup of vcsserver/tests"
109 rm -rf $out/lib/${self.python.libPrefix}/site-packages/vcsserver/tests
109 rm -rf $out/lib/${self.python.libPrefix}/site-packages/vcsserver/tests
110 '';
110 '';
111
111
112 postInstall = ''
112 postInstall = ''
113 echo "Writing vcsserver meta information for rccontrol to nix-support/rccontrol"
113 echo "Writing vcsserver meta information for rccontrol to nix-support/rccontrol"
114 mkdir -p $out/nix-support/rccontrol
114 mkdir -p $out/nix-support/rccontrol
115 cp -v vcsserver/VERSION $out/nix-support/rccontrol/version
115 cp -v vcsserver/VERSION $out/nix-support/rccontrol/version
116 echo "DONE: vcsserver meta information for rccontrol written"
116 echo "DONE: vcsserver meta information for rccontrol written"
117
117
118 mkdir -p $out/etc
118 mkdir -p $out/etc
119 cp configs/production.ini $out/etc
119 cp configs/production.ini $out/etc
120 echo "DONE: saved vcsserver production.ini into $out/etc"
120 echo "DONE: saved vcsserver production.ini into $out/etc"
121
121
122 # python based programs need to be wrapped
122 # python based programs need to be wrapped
123 mkdir -p $out/bin
123 mkdir -p $out/bin
124 ln -s ${self.python}/bin/python $out/bin
124 ln -s ${self.python}/bin/python $out/bin/
125 ln -s ${self.pyramid}/bin/* $out/bin/
126 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
125 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
126 ln -s ${self.pyramid}/bin/prequest $out/bin/
127 ln -s ${self.pyramid}/bin/pserve $out/bin/
127
128
128 # Symlink version control utilities
129 # Symlink version control utilities
129 # We ensure that always the correct version is available as a symlink.
130 # We ensure that always the correct version is available as a symlink.
130 # So that users calling them via the profile path will always use the
131 # So that users calling them via the profile path will always use the
131 # correct version.
132 # correct version. Wrapping is required so those can "import"
133 # vcsserver python hooks.
132
134
133 ln -s ${pkgs.git}/bin/git $out/bin
135 ln -s ${pkgs.git}/bin/git $out/bin
134 ln -s ${self.mercurial}/bin/hg $out/bin
136 ln -s ${self.mercurial}/bin/hg $out/bin
135 ln -s ${pkgs.subversion}/bin/svn* $out/bin
137 ln -s ${pkgs.subversion}/bin/svn* $out/bin
138
136 echo "DONE: created symlinks into $out/bin"
139 echo "DONE: created symlinks into $out/bin"
140 DEPS="$out/bin/*"
137
141
138 for file in $out/bin/*;
142 # wrap only dependency scripts, they require to have full PYTHONPATH set
143 # to be able to import all packages
144 for file in $DEPS;
139 do
145 do
140 wrapProgram $file \
146 wrapProgram $file \
141 --prefix PATH : $PATH \
147 --prefix PATH : $PATH \
142 --prefix PYTHONPATH : $PYTHONPATH \
148 --prefix PYTHONPATH : $PYTHONPATH \
143 --set PYTHONHASHSEED random
149 --set PYTHONHASHSEED random
144 done
150 done
151
145 echo "DONE: vcsserver binary wrapping"
152 echo "DONE: vcsserver binary wrapping"
146
153
147 '';
154 '';
148
155
149 });
156 });
150 };
157 };
151
158
152 basePythonPackages = with builtins;
159 basePythonPackages = with builtins;
153 if isAttrs pythonPackages then
160 if isAttrs pythonPackages then
154 pythonPackages
161 pythonPackages
155 else
162 else
156 getAttr pythonPackages pkgs;
163 getAttr pythonPackages pkgs;
157
164
158 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
165 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
159 inherit pkgs;
166 inherit pkgs;
160 inherit (pkgs) fetchurl fetchgit fetchhg;
167 inherit (pkgs) fetchurl fetchgit fetchhg;
161 };
168 };
162
169
163 pythonVCSServerOverrides = import ./pkgs/python-packages-overrides.nix {
170 pythonVCSServerOverrides = import ./pkgs/python-packages-overrides.nix {
164 inherit pkgs basePythonPackages;
171 inherit pkgs basePythonPackages;
165 };
172 };
166
173
167
174
168 # Apply all overrides and fix the final package set
175 # Apply all overrides and fix the final package set
169 myPythonPackagesUnfix = with pkgs.lib;
176 myPythonPackagesUnfix = with pkgs.lib;
170 (extends pythonExternalOverrides
177 (extends pythonExternalOverrides
171 (extends pythonLocalOverrides
178 (extends pythonLocalOverrides
172 (extends pythonVCSServerOverrides
179 (extends pythonVCSServerOverrides
173 (extends pythonGeneratedPackages
180 (extends pythonGeneratedPackages
174 basePythonPackagesUnfix))));
181 basePythonPackagesUnfix))));
175
182
176 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
183 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
177
184
178 in myPythonPackages.rhodecode-vcsserver
185 in myPythonPackages.rhodecode-vcsserver
General Comments 0
You need to be logged in to leave comments. Login now