1{ stdenv, lib, fetchurl, fetchFromGitHub
2, zlib, zlibSupport ? true
3, openssl, opensslSupport ? true
4, gdbm, gdbmSupport ? true
5, ncurses, readline, cursesSupport ? true
6, groff, docSupport ? false
7, ruby_1_8_7, autoreconfHook, bison, useRailsExpress ? true
8}:
9
10let
11 op = stdenv.lib.optional;
12 ops = stdenv.lib.optionals;
13 patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; };
14 baseruby = ruby_1_8_7.override { useRailsExpress = false; };
15in
16
17stdenv.mkDerivation rec {
18 version = with passthru; "${majorVersion}.${minorVersion}.${teenyVersion}-p${patchLevel}";
19
20 name = "ruby-${version}";
21
22 src = if useRailsExpress then fetchFromGitHub {
23 owner = "ruby";
24 repo = "ruby";
25 rev = "v1_8_7_${passthru.patchLevel}";
26 sha256 = "1xddhxr0j26hpxfixvhqdscwk2ri846w2129fcfwfjzvy19igswx";
27 } else fetchurl {
28 url = "http://cache.ruby-lang.org/pub/ruby/1.8/${name}.tar.bz2";
29 sha256 = "1qq7khilwkayrhwmzlxk83scrmiqfi7lgsn4c63znyvz2c1lgqxl";
30 };
31
32 # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
33 NROFF = "${groff}/bin/nroff";
34
35 buildInputs = ops useRailsExpress [ autoreconfHook bison ]
36 ++ (ops cursesSupport [ ncurses readline ] )
37 ++ (op docSupport groff )
38 ++ (op zlibSupport zlib)
39 ++ (op opensslSupport openssl)
40 ++ (op gdbmSupport gdbm);
41
42 patches = ops useRailsExpress [
43 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/01-ignore-generated-files.patch"
44 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/02-fix-tests-for-osx.patch"
45 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/03-sigvtalrm-fix.patch"
46 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/04-railsbench-gc-patch.patch"
47 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/05-display-full-stack-trace.patch"
48 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/06-better-source-file-tracing.patch"
49 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/07-heap-dump-support.patch"
50 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/08-fork-support-for-gc-logging.patch"
51 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/09-track-malloc-size.patch"
52 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/10-track-object-allocation.patch"
53 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/11-expose-heap-slots.patch"
54 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/12-fix-heap-size-growth-logic.patch"
55 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/13-heap-slot-size.patch"
56 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/14-add-trace-stats-enabled-methods.patch"
57 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/15-track-live-dataset-size.patch"
58 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/16-add-object-size-information-to-heap-dump.patch"
59 "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/17-caller-for-all-threads.patch"
60 ];
61
62 configureFlags = [ "--enable-shared" "--enable-pthread" ]
63 # Without this fails due to not finding X11/Xlib.h
64 # Not sure why this isn't required on Linux
65 ++ ops stdenv.isDarwin [ "--without-tcl" "--without-tk" ]
66 ++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby";
67
68 installFlags = stdenv.lib.optionalString docSupport "install-doc";
69
70 postInstall = ''
71 # Bundler tries to create this directory
72 mkdir -pv $out/${passthru.gemPath}
73 mkdir -p $out/nix-support
74 cat > $out/nix-support/setup-hook <<EOF
75 addGemPath() {
76 addToSearchPath GEM_PATH \$1/${passthru.gemPath}
77 }
78
79 envHooks+=(addGemPath)
80 EOF
81 '' + lib.optionalString useRailsExpress ''
82 rbConfig=$(find $out/lib/ruby -name rbconfig.rb)
83
84 # Prevent the baseruby from being included in the closure.
85 sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig
86 sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig
87 '';
88
89 meta = {
90 license = stdenv.lib.licenses.ruby;
91 homepage = "http://www.ruby-lang.org/en/";
92 description = "The Ruby language";
93 };
94
95 passthru = rec {
96 majorVersion = "1";
97 minorVersion = "8";
98 teenyVersion = "7";
99 patchLevel = "374";
100 rubyEngine = "ruby";
101 libPath = "lib/${rubyEngine}/${majorVersion}.${minorVersion}.${teenyVersion}";
102 gemPath = "lib/${rubyEngine}/gems/${majorVersion}.${minorVersion}.${teenyVersion}";
103 };
104}