I recently worked on ways to work with Ruby projects for development (and potentially deployment) purposes. I found flakes to be working quite well, so I experimented a bit how it could work for the Rails projects at work.
I came up with nixpkgs-ruby: a Nix flake repository with all Ruby versions available. The repository is automatically updated with new versions of Ruby.
Next I looked at ways to use this flake in existing Rails projects. These projects all use
.ruby-version, so I thought I’d use that instead of specifying the version in Nix. This way non-Nix colleagues could still maintain their projects without using Nix.
The result of this is a template that can be used for
nix flake init: https://github.com/bobvanderlinden/templates/tree/master/ruby
This allows for the following command:
nix flake init --template github:bobvanderlinden/templates#ruby
It creates a
use flake. It creates a
flake.nix devShell which sources the Ruby version from
.ruby-version and takes the right Ruby derivation from nixpkgs-ruby. Lastly it predefined a
bundleEnv, so that whenever bundix is called can be easily included.
I hope this can help others as well. I’m interested in the workflows others are using for working with Ruby projects and non-Nix contributors.