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