NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.36k stars 14.32k forks source link

binstubs die looking for `bundler/setup` #103299

Open chooh opened 4 years ago

chooh commented 4 years ago

Describe the bug I am using nix and direnv to have a development environment for a rails application. My shell.nix looks like this:

with import <nixpkgs> {};

mkShell {
  name = "env";
  buildInputs = [
    ruby_2_5.devEnv
  ];
}

To Reproduce Steps to reproduce the behavior:

  1. cd tempdir
  2. run shell nix-shell -p ruby_2_5.devEnv
  3. execute:
    GEM_HOME=$(pwd)
    echo 'gem "rake"' > Gemfile
    bundle install
    bundle binstubs rake --path .
    ./rake -T
    Traceback (most recent call last):
        2: from ./rake:27:in `<main>'
        1: from /nix/store/qfn1xq5ic1cwmd1iqnqxzl6ns3wk962p-ruby-2.5.8/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
    /nix/store/qfn1xq5ic1cwmd1iqnqxzl6ns3wk962p-ruby-2.5.8/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- bundler/setup (LoadError)

Expected behavior I expect that I already have gem bundler and I don't have to install it again with gem install bundler.

Notify maintainers @zimbatm

Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-darwin"`
 - host os: `Darwin 19.6.0, macOS 10.15.7`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.7`
 - channels(alex): `"nixpkgs-21.03pre251181.dd1b7e377f6"`
 - nixpkgs: `/Users/chooh/.nix-defexpr/channels/nixpkgs
chooh commented 4 years ago

I looked at /nix/store/20nb9mf9cqrgdyi8ljcsrbqll33fnmf2-ruby-dev-2.5.8/bin/bundle and found that $GEM_PATH had been altered with extra paths from nix:

Gem.paths = {
  'GEM_PATH' => (
    ENV['GEM_PATH'].to_s.split(File::PATH_SEPARATOR) +
    ["/nix/store/0hxycyxcvfd2mls1znx5ws06dlzwyqqa-bundler-2.1.4/lib/ruby/gems/2.5.0", "/nix/store/qfn1xq5ic1cwmd1iqnqxzl6ns3wk962p-ruby-2.5.8/lib/ruby/gems/2.5.0"]
  ).join(File::PATH_SEPARATOR)
}

If I take my example above and run it:

GEM_PATH=/nix/store/0hxycyxcvfd2mls1znx5ws06dlzwyqqa-bundler-2.1.4/lib/ruby/gems/2.5.0:/nix/store/qfn1xq5ic1cwmd1iqnqxzl6ns3wk962p-ruby-2.5.8/lib/ruby/gems/2.5.0 rake -T
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/Library/Ruby/Gems/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

It works as expected.

Furthermore gem env shows as follows:

  - GEM PATHS:
     - /Users/chooh/project/.direnv/ruby
     - /Users/chooh/.gem/ruby/2.5.0
     - /nix/store/qfn1xq5ic1cwmd1iqnqxzl6ns3wk962p-ruby-2.5.8/lib/ruby/gems/2.5.0

There is no /nix/store/0hxycyxcvfd2mls1znx5ws06dlzwyqqa-bundler-2.1.4/lib/ruby/gems/2.5.0 in the GEM PATHS.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info