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