lol

ruby: install ri docs to devdoc output

This allows getting access to Ruby documentation through ri by doing

nix-shell -p ruby ruby.devdoc

or by installing the ruby.devdoc package.

A setup hook will add a shim to LOAD_PATH to point ri to the devdoc
output instead of out.

+46 -1
+21 -1
pkgs/development/interpreters/ruby/default.nix
··· 61 61 # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds. 62 62 NROFF = if docSupport then "${groff}/bin/nroff" else null; 63 63 64 + outputs = [ "out" ] ++ lib.optional docSupport "devdoc"; 65 + 64 66 nativeBuildInputs = [ autoreconfHook bison ] 65 67 ++ (op docSupport groff) 66 68 ++ op (stdenv.buildPlatform != stdenv.hostPlatform) buildPackages.ruby; ··· 115 117 ++ op (stdenv.hostPlatform != stdenv.buildPlatform) 116 118 "--with-baseruby=${buildRuby}"; 117 119 120 + preConfigure = opString docSupport '' 121 + configureFlagsArray+=("--with-ridir=$devdoc/share/ri") 122 + ''; 123 + 118 124 # fails with "16993 tests, 2229489 assertions, 105 failures, 14 errors, 89 skips" 119 125 # mostly TZ- and patch-related tests 120 126 # TZ- failures are caused by nix sandboxing, I didn't investigate others ··· 143 149 cat > $out/nix-support/setup-hook <<EOF 144 150 addGemPath() { 145 151 addToSearchPath GEM_PATH \$1/${passthru.gemPath} 152 + } 153 + addRubyLibPath() { 154 + addToSearchPath RUBYLIB \$1/lib/ruby/site_ruby 155 + addToSearchPath RUBYLIB \$1/lib/ruby/site_ruby/${ver.libDir} 156 + addToSearchPath RUBYLIB \$1/lib/ruby/site_ruby/${ver.libDir}/${stdenv.targetPlatform.system} 146 157 } 147 158 148 159 addEnvHooks "$hostOffset" addGemPath 160 + addEnvHooks "$hostOffset" addRubyLibPath 149 161 EOF 150 - '' + opString useRailsExpress '' 162 + 151 163 rbConfig=$(find $out/lib/ruby -name rbconfig.rb) 164 + '' + opString docSupport '' 165 + # Prevent the docs from being included in the closure 166 + sed -i "s|\$(DESTDIR)$devdoc|\$(datarootdir)/\$(RI_BASE_NAME)|" $rbConfig 167 + sed -i "s|'--with-ridir=$devdoc/share/ri'||" $rbConfig 152 168 169 + # Add rbconfig shim so ri can find docs 170 + mkdir -p $devdoc/lib/ruby/site_ruby 171 + cp ${./rbconfig.rb} $devdoc/lib/ruby/site_ruby/rbconfig.rb 172 + '' + opString useRailsExpress '' 153 173 # Prevent the baseruby from being included in the closure. 154 174 sed -i '/^ CONFIG\["BASERUBY"\]/d' $rbConfig 155 175 sed -i "s|'--with-baseruby=${baseruby}/bin/ruby'||" $rbConfig
+25
pkgs/development/interpreters/ruby/rbconfig.rb
··· 1 + # This is a shim around whatever real rbconfig.rb is in the LOAD_PATH, 2 + # so that RbConfig::CONFIG["ridir"] can be overridden to point to the 3 + # custom location of the ri docs, without the main derivation having 4 + # those docs in its closure. 5 + 6 + MY_PATH = File.realpath(__FILE__) 7 + 8 + candidates = $LOAD_PATH.map { |dir| File.join(dir, "rbconfig.rb") } 9 + 10 + # First, drop everything _before_ this file in the LOAD_PATH, just on 11 + # the off-chance somebody is composing shims like this for some reason. 12 + candidates.drop_while { |c| !File.exist?(c) || File.realpath(c) != MY_PATH } 13 + 14 + # Now, the wrapped rbconfig.rb is the next rbconfig.rb in the LOAD_PATH 15 + # that isn't this same file. (Yes, duplicate LOAD_PATH entries are a 16 + # thing we have to deal with.) 17 + next_rbconfig = candidates.find { |c| 18 + File.exist?(c) && File.realpath(c) != MY_PATH 19 + } 20 + 21 + # Load the wrapped rbconfig.rb 22 + require next_rbconfig 23 + 24 + # Now we have RbConfig, and can modify it for our own ends. 25 + RbConfig::CONFIG["ridir"] = File.expand_path("../../../share/ri", __dir__)