Generates a Nix expression for your Bundler-managed application.
Branch: master
Clone or download
Pull request Compare This branch is 61 commits ahead of cstrahan:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Handle path sources (e.g. gemspec directives) (#37) Nov 25, 2018


Bundix makes it easy to package your Bundler-enabled Ruby applications with the Nix package manager.


Installing from this repo:

nix-env -iA bundix

Please note that in order to actually use this gem you must have Nix installed.

Basic Usage

I recommend first reading the nixpkgs manual entry for Ruby as this README might become outdated, it's a short read right now, so you won't regret it.

  1. Making a gemset.nix

Change to your project's directory and run this:

bundix -l

This will generate a gemset.nix file that you then can use in your bundlerEnv expression like this:

  1. Using nix-shell

To try your package in nix-shell, create a default.nix like this:

with (import <nixpkgs> {});
  gems = bundlerEnv {
    name = "your-package";
    inherit ruby;
    gemdir = ./.;
in stdenv.mkDerivation {
  name = "your-package";
  buildInputs = [gems ruby];

and then simply run nix-shell.

  1. Proper packages

To make a package for nixpkgs, you can try something like this:

{ stdenv, bundlerEnv, ruby }:
  gems = bundlerEnv {
    name = "your-package";
    inherit ruby;
    gemdir  = ./.;
in stdenv.mkDerivation {
  name = "your-package";
  src = ./.;
  buildInputs = [gems ruby];
  installPhase = ''
    mkdir -p $out
    cp -r $src $out

How & Why

I'd usually just tell you to read the code yourself, but the big picture is that bundix tries to fetch a hash for each of your bundle dependencies and store them all together in a format that Nix can understand and is then used by bundlerEnv.

I wrote this new version of bundix because I became frustrated with the poor performance of the old bundix, and wanted to save both time and bandwidth, as well as learn more about Nix.

For each gem, it first tries to look for an existing gem in the bundler cache (usually generated via bundle package), and if that fails it goes through each remote and tries to fetch the gem from there. If the remote happens to be we ask the API first for a hash of the gem, and then ask the Nix store whether we have this version already. Only if that also fails do we download the gem.

As an added bonus I also implemented parsing the gemset.nix if it already exists, and get hashes from there directly, that way updating an existing gemset.nix only takes a few seconds.

The output from bundix should be as stable as possible, to make auditing diffs easier, that's why I also implemented a pretty printer for the gemset.nix.

I hope you enjoy using bundix as much as I do, and if you don't, let me know.

Closing words

For any questions or suggestions, please file an issue on Github or ask in #nixos on Freenode.

Big thanks go out to Charles Strahan for his awesome work bringing Ruby to Nix, zimbatm for being a good rubber duck and tester, and Alexander Flatter for the original bundix. I couldn't have done this without you guys.