Created
June 15, 2021 23:14
-
-
Save fzakaria/4dc7475faf6f734fb1b510ee528a20ae to your computer and use it in GitHub Desktop.
Build any JRuby commit easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This derivation is meant to be used in the overlay or can be built | |
# by itself to test which is why you see all the defaults being set. | |
# Please consult https://github.com/looker/helltool/blob/master/docs/jruby.md | |
# for additional information. | |
{ sources ? import ./sources.nix, pkgs ? import sources.nixpkgs { } | |
, lib ? pkgs.lib, stdenv ? pkgs.stdenv, callPackage ? pkgs.callPackage | |
, fetchFromGitHub ? pkgs.fetchFromGitHub, makeWrapper ? pkgs.makeWrapper | |
, jre ? pkgs.jre, maven ? pkgs.maven, ant ? pkgs.ant }: | |
let | |
# The version number here is whatever is reported by the RUBY_VERSION string | |
# ❯ jruby -e "puts RUBY_VERSION" | |
# 2.5.7 | |
rubyVersion = callPackage | |
"${sources.nixpkgs.outPath}/pkgs/development/interpreters/ruby/ruby-version.nix" | |
{ } "2" "5" "7" ""; | |
jrubyVersion = "9.2.16.0"; | |
jruby = stdenv.mkDerivation rec { | |
# let's not use sandboxing for this derivation otherwise you'll need to follow some other practices | |
# to separate out the maven repository into it's own derivation. | |
# If you are building this derivation yourself, YOU WILL NEED TO RELAX the sandboxing. | |
# `nix-build nix/jruby.nix --option sandbox relaxed` (can also be set in nix.conf globally) | |
# Be sure to upload to our cache so others can just memoize the result without having to relax their sandbox. | |
# or | |
# You will have to use the double derivation scheme as defined in | |
# https://nixos.org/manual/nixpkgs/unstable/#maven. | |
# | |
__noChroot = true; | |
pname = "jruby"; | |
version = jrubyVersion; | |
src = fetchFromGitHub { | |
owner = "jruby"; | |
repo = "jruby"; | |
# rev corresponds to the Git commit hash or tag (e.g v1.0) that will be downloaded from Git. | |
# https://nixos.org/manual/nixpkgs/stable/#fetchfromgithub | |
rev = jrubyVersion; | |
# When changing the revision, you can set the sha256 to `lib.fakeSha256`. | |
# The build will then fail and tell you the expected sha256 | |
sha256 = "14zs1xr9rb7ydna7kfr2xvsvgwpm8lr5ngmb8dqgdv1hq687h6wz"; | |
}; | |
buildInputs = [ makeWrapper maven ant jre ]; | |
buildPhase = '' | |
mvn -Dmaven.install.skip=true -Pdist | |
mkdir ./dist | |
tar -xzvf ./maven/jruby-dist/target/jruby-dist-*-bin.tar.gz --strip-components=1 -C ./dist | |
cd ./dist | |
''; | |
installPhase = '' | |
mkdir -pv $out/docs | |
mv * $out | |
rm $out/bin/*.{bat,dll,exe,sh} | |
mv $out/COPYING $out/LICENSE* $out/docs | |
for i in $out/bin/jruby{,.bash}; do | |
wrapProgram $i \ | |
--set JAVA_HOME ${jre.home} | |
done | |
ln -s $out/bin/jruby $out/bin/ruby | |
# 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} | |
} | |
addEnvHooks "$hostOffset" addGemPath | |
EOF | |
''; | |
postFixup = '' | |
PATH=$out/bin:$PATH patchShebangs $out/bin | |
''; | |
passthru = rec { | |
rubyEngine = "jruby"; | |
gemPath = "lib/${rubyEngine}/gems/${rubyVersion.libDir}"; | |
libPath = "lib/${rubyEngine}/${rubyVersion.libDir}"; | |
}; | |
meta = with lib; { | |
description = "Ruby interpreter written in Java"; | |
homepage = "http://jruby.org/"; | |
license = with licenses; [ cpl10 gpl2 lgpl21 ]; | |
platforms = platforms.unix; | |
maintainers = [ maintainers.fzakaria ]; | |
}; | |
}; | |
in jruby.overrideAttrs (oldAttrs: { | |
passthru = oldAttrs.passthru // { | |
devEnv = callPackage | |
"${sources.nixpkgs.outPath}/pkgs/development/interpreters/ruby/dev.nix" { | |
ruby = jruby; | |
}; | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment