1{ stdenv, lib, fetchurl, fetchgit, fetchFromGitHub
2, zlib, zlibSupport ? true
3, openssl, opensslSupport ? true
4, gdbm, gdbmSupport ? true
5, ncurses, readline, cursesSupport ? true
6, groff, docSupport ? false
7, libyaml, yamlSupport ? true
8, libffi, fiddleSupport ? true
9, ruby_2_2_0, autoreconfHook, bison, useRailsExpress ? true
10, libiconv, libobjc, libunwind
11}:
12
13let
14 op = stdenv.lib.optional;
15 ops = stdenv.lib.optionals;
16 patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; };
17 config = import ./config.nix fetchgit;
18 baseruby = ruby_2_2_0.override { useRailsExpress = false; };
19in
20
21stdenv.mkDerivation rec {
22 version = with passthru; "${majorVersion}.${minorVersion}.${teenyVersion}-p${patchLevel}";
23
24 name = "ruby-${version}";
25
26 src = if useRailsExpress then fetchFromGitHub {
27 owner = "ruby";
28 repo = "ruby";
29 rev = "v2_2_0";
30 sha256 = "1w7rr2nq1bbw6aiagddzlrr3rl95kk33x4pv6570nm072g55ybpi";
31 } else fetchurl {
32 url = "http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.0.tar.gz";
33 sha256 = "1z2092fbpc2qkv1j3yj7jdz7qwvqpxqpmcnkphpjcpgvmfaf6wbn";
34 };
35
36 # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
37 NROFF = "${groff}/bin/nroff";
38
39 buildInputs = ops useRailsExpress [ autoreconfHook bison ]
40 ++ (op fiddleSupport libffi)
41 ++ (ops cursesSupport [ ncurses readline ])
42 ++ (op docSupport groff)
43 ++ (op zlibSupport zlib)
44 ++ (op opensslSupport openssl)
45 ++ (op gdbmSupport gdbm)
46 ++ (op yamlSupport libyaml)
47 # Looks like ruby fails to build on darwin without readline even if curses
48 # support is not enabled, so add readline to the build inputs if curses
49 # support is disabled (if it's enabled, we already have it) and we're
50 # running on darwin
51 ++ (op (!cursesSupport && stdenv.isDarwin) readline)
52 ++ (ops stdenv.isDarwin [ libiconv libobjc libunwind ]);
53
54 enableParallelBuilding = true;
55
56 patches = ops useRailsExpress [
57 "${patchSet}/patches/ruby/2.2.0/railsexpress/01-zero-broken-tests.patch"
58 "${patchSet}/patches/ruby/2.2.0/railsexpress/02-improve-gc-stats.patch"
59 "${patchSet}/patches/ruby/2.2.0/railsexpress/03-display-more-detailed-stack-trace.patch"
60 "${patchSet}/patches/ruby/2.2.0/railsexpress/04-backport-401c8bb.patch"
61 "${patchSet}/patches/ruby/2.2.0/railsexpress/05-fix-packed-bitfield-compat-warning-for-older-gccs.patch"
62 ];
63
64 postPatch = ops useRailsExpress ''
65 sed -i configure.in -e '/config.guess/d'
66 cp ${config}/config.guess tool/
67 cp ${config}/config.sub tool/
68 '';
69
70 configureFlags = ["--enable-shared" ]
71 ++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby"
72 # on darwin, we have /usr/include/tk.h -- so the configure script detects
73 # that tk is installed
74 ++ ( if stdenv.isDarwin then [ "--with-out-ext=tk " ] else [ ]);
75
76 installFlags = stdenv.lib.optionalString docSupport "install-doc";
77 # Bundler tries to create this directory
78 postInstall = ''
79 # Bundler tries to create this directory
80 mkdir -pv $out/${passthru.gemPath}
81 mkdir -p $out/nix-support
82 cat > $out/nix-support/setup-hook <<EOF
83 addGemPath() {
84 addToSearchPath GEM_PATH \$1/${passthru.gemPath}
85 }
86
87 envHooks+=(addGemPath)
88 EOF
89 '' + lib.optionalString useRailsExpress ''
90 rbConfig=$(find $out/lib/ruby -name rbconfig.rb)
91
92 # Prevent the baseruby from being included in the closure.
93 sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig
94 sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig
95 '';
96
97 meta = {
98 license = stdenv.lib.licenses.ruby;
99 homepage = "http://www.ruby-lang.org/en/";
100 description = "The Ruby language";
101 platforms = stdenv.lib.platforms.all;
102 };
103
104 passthru = rec {
105 majorVersion = "2";
106 minorVersion = "2";
107 teenyVersion = "0";
108 patchLevel = "0";
109 rubyEngine = "ruby";
110 libPath = "lib/${rubyEngine}/${majorVersion}.${minorVersion}.${teenyVersion}";
111 gemPath = "lib/${rubyEngine}/gems/${majorVersion}.${minorVersion}.${teenyVersion}";
112 };
113}