summary refs log tree commit diff
path: root/pkgs/development/interpreters/ruby/ruby-1.8.7.nix
blob: 3c2ea71ecf2655fcf47e6de89a350f7e19d28acf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ stdenv, lib, fetchurl, fetchFromGitHub
, zlib, zlibSupport ? true
, openssl, opensslSupport ? true
, gdbm, gdbmSupport ? true
, ncurses, readline, cursesSupport ? true
, groff, docSupport ? false
, ruby_1_8_7, autoreconfHook, bison, useRailsExpress ? true
}:

let
  op = stdenv.lib.optional;
  ops = stdenv.lib.optionals;
  patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; };
  baseruby = ruby_1_8_7.override { useRailsExpress = false; };
in

stdenv.mkDerivation rec {
  version = with passthru; "${majorVersion}.${minorVersion}.${teenyVersion}-p${patchLevel}";

  name = "ruby-${version}";

  src = if useRailsExpress then fetchFromGitHub {
    owner  = "ruby";
    repo   = "ruby";
    rev    = "v1_8_7_${passthru.patchLevel}";
    sha256 = "1xddhxr0j26hpxfixvhqdscwk2ri846w2129fcfwfjzvy19igswx";
  } else fetchurl {
    url = "http://cache.ruby-lang.org/pub/ruby/1.8/${name}.tar.bz2";
    sha256 = "1qq7khilwkayrhwmzlxk83scrmiqfi7lgsn4c63znyvz2c1lgqxl";
  };

  # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds.
  NROFF = "${groff}/bin/nroff";

  buildInputs = ops useRailsExpress [ autoreconfHook bison ]
    ++ (ops cursesSupport [ ncurses readline ] )
    ++ (op docSupport groff )
    ++ (op zlibSupport zlib)
    ++ (op opensslSupport openssl)
    ++ (op gdbmSupport gdbm);

  patches = ops useRailsExpress [
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/01-ignore-generated-files.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/02-fix-tests-for-osx.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/03-sigvtalrm-fix.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/04-railsbench-gc-patch.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/05-display-full-stack-trace.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/06-better-source-file-tracing.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/07-heap-dump-support.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/08-fork-support-for-gc-logging.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/09-track-malloc-size.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/10-track-object-allocation.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/11-expose-heap-slots.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/12-fix-heap-size-growth-logic.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/13-heap-slot-size.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/14-add-trace-stats-enabled-methods.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/15-track-live-dataset-size.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/16-add-object-size-information-to-heap-dump.patch"
    "${patchSet}/patches/ruby/1.8.7/p374/railsexpress/17-caller-for-all-threads.patch"
  ];

  configureFlags = [ "--enable-shared" "--enable-pthread" ]
    ++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby";

  installFlags = stdenv.lib.optionalString docSupport "install-doc";

  postInstall = ''
    # Bundler tries to create this directory
    mkdir -pv $out/${passthru.gemPath}
    mkdir -p $out/nix-support
    cat > $out/nix-support/setup-hook <<EOF
    addGemPath() {
      addToSearchPath GEM_PATH \$1/${passthru.gemPath}
    }

    envHooks+=(addGemPath)
    EOF
  '' + lib.optionalString useRailsExpress ''
    rbConfig=$(find $out/lib/ruby -name rbconfig.rb)

    # Prevent the baseruby from being included in the closure.
    sed -i '/^  CONFIG\["BASERUBY"\]/d' $rbConfig
    sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig
  '';

  meta = {
    license = stdenv.lib.licenses.ruby;
    homepage = "http://www.ruby-lang.org/en/";
    description = "The Ruby language";
  };

  passthru = rec {
    majorVersion = "1";
    minorVersion = "8";
    teenyVersion = "7";
    patchLevel = "374";
    rubyEngine = "ruby";
    libPath = "lib/${rubyEngine}/${majorVersion}.${minorVersion}.${teenyVersion}";
    gemPath = "lib/${rubyEngine}/gems/${majorVersion}.${minorVersion}.${teenyVersion}";
  };
}