How would you recommend someone to move from an existing Rails application to use Nix with this template?
Copy the files over that you have changed/added from what Rails itself would generate? (which seem to be flake.nix, flake.lock, .envrc, scripts/) and then run nix run nixpkgs#bundix?
Or using some other method?
(I’m very new to Nix, so maybe I am confused by something trivial)
Good question! Off the top of my head, this is what I would do:
Generate Gemfile.lock
Edit Gemfile.lock to remove the system-specific information from the nokogiri entry (otherwise you’ll get errors when you try to build)
Run bundix using that same method you mentioned, which will generate a gemset.nix
At that point, you should be able to copy the Nix stuff from the example project into your directory and run direnv allow. That gives you access to an executable called update-deps that you can run any time you change your Gemfile. That script deletes Gemfile.lock and gemset.nix and regenerates both, and it uses the local Bundler config to not apply --use-system-libraries when installing Nokogiri.
If you run which rails you should see something like /nix/store/mbxfqhd67p1dpq5cl8b0li3917fp34mx-rails-env/bin/rails, which means that the application is properly bundled and thus you can just run rails server to start the server.
Thank you! This mostly worked. There was one change necessary to get gems like nokogiri to keep working as intended when running update-deps: The BUNDLE_FORCE_RUBY_PLATFORM=true environment variable.
This can be overridden in the bundler configuration, which was the case on my machine (for reasons unbeknownst to me). Without this set to true, you will end up still trying to build OS-specific versions of gems, which results in different hashes when running nix develop.
I ended up changing the line in the scripts/update.sh from
Something else came to mind: Currently JS packages do not seem to be managed by Nix, but rather still by running nodejs or yarn by hand. Does it make sense to add this as well?