Bundler and ruby (via .ruby-version) both have system gems
Describe the bug It seems that both bundler and ruby are both bringing their own system gems to the party. This is bad.

To reproduce
-
devenv init - Set up ruby via .ruby-version in devenv.nix.
-
rails new foo - It won't bundle.
Version devenv: 0.6.2
I cannot reproduce this error. I did the following:
$ devenv init
$ echo 3 > .ruby-version
$ nano devenv.nix # See gist below
# An error about nixpkgs-ruby not being part of `devenv.yaml`.
$ nano devenv.yaml # See gist below
# devenv loads
$ gem install rails # Installs rails in $DEVENV_STATE/.bundle/
$ command -v rails # Check whether rails is in $DEVENV_STATE/.bundle
.../.devenv/state/.bundle/ruby/3.2.0/bin/rails
$ rails new foo
Output of `rails new foo`
$ rails new foo
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create .gitattributes
create Gemfile
run git init from "."
Initialized empty Git repository in /home/bob.vanderlinden/tmp/experiment-rails/foo/.git/
create app
create app/assets/config/manifest.js
create app/assets/stylesheets/application.css
create app/channels/application_cable/channel.rb
create app/channels/application_cable/connection.rb
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/jobs/application_job.rb
create app/mailers/application_mailer.rb
create app/models/application_record.rb
create app/views/layouts/application.html.erb
create app/views/layouts/mailer.html.erb
create app/views/layouts/mailer.text.erb
create app/assets/images
create app/assets/images/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/rails
create bin/rake
create bin/setup
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/cable.yml
create config/puma.rb
create config/storage.yml
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/assets.rb
create config/initializers/content_security_policy.rb
create config/initializers/cors.rb
create config/initializers/filter_parameter_logging.rb
create config/initializers/inflections.rb
create config/initializers/new_framework_defaults_7_0.rb
create config/initializers/permissions_policy.rb
create config/locales
create config/locales/en.yml
create config/master.key
append .gitignore
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create lib
create lib/tasks
create lib/tasks/.keep
create lib/assets
create lib/assets/.keep
create log
create log/.keep
create public
create public/404.html
create public/422.html
create public/500.html
create public/apple-touch-icon-precomposed.png
create public/apple-touch-icon.png
create public/favicon.ico
create public/robots.txt
create tmp
create tmp/.keep
create tmp/pids
create tmp/pids/.keep
create tmp/cache
create tmp/cache/assets
create vendor
create vendor/.keep
create test/fixtures/files
create test/fixtures/files/.keep
create test/controllers
create test/controllers/.keep
create test/mailers
create test/mailers/.keep
create test/models
create test/models/.keep
create test/helpers
create test/helpers/.keep
create test/integration
create test/integration/.keep
create test/channels/application_cable/connection_test.rb
create test/test_helper.rb
create test/system
create test/system/.keep
create test/application_system_test_case.rb
create storage
create storage/.keep
create tmp/storage
create tmp/storage/.keep
remove config/initializers/cors.rb
remove config/initializers/new_framework_defaults_7_0.rb
run bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Fetching rake 13.0.6
Installing rake 13.0.6
Using concurrent-ruby 1.2.2
Fetching timeout 0.3.2
Using crass 1.0.6
Using racc 1.6.2
Fetching bindex 0.8.1
Using rack 2.2.7
Fetching msgpack 1.7.1
Using nio4r 2.5.9
Using bundler 2.4.10
Fetching public_suffix 5.0.1
Using websocket-extensions 0.1.5
Fetching regexp_parser 2.8.0
Fetching matrix 0.4.2
Using erubi 1.12.0
Using io-console 0.6.0
Using method_source 1.0.0
Using thor 1.2.2
Using zeitwerk 2.6.8
Using marcel 1.0.2
Fetching rexml 3.2.5
Using mini_mime 1.1.2
Fetching rubyzip 2.3.2
Using date 3.3.3
Fetching websocket 1.2.9
Fetching sqlite3 1.6.3 (x86_64-linux)
Using builder 3.2.4
Using i18n 1.13.0
Using tzinfo 2.0.6
Using nokogiri 1.15.2 (x86_64-linux)
Fetching minitest 5.18.0
Using rack-test 2.1.0
Fetching puma 5.6.5
Installing timeout 0.3.2
Installing bindex 0.8.1 with native extensions
Installing msgpack 1.7.1 with native extensions
Fetching sprockets 4.2.0
Installing matrix 0.4.2
Installing websocket 1.2.9
Installing regexp_parser 2.8.0
Using websocket-driver 0.7.5
Installing rubyzip 2.3.2
Fetching reline 0.3.4
Installing rexml 3.2.5
Installing public_suffix 5.0.1
Installing sprockets 4.2.0
Installing minitest 5.18.0
Installing puma 5.6.5 with native extensions
Installing reline 0.3.4
Using loofah 2.21.3
Fetching xpath 3.2.0
Using net-protocol 0.2.1
Using rails-html-sanitizer 1.6.0
Fetching net-imap 0.3.4
Fetching net-pop 0.1.2
Installing xpath 3.2.0
Fetching net-smtp 0.3.3
Fetching addressable 2.8.4
Using activesupport 7.0.5
Fetching irb 1.6.4
Installing net-pop 0.1.2
Installing net-smtp 0.3.3
Fetching selenium-webdriver 4.9.1
Using rails-dom-testing 2.0.3
Using globalid 1.1.0
Using activemodel 7.0.5
Using actionview 7.0.5
Using activejob 7.0.5
Using activerecord 7.0.5
Fetching jbuilder 2.11.5
Using actionpack 7.0.5
Using actioncable 7.0.5
Using activestorage 7.0.5
Using railties 7.0.5
Using actiontext 7.0.5
Fetching importmap-rails 1.1.6
Installing irb 1.6.4
Installing net-imap 0.3.4
Fetching stimulus-rails 1.2.1
Fetching turbo-rails 1.4.0
Installing addressable 2.8.4
Installing jbuilder 2.11.5
Fetching web-console 4.2.0
Fetching sprockets-rails 3.4.2
Fetching capybara 3.39.1
Installing sprockets-rails 3.4.2
Installing web-console 4.2.0
Installing stimulus-rails 1.2.1
Using mail 2.8.1
Using actionmailbox 7.0.5
Using actionmailer 7.0.5
Using rails 7.0.5
Installing importmap-rails 1.1.6
Installing turbo-rails 1.4.0
Fetching debug 1.8.0
Installing capybara 3.39.1
Installing debug 1.8.0 with native extensions
Installing sqlite3 1.6.3 (x86_64-linux)
Installing selenium-webdriver 4.9.1
Fetching webdrivers 5.2.0
Installing webdrivers 5.2.0
Fetching bootsnap 1.16.0
Installing bootsnap 1.16.0 with native extensions
Bundle complete! 15 Gemfile dependencies, 72 gems now installed.
Bundled gems are installed into `/home/bob.vanderlinden/tmp/experiment-rails/.devenv/state/.bundle`
run bundle binstubs bundler
rails importmap:install
Add Importmap include tags in application layout
insert app/views/layouts/application.html.erb
Create application.js module as entrypoint
create app/javascript/application.js
Use vendor/javascript for downloaded pins
create vendor/javascript
create vendor/javascript/.keep
Ensure JavaScript files are in the Sprocket manifest
append app/assets/config/manifest.js
Configure importmap paths in config/importmap.rb
create config/importmap.rb
Copying binstub
create bin/importmap
rails turbo:install stimulus:install
Import Turbo
append app/javascript/application.js
Pin Turbo
append config/importmap.rb
Enable redis in bundle
gsub Gemfile
run bundle install
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using rake 13.0.6
Using concurrent-ruby 1.2.2
Using minitest 5.18.0
Using builder 3.2.4
Using racc 1.6.2
Using crass 1.0.6
Using rack 2.2.7
Using matrix 0.4.2
Using regexp_parser 2.8.0
Using io-console 0.6.0
Using mini_mime 1.1.2
Using thor 1.2.2
Using public_suffix 5.0.1
Using bindex 0.8.1
Fetching redis 4.8.1
Using erubi 1.12.0
Using rubyzip 2.3.2
Using msgpack 1.7.1
Using websocket 1.2.9
Using nio4r 2.5.9
Using tzinfo 2.0.6
Using date 3.3.3
Using rack-test 2.1.0
Using zeitwerk 2.6.8
Using rexml 3.2.5
Using websocket-extensions 0.1.5
Using bootsnap 1.16.0
Using i18n 1.13.0
Using marcel 1.0.2
Using selenium-webdriver 4.9.1
Using method_source 1.0.0
Using nokogiri 1.15.2 (x86_64-linux)
Using bundler 2.4.10
Using xpath 3.2.0
Using webdrivers 5.2.0
Using addressable 2.8.4
Using timeout 0.3.2
Using capybara 3.39.1
Using net-protocol 0.2.1
Using sqlite3 1.6.3 (x86_64-linux)
Using websocket-driver 0.7.5
Using net-imap 0.3.4
Using loofah 2.21.3
Using reline 0.3.4
Using puma 5.6.5
Using rails-html-sanitizer 1.6.0
Using irb 1.6.4
Using net-pop 0.1.2
Using net-smtp 0.3.3
Using debug 1.8.0
Using sprockets 4.2.0
Using activesupport 7.0.5
Using mail 2.8.1
Using rails-dom-testing 2.0.3
Using activemodel 7.0.5
Using globalid 1.1.0
Using activerecord 7.0.5
Using actionview 7.0.5
Using actionpack 7.0.5
Using activejob 7.0.5
Using jbuilder 2.11.5
Using activestorage 7.0.5
Using railties 7.0.5
Using sprockets-rails 3.4.2
Using actionmailbox 7.0.5
Using actioncable 7.0.5
Using actionmailer 7.0.5
Using importmap-rails 1.1.6
Using stimulus-rails 1.2.1
Using turbo-rails 1.4.0
Using web-console 4.2.0
Using actiontext 7.0.5
Using rails 7.0.5
Installing redis 4.8.1
Bundle complete! 16 Gemfile dependencies, 73 gems now installed.
Bundled gems are installed into `/home/bob.vanderlinden/tmp/experiment-rails/.devenv/state/.bundle`
Switch development cable to use redis
gsub config/cable.yml
Create controllers directory
create app/javascript/controllers
create app/javascript/controllers/index.js
create app/javascript/controllers/application.js
create app/javascript/controllers/hello_controller.js
Import Stimulus controllers
append app/javascript/application.js
Pin Stimulus
Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
append config/importmap.rb
Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
append config/importmap.rb
Pin all controllers
Appending: pin_all_from "app/javascript/controllers", under: "controllers"
append config/importmap.rb
See the gist: https://gist.github.com/bobvanderlinden/dab0489bf7840ab3478f3e8773750c49
Alternative to using gem install rails I also tried to add the Nix package of rails:
packages = [
pkgs.rubyPackages.rails
];
That also seems to be working without error.
Do you have the following in devenv.yaml?
nixpkgs-ruby:
url: github:bobvanderlinden/nixpkgs-ruby
inputs:
nixpkgs:
follows: nixpkgs
To be able to reproduce, could you create a gist similar to mine? That would include the ruby-version being used, the devenv version and the devenv configuration.
@bobvanderlinden You've given me a wonderfully detailed response! Thank you!
I'm running into this issue now with bundler directly at times when I use bundle exec.
With other gems I'm hitting:
It does look like my installation of bundler 2.4.13 from nix has only the bundler gem in it. Do we need to add that to GEM_HOME?
@bobvanderlinden I have a repro for the binstub issue: https://github.com/ryansch/nix-bundler-issue
I'm unable to run solargraph or rspec without bundle exec.
I didn't use pkgs.rubyPackages.rails but instead did a gem install rails; rails new foo.
I found a workaround!
Setting languages.ruby.bundler.enable = false; causes nix to use the version included with whatever ruby we've installed. Bundler is smart enough to read the Gemfile.lock and automatically install the specified version and reexec.
@bobvanderlinden do you think this issue is still relevant? Either way it belongs to nixpgks-ruby
From what I can tell, the problem is including nixpkgs' bundler package, instead of using the bundler executable from the ruby package (unsure whether that only works for nixpkgs-ruby or whether it also works for nixpkgs' ruby).
If I understand this correctly, removing https://github.com/cachix/devenv/blob/cdb6a64787ab77d7ec37c68d19de483a76f08173/src/modules/languages/ruby.nix#L76 would fix the issue. At the same time I don't know whether it will break other use cases.
Older versions of Ruby didn't ship bundler, so adding bundler in devenv was needed. I can imagine that the more common ruby versions now do ship bundler, so changing the default to false might be a good option nowadays.
The option is part of seven, so I think the issue is most relevant here.
@ryansch do you always disable the bundler option nowadays?