A gemset manager for Ruby written as a Nix flake
README.md

Corundix #

A Nix flake for managing multiple isolated Ruby gemsets. Each gemset pins its own Ruby version and gem dependencies, reproducible across machines. It makes use of the excellent flake from bobvanderlin bobvanderlinden/nixpkgs-ruby.

demo

Prerequisites #

Nix with flakes enabled.

Quickstart #

# Create a new gemset named "myapp" using Ruby 3.4.1
nix run .#gemset-create -- myapp 3.4.1

# Edit gemsets/myapp/Gemfile to add your gems, then lock it
git add gemsets/myapp
nix run .#gemset-lock -- myapp

# Commit the lock files
git add gemsets/myapp/Gemfile.lock gemsets/myapp/gemset.nix

# Run a script with the gemset's Ruby
nix run .#myapp -- script.rb

Usage suggestion #

If you want to maintain a corundix installation which you can use across multiple projects then try this. In this example you have corundix checked out locally in your home folder.

nix registry add corundix /home/markd/corundix

You can then get a dev shell anywhere with nix develop corundix#myapp. Alternatively, you can use nix shell corundix#myapp to run a shell with the gemset's Ruby.

Gemset layout #

Each gemset lives under gemsets/<name>/:

gemsets/
└── myapp/
    ├── Gemfile        # gem dependencies
    ├── Gemfile.lock   # locked versions
    ├── gemset.nix     # Nix-format lock file (generated by bundix)
    └── ruby-version   # Ruby version, e.g. 3.4.1

Commands #

gemset-create #

Create a new gemset directory with a starter Gemfile.

nix run .#gemset-create -- NAME [RUBY_VERSION]
# RUBY_VERSION defaults to 3.3.6

gemset-lock #

Lock the current Gemfile (runs bundle lock then bundix).

nix run .#gemset-lock -- NAME

gemset-update #

Update all gems to their latest allowed versions (runs bundle update then bundix).

nix run .#gemset-update -- NAME

gemset-delete #

Remove a gemset directory.

nix run .#gemset-delete -- NAME

Running Ruby and Bundler #

Each gemset exposes its Ruby interpreter and Bundler as flake apps:

# Run a script
nix run .#myapp -- script.rb

# Run bundle commands (install, exec, etc.)
nix run .#bundle-myapp -- exec rake

Dev shell #

A default shell with all gemsets' Rubies and bundix available:

nix develop .#myapp