0

I am a Rubyist of many years. I cannot determine what's missing to prevent FFI from installing.

Here is the error from the make.out file (gotta love that name):

make[3]: *** [Makefile:1048: libffi_convenience.la] Error 1
make[3]: Leaving directory '/home/dw/.gem/ruby/2.4.0/gems/ffi-1.9.23/ext/ffi_c/libffi-x86_64-linux'
make[2]: *** [Makefile:1309: all-recursive] Error 1
make[2]: Leaving directory '/home/dw/.gem/ruby/2.4.0/gems/ffi-1.9.23/ext/ffi_c/libffi-x86_64-linux'
make[1]: *** [Makefile:617: all] Error 2
make[1]: Leaving directory '/home/dw/.gem/ruby/2.4.0/gems/ffi-1.9.23/ext/ffi_c/libffi-x86_64-linux'
make: *** [libffi.mk:9: "/home/dw/.gem/ruby/2.4.0/gems/ffi-1.9.23/ext/ffi_c/libffi-x86_64-linux"/.libs/libffi_convenience.a] Error 2

make failed, exit code 2

I checked nixpkgs and saw libffi-3.2.1 and pure-ffi-0.14 were available. I installed both. I still getting the error.

  • make.out LMAO! You mentioned installing two libraries in an attempt to provide the necessary dependencies for building a Ruby gem. NixOS takes a different approach here: derivations must specify their dependencies. What this means in practice is that installed libraries are not exposed in the way needed for other libraries and applications can find them. So when you try to build a binary outside of Nix, the linker is simply unable to find the libraries you've installed. In contrast, applications you install explicitly get added to your "user environment" which makes when accessible to you. – Emmanuel Rosa Apr 28 '18 at 17:24
  • generally, rubygems and bundler handle these dependencies. Are you saying on NixOS the preference is to use nix and Derivations? I am aware from earlier attempted npm package installs that there is some friction when there is another thing that tries to handle dependencies. Is this similar? – David West Apr 29 '18 at 16:09
  • Yes, it's exactly the same issue as with npm. It's not really NixOS, but rather Nix that requires (rather than prefers) that you specify dependencies using Nix. There's some tooling for compiling gems with Nix: nixos.org/nixpkgs/manual/#sec-language-ruby – Emmanuel Rosa Apr 29 '18 at 21:21
0

The first option is to use bundix. It uses a global override file to inject system dependencies: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/ruby-modules/gem-config/default.nix

Most important gems should be found there including the ffi gem, that you are trying to install.

If you don't want to/can use bundix, the alternative is a nix-shell that gives you the correct build environment.

For the ffi gem you can also borrow the code from nixpkgs's gem-config:

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "env";
  buildInputs = [
    ffi pkgconfig
  ];
}

Then just run nix-shell in the project. This step can be also automated using direnv's nix support. Installing ffi via nix-env does not work because it does not set the NIX_CFLAGS_COMPILE and NIX_LDFLAGS variable that is necessary for the ffi gem to find the correct header/libraries during compilation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.