I’m writing a shell.nix for a ruby project that uses rugged, a library of ruby bindings to libgit2. Building rugged
requires cmake.
# shell.nix
with (import <nixpkgs> { });
mkShell {
buildInputs = [
bundler
ruby
# "rugged" dependencies
cmake
pkgconfig
openssl
];
shellHook = "export BUNDLE_PATH=.bundle";
}
# Gemfile
source "https://rubygems.org"
gem "rugged"
Entering the shell with nix-shell --pure
, I can run bundle install
and it builds and installs rugged
as expected.
But if I add bundle install
to the shellHook
it fails to find a needed libgit2 header:
/path/to/project/.bundle/gems/rugged-0.28.2/vendor/libgit2/src/alloc.h:11:10: fatal error: git2/sys/alloc.h: No such file or directory
#include "git2/sys/alloc.h"
^~~~~~~~~~~~~~~~~~
Adding libgit2
to buildInputs
doesn’t seem to help. The only solution I’ve found so far is:
shellHook = ''
export BUNDLE_PATH=.bundle
NIX_ENFORCE_PURITY=0 bundle install
'';
I discovered this by comparing env
inside the shellHook
with env
inside the nix-shell.
What’s the right way to resolve this?
A side-note: I’m aware of bundix, but cannot use it for this particular project. The above shell.nix is a minimal example that reproduces my issue, but the actual project uses an older ruby version and has a couple gems specified by local filepath.