My concrete goal is to install twitter/twurl on macOS without letting ruby/gem litter the filesystem, thus want to install it via nix. twurl
is a simple command line tool which you’d usually install simply via
gem install twurl
What I’ve got so far: With a small fix, bundix --magic
runs successfully within a source checkout of twurl
, generating gemset.nix
.
Furthermore, bundix -i
generates a shell.nix
, and nix-shell
seems to build the ruby dependencies successfully. However, running ./bin/twurl
within nix-shell
fails due to failing ruby imports of dependencies. It turns out this is because it uses system ruby; adding ruby
to the shell dependencies gives me a working twurl
in nix-shell
.
Where I’m stuck now is finding a working default.nix
that allows installing the twurl
executable so that it runs. The closest I’ve come is:
with (import <nixpkgs> {});
let
env = bundlerEnv {
name = "twurl-bundler-env";
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
in stdenv.mkDerivation {
name = "twurl";
buildInputs = [ env ruby ];
src = ./.;
installPhase = ''
mkdir -p $out
cp -r $src/* $out
'';
}
which gives me twurl
in the PATH and with a correctly patched ruby interpreter, but it fails because it doesn’t find the library files from src/lib
. I’m unclear on whether these should go inside the bundlerEnv
or whether I should do some explicit magic to tell the executable about where to look for them. (I’m also unclear on the meaning of gemdir
as an argument to bundlerEnv
which shows up in examples apparently randomly instead of gemfile
/gemset
.)
Finally, I’m wondering if there isn’t (shouldn’t be) a more straightforward way to do this? Initially I’d have thought bundix
or a similar tool might just generate a working default.nix
from the gemspec
file. Maybe that exists but bundix
is not that tool?