at v192 124 lines 4.7 kB view raw
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_6, 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 { inherit fetchFromSavannah; }; 18 baseruby = ruby_2_1_6.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_1_6"; 30 sha256 = "18kbjsbmgv6l3p1qxgmjnhh4jl7xdk3c20ycjpp62vrhq7pyzjsm"; 31 } else fetchurl { 32 url = "http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz"; 33 sha256 = "1r4bs8lfwsypbcf8j2lpv3by40729vp5mh697njizj97fjp644qy"; 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 # Fix a build failure on systems with nix store optimisation. 57 # (The build process attempted to copy file a overwriting file b, where a and 58 # b are hard-linked, which results in cp returning a non-zero exit code.) 59 # https://github.com/NixOS/nixpkgs/issues/4266 60 postUnpack = ''rm "$sourceRoot/enc/unicode/name2ctype.h"''; 61 62 patches = ops useRailsExpress [ 63 "${patchSet}/patches/ruby/2.1.6/railsexpress/01-zero-broken-tests.patch" 64 "${patchSet}/patches/ruby/2.1.6/railsexpress/02-improve-gc-stats.patch" 65 "${patchSet}/patches/ruby/2.1.6/railsexpress/03-display-more-detailed-stack-trace.patch" 66 "${patchSet}/patches/ruby/2.1.6/railsexpress/04-show-full-backtrace-on-stack-overflow.patch" 67 "${patchSet}/patches/ruby/2.1.6/railsexpress/05-funny-falcon-stc-density.patch" 68 "${patchSet}/patches/ruby/2.1.6/railsexpress/06-funny-falcon-stc-pool-allocation.patch" 69 "${patchSet}/patches/ruby/2.1.6/railsexpress/07-aman-opt-aset-aref-str.patch" 70 "${patchSet}/patches/ruby/2.1.6/railsexpress/08-funny-falcon-method-cache.patch" 71 "${patchSet}/patches/ruby/2.1.6/railsexpress/09-heap-dump-support.patch" 72 ]; 73 74 # Ruby >= 2.1.0 tries to download config.{guess,sub} 75 postPatch = '' 76 rm tool/config_files.rb 77 cp ${config}/config.guess tool/ 78 cp ${config}/config.sub tool/ 79 ''; 80 81 configureFlags = ["--enable-shared" ] 82 ++ op useRailsExpress "--with-baseruby=${baseruby}/bin/ruby" 83 # on darwin, we have /usr/include/tk.h -- so the configure script detects 84 # that tk is installed 85 ++ ( if stdenv.isDarwin then [ "--with-out-ext=tk " ] else [ ]); 86 87 installFlags = stdenv.lib.optionalString docSupport "install-doc"; 88 # Bundler tries to create this directory 89 postInstall = '' 90 # Bundler tries to create this directory 91 mkdir -pv $out/${passthru.gemPath} 92 mkdir -p $out/nix-support 93 cat > $out/nix-support/setup-hook <<EOF 94 addGemPath() { 95 addToSearchPath GEM_PATH \$1/${passthru.gemPath} 96 } 97 98 envHooks+=(addGemPath) 99 EOF 100 '' + lib.optionalString useRailsExpress '' 101 rbConfig=$(find $out/lib/ruby -name rbconfig.rb) 102 103 # Prevent the baseruby from being included in the closure. 104 sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig 105 sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig 106 ''; 107 108 meta = { 109 license = stdenv.lib.licenses.ruby; 110 homepage = "http://www.ruby-lang.org/en/"; 111 description = "The Ruby language"; 112 platforms = stdenv.lib.platforms.all; 113 }; 114 115 passthru = rec { 116 majorVersion = "2"; 117 minorVersion = "1"; 118 teenyVersion = "6"; 119 patchLevel = "0"; 120 rubyEngine = "ruby"; 121 libPath = "lib/${rubyEngine}/${majorVersion}.${minorVersion}.${teenyVersion}"; 122 gemPath = "lib/${rubyEngine}/gems/${majorVersion}.${minorVersion}.${teenyVersion}"; 123 }; 124}