inscapist / ruby-nix

Generates reproducible ruby/bundler app environment with Nix
MIT License
114 stars 5 forks source link

Gemfile `ruby: file` unsupported #44

Closed J-Swift closed 1 month ago

J-Swift commented 1 month ago

Maybe I'm not configuring something properly on my end, but it looks like providing ruby version in a Gemfile doesnt work.

e.g. if I do this in my Gemfile

ruby file: '.ruby-version'

if fails with

/nix/store/3h12slpvxj5gxmwv9xgpc8c85lqb4lba-ruby-3.2.2/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your Ruby version is 3.2.2, but your Gemfile specified  (Bundler::RubyVersionMismatch)

but if I do it explicitly

ruby '3.2.2'

it works. I assume its because the version file isnt being copied to the store, but it also seems like it should still work at runtime since the version file exists? I added ruby-nix to an existing project that was working before, so its definitely configured properly at a basic level.

EDIT: it also turns out that this old-style of specifying the path also works

ruby File.read('.ruby-version').strip
inscapist commented 1 month ago

I wasn't able to replicate this. But in any case, you should use the ruby File.read('.ruby-version') syntax

J-Swift commented 1 month ago

Hmm the only other thing I can think of is that Im specifying the ruby version explicitly for nix (ruby = pkgs.ruby_3_2) instead of reading the file. That could be why its not in the store. Wont be back into the office until monday to check.

inscapist commented 1 month ago

If it's not too much trouble, could you make a small reproducible example? Or maybe share the flake.nix here?

J-Swift commented 1 month ago

@inscapist will do. Hopefully sometime next week

J-Swift commented 1 month ago

@inscapist heres a basic repro off a rails new: https://github.com/J-Swift/rubynix-repro

inscapist commented 1 month ago

thank you. I will take a look tomorrow

inscapist commented 1 month ago

@J-Swift the issue actually stems from the version of bundler being used. In the repro, your bundler version is 2.4.10 but the new syntax is only supported in 2.4.19 and above

https://github.com/rubygems/rubygems/releases/tag/bundler-v2.4.19

You could try switching to bobvanderlinden's nixpkgs-ruby and set your ruby version to 3.2.5. On ruby 3.2.5, the built-in bundler version is 2.4.19

inscapist commented 1 month ago

This syntax is probably the new default for newer versions of rails. I am sure more people will be affected by this.

So thanks for the report!

J-Swift commented 1 month ago

Hmm weird. Good catch. Previously I was running via docker and other team members are running bare metal (no nix) so Ill have to figure out what bundler was being used before.

On Tue, Aug 27, 2024 at 10:42 AM Felx @.***> wrote:

This syntax is probably the new default for newer versions https://github.com/rails/rails/pull/49360 of rails. I am sure more people will be affected by this.

So thanks for the report!

— Reply to this email directly, view it on GitHub https://github.com/inscapist/ruby-nix/issues/44#issuecomment-2312763895, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFTHTTCKDO6YSPARDK2LX3ZTSF5PAVCNFSM6AAAAABNANVES2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJSG43DGOBZGU . You are receiving this because you were mentioned.Message ID: @.***>

J-Swift commented 1 month ago

Also, thanks for this project. It greatly simplified moving to nix on rails. Id tried a few times before and never could get it working quite right so Ive been sticking to docker for rails. Now I get nix + bare metal performance… win+win!

inscapist commented 1 month ago

I know what you mean, that's great to hear!