1{ stdenv, lib, fetchurl, fetchFromSavannah, fetchFromGitHub
2, zlib, openssl, gdbm, ncurses, readline, groff, libyaml, libffi, autoreconfHook, bison
3, autoconf, darwin ? null
4} @ args:
5
6let
7 op = stdenv.lib.optional;
8 ops = stdenv.lib.optionals;
9 opString = stdenv.lib.optionalString;
10 patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; };
11 config = import ./config.nix { inherit fetchFromSavannah; };
12
13 generic = { majorVersion, minorVersion, teenyVersion, patchLevel, sha256 }: let
14 versionNoPatch = "${majorVersion}.${minorVersion}.${teenyVersion}";
15 version = "${versionNoPatch}-p${patchLevel}";
16 fullVersionName = if patchLevel != "0" && stdenv.lib.versionOlder versionNoPatch "2.1"
17 then version
18 else versionNoPatch;
19 tag = "v" + stdenv.lib.replaceChars ["." "p" "-"] ["_" "_" ""] fullVersionName;
20 isRuby21 = majorVersion == "2" && minorVersion == "1";
21 baseruby = self.override { useRailsExpress = false; };
22 self = lib.makeOverridable (
23 { stdenv, lib, fetchurl, fetchFromSavannah, fetchFromGitHub
24 , useRailsExpress ? true
25 , zlib, zlibSupport ? true
26 , openssl, opensslSupport ? true
27 , gdbm, gdbmSupport ? true
28 , ncurses, readline, cursesSupport ? true
29 , groff, docSupport ? false
30 , libyaml, yamlSupport ? true
31 , libffi, fiddleSupport ? true
32 , autoreconfHook, bison, autoconf
33 , darwin ? null
34 }:
35 stdenv.mkDerivation rec {
36 inherit version;
37
38 name = "ruby-${version}";
39
40 src = if useRailsExpress then fetchFromGitHub {
41 owner = "ruby";
42 repo = "ruby";
43 rev = tag;
44 sha256 = sha256.git;
45 } else fetchurl {
46 url = "http://cache.ruby-lang.org/pub/ruby/${majorVersion}.${minorVersion}/ruby-${fullVersionName}.tar.gz";
47 sha256 = sha256.src;
48 };
49
50 # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
51 NROFF = "${groff}/bin/nroff";
52
53 buildInputs = ops useRailsExpress [ autoreconfHook bison ]
54 ++ (op fiddleSupport libffi)
55 ++ (ops cursesSupport [ ncurses readline ])
56 ++ (op docSupport groff)
57 ++ (op zlibSupport zlib)
58 ++ (op opensslSupport openssl)
59 ++ (op gdbmSupport gdbm)
60 ++ (op yamlSupport libyaml)
61 # Looks like ruby fails to build on darwin without readline even if curses
62 # support is not enabled, so add readline to the build inputs if curses
63 # support is disabled (if it's enabled, we already have it) and we're
64 # running on darwin
65 ++ (op (!cursesSupport && stdenv.isDarwin) readline)
66 ++ (ops stdenv.isDarwin (with darwin; [ libiconv libobjc libunwind ]));
67
68 enableParallelBuilding = true;
69
70 patches = (import ./patchsets.nix {
71 inherit patchSet useRailsExpress ops patchLevel;
72 })."${versionNoPatch}";
73
74 postUnpack = opString isRuby21 ''
75 rm "$sourceRoot/enc/unicode/name2ctype.h"
76 '';
77
78 postPatch = if isRuby21 then ''
79 rm tool/config_files.rb
80 cp ${config}/config.guess tool/
81 cp ${config}/config.sub tool/
82 ''
83 else opString useRailsExpress ''
84 sed -i configure.in -e '/config.guess/d'
85 cp ${config}/config.guess tool/
86 cp ${config}/config.sub tool/
87 '';
88
89 configureFlags = ["--enable-shared" "--enable-pthread"]
90 ++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby"
91 ++ ops stdenv.isDarwin [
92 # on darwin, we have /usr/include/tk.h -- so the configure script detects
93 # that tk is installed
94 "--with-out-ext=tk"
95 # on yosemite, "generating encdb.h" will hang for a very long time without this flag
96 "--with-setjmp-type=setjmp"
97 ];
98
99 installFlags = stdenv.lib.optionalString docSupport "install-doc";
100 # Bundler tries to create this directory
101 postInstall = ''
102 # Bundler tries to create this directory
103 mkdir -pv $out/${passthru.gemPath}
104 mkdir -p $out/nix-support
105 cat > $out/nix-support/setup-hook <<EOF
106 addGemPath() {
107 addToSearchPath GEM_PATH \$1/${passthru.gemPath}
108 }
109
110 envHooks+=(addGemPath)
111 EOF
112 '' + opString useRailsExpress ''
113 rbConfig=$(find $out/lib/ruby -name rbconfig.rb)
114
115 # Prevent the baseruby from being included in the closure.
116 sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig
117 sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig
118 '';
119
120 meta = {
121 license = stdenv.lib.licenses.ruby;
122 homepage = "http://www.ruby-lang.org/en/";
123 description = "The Ruby language";
124 platforms = stdenv.lib.platforms.all;
125 };
126
127 passthru = rec {
128 inherit majorVersion minorVersion teenyVersion patchLevel;
129 rubyEngine = "ruby";
130 baseRuby = baseruby;
131 libPath = "lib/${rubyEngine}/${versionNoPatch}";
132 gemPath = "lib/${rubyEngine}/gems/${versionNoPatch}";
133 };
134 }
135 ) args; in self;
136
137in {
138 ruby_1_9_3 = generic {
139 majorVersion = "1";
140 minorVersion = "9";
141 teenyVersion = "3";
142 patchLevel = "551";
143 sha256 = {
144 src = "1s2ibg3s2iflzdv7rfxi1qqkvdbn2dq8gxdn0nxrb77ls5ffanxv";
145 git = "1r9xzzxmci2ajb34qb4y1w424mz878zdgzxkfp9w60agldxnb36s";
146 };
147 };
148
149 ruby_2_0_0 = generic {
150 majorVersion = "2";
151 minorVersion = "0";
152 teenyVersion = "0";
153 patchLevel = "647";
154 sha256 = {
155 src = "1v2vbvydarcx5801gx9lc6gr6dfi0i7qbzwhsavjqbn79rdsz2n8";
156 git = "186pf4q9xymzn4zn1sjppl1skrl5f0159ixz5cz8g72dmmynq3g3";
157 };
158 };
159
160 ruby_2_1_0 = generic {
161 majorVersion = "2";
162 minorVersion = "1";
163 teenyVersion = "0";
164 patchLevel = "0";
165 sha256 = {
166 src = "17fhfbw8sr13rxfn58wvrhk2f5i88lkna2afn3gdjvprd8gyqf1m";
167 git = "12sn532yvznqfz85378ys0b9ggmj7w8ddhzc1pnnlx7mbyy7r2hx";
168 };
169 };
170
171 ruby_2_1_1 = generic {
172 majorVersion = "2";
173 minorVersion = "1";
174 teenyVersion = "1";
175 patchLevel = "0";
176 sha256 = {
177 src = "0hc9x3mazyvnk94gs19q8mbnanlzk8mv0hii77slkvc8mqqxyhy8";
178 git = "1v2ffvyd0xx1h1qd70431zczhvsdiyyw5kjxih4rszd5avzh5grl";
179 };
180 };
181
182 ruby_2_1_2 = generic {
183 majorVersion = "2";
184 minorVersion = "1";
185 teenyVersion = "2";
186 patchLevel = "353";
187 sha256 = {
188 src = "0db6krc2bd7yha8p96lcqrahjpsz7g7abhni134g708sh53n8apj";
189 git = "14f8w3zwngnxsgigffh6h9z3ng53xq8mk126xmwrsmz9n3ypm6l0";
190 };
191 };
192
193 ruby_2_1_3 = generic {
194 majorVersion = "2";
195 minorVersion = "1";
196 teenyVersion = "3";
197 patchLevel = "0";
198 sha256 = {
199 src = "00bz6jcbxgnllplk4b9lnyc3w8yd3pz5rn11rmca1s8cn6vvw608";
200 git = "1pnam9jry2l2mbji3gvrbb7jyisxl99xjz6l1qrccwnfinxxbmhv";
201 };
202 };
203
204 ruby_2_1_6 = generic {
205 majorVersion = "2";
206 minorVersion = "1";
207 teenyVersion = "6";
208 patchLevel = "0";
209 sha256 = {
210 src = "1r4bs8lfwsypbcf8j2lpv3by40729vp5mh697njizj97fjp644qy";
211 git = "18kbjsbmgv6l3p1qxgmjnhh4jl7xdk3c20ycjpp62vrhq7pyzjsm";
212 };
213 };
214
215 ruby_2_1_7 = generic {
216 majorVersion = "2";
217 minorVersion = "1";
218 teenyVersion = "7";
219 patchLevel = "0";
220 sha256 = {
221 src = "10fxlqmpbq9407zgsx060q22yj4zq6c3czbf29h7xk1rmjb1b77m";
222 git = "1fmbqd943akqjwsfbj9bg394ac46qmpavm8s0kv2w87rflrjcjfb";
223 };
224 };
225
226 ruby_2_2_0 = generic {
227 majorVersion = "2";
228 minorVersion = "2";
229 teenyVersion = "0";
230 patchLevel = "0";
231 sha256 = {
232 src = "1z2092fbpc2qkv1j3yj7jdz7qwvqpxqpmcnkphpjcpgvmfaf6wbn";
233 git = "1w7rr2nq1bbw6aiagddzlrr3rl95kk33x4pv6570nm072g55ybpi";
234 };
235 };
236
237 ruby_2_2_2 = generic {
238 majorVersion = "2";
239 minorVersion = "2";
240 teenyVersion = "2";
241 patchLevel = "0";
242 sha256 = {
243 src = "0i4v7l8pnam0by2cza12zldlhrffqchwb2m9shlnp7j2gqqhzz2z";
244 git = "08mw1ql2ghy483cp8xzzm78q17simn4l6phgm2gah7kjh9y3vbrn";
245 };
246 };
247
248 ruby_2_2_3 = generic {
249 majorVersion = "2";
250 minorVersion = "2";
251 teenyVersion = "3";
252 patchLevel = "0";
253 sha256 = {
254 src = "1kpdf7f8pw90n5bckpl2idzggk0nn0240ah92sj4a1w6k4pmyyfz";
255 git = "1ssq3c23ay57ypfis47y2n817hfmb71w0xrdzp57j6bv12jqmgrx";
256 };
257 };
258
259 ruby_2_3_0 = generic {
260 majorVersion = "2";
261 minorVersion = "3";
262 teenyVersion = "0";
263 patchLevel = "0";
264 sha256 = {
265 # src = "1ssq3c23ay57ypfis47y2n817hfmb71w0xrdzp57j6bv12jqmgrx";
266 src = "01z5cya4a7y751d4pb3aak5qcwmmvnwkbgz9z171p8hsbw7acnxs";
267 git = "0nl0pp96m0jxi422mqx09jqn9bff90pzz0xxa0ikrx7by0g00npg";
268 };
269 };
270}