Hi!
I would love some feedback on how to cleanup + improve my Nix seutp for use with Ruby / JRuby.
Disclaimer: Although the “nix” thing to do is probably use a shell.nix file to set a specific Ruby version installation; I’m trying to migrate an existing large codebase to Nix and it heavily relies on rbenv
rbenv dynamically switches the ruby version according to a
.ruby-version
file in a directory
First thing I did was create a very simple rbenv derivation
{ stdenv, fetchFromGitHub, bash }:
stdenv.mkDerivation {
name = "rbenv";
# fetchFromGitHub is a build support function that fetches a GitHub
# repository and extracts into a directory; so we can use it
# fetchFromGithub is actually a derivation itself :)
src = fetchFromGitHub {
owner = "rbenv";
repo = "rbenv";
rev = "v1.1.2";
sha256 = "12i050vs35iiblxga43zrj7xwbaisv3mq55y9ikagkr8pj1vmq53";
};
buildPhase = ''
${bash}/bin/bash src/configure
make -C src
'';
# This overrides the shell code that is run during the installPhase.
# By default; this runs `make install`.
# The install phase will fail if there is no makefile; so it is the
# best choice to replace with our custom code.
installPhase = ''
mkdir -p $out/bin
mv libexec $out
mv completions $out
ln -s $out/libexec/rbenv $out/bin/rbenv
'';
}
I’ve actually posted this as a pull-request to nixpkgs.
The way in which rbenv works is by finding versions in ~/.rbenv/versions.
My plan is to use home-manager to symlink my ruby/jruby versions in that directory
home.file = {
".rbenv/versions/jruby-${jruby_9_2_9_0.version}" = {
source = jruby_9_2_9_0;
target = ".rbenv/versions/jruby-${jruby_9_2_9_0.version}";
};
".rbenv/versions/jruby-${jruby_9_2_12_0.version}" = {
source = jruby_9_2_12_0;
target = ".rbenv/versions/jruby-${jruby_9_2_12_0.version}";
};
};
This works great so far however it turns out that nixpkg only has a single jruby version; so I had to create my own derivations for each version.
jruby_9_2_9_0 = super.jruby.overrideAttrs (oldAtrrs: rec {
version = "9.2.9.0";
src = super.fetchurl {
url = "https://s3.amazonaws.com/jruby.org/downloads/${version}/jruby-bin-${version}.tar.gz";
sha256 = "04grdf57c1dgragm17yyjk69ak8mwiwfc1vjzskzcaag3fwgplyf";
};
});
jruby_9_2_12_0 = super.jruby.overrideAttrs (oldAtrrs: rec {
version = "9.2.12.0";
src = super.fetchurl {
url = "https://s3.amazonaws.com/jruby.org/downloads/${version}/jruby-bin-${version}.tar.gz";
sha256 = "013c1q1n525y9ghp369z1jayivm9bw8c1x0g5lz7479hqhj62zrh";
};
});
My questions are as follows:
- It’s a bit of a PITA to have to override the whole fetchurl just to change the sha256. Is this the only way ?
- I wouldn’t mind someone helping me understand the jruby derivation; specifically the use of rubyVersion and why it’s doing some funky override at the bottom.
- What’s the nixlang syntax so I can just iterate over an array of versions to create that symlink attr set above rather than manually typing it. Something like:
map [ "9.2.9.0" "9.2.12.0"] (version: {
# what here!
});