Using bundix with local gems (or Rails' engines)

I’m trying to use bundix on a rails projects that uses multiple engines. I’ve ran bundix to generate a gemset.nix and shell.nix. So far building works fine but when calling bundler (or any other commands installed by the derivation created by bundix) it complains that it can’t find the engines with the following error:

/nix/store/3h9n2k5gfm84gk74s77vb23d274c7g83-bundler-2.2.20/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/source/path.rb:209:in load_spec_files': The path /nix/store/r2ndb03whz82fj6nbsgm1ks6n2z09y27-gemfile-and-lockfile/engines/engine-name` does not exist. (Bundler::PathError)

Indeed the /nix/store/r2ndb03whz82fj6nbsgm1ks6n2z09y27-gemfile-and-lockfile/Gemfile file contains the following:

gem ‘engine-name’, path: ‘engines/engine-name’

I can see that this gem is in the nix store but it’s searching for it relative to the Gemfile and there is nothing else in the gemfile-and-lockfile directory except the Gemfile and Gemfile.lock. What can I do to fix this? Should I somehow create links from the gemfile-and-lockfile directory to the gem’s directory in the nix store? Or should I find a way to patch the Gemfile to se the full path? Or did I miss something way simpler?

It seems it should have been fixed in bundix 2.4 but I’m using 2.5 and I can’t get it to work.

1 Like

This isn’t an issue with bundix, but rather with the bundlerEnv function provided by Nixpkgs.

See bundlerEnv doesn't work with local "unbuilt" gems ("path" source) · Issue #197556 · NixOS/nixpkgs · GitHub.

If you’re using flakes, you may find GitHub - sagittaros/ruby-nix: Generates reproducible ruby/bundler app environment with Nix helpful as a drop-in replacement for bundlerEnv.

If your gemfile requires other files to be present relative to their location you need to copy them. bundlerEnv gives the the extraConfigPath for this scenario. You can see how its use in the [gitlab derivation](

However copying the entire engine gem might be undesirable when working on that engine as you’ll be running the version as it was when bundlerEnv was built. Another approach for that scenario would be to use --substitute-in-place to fix the path so that it an absolute path to the version in your project.

1 Like