NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.05k forks source link

Using bundlerEnv with the gem kubeclient fails with a NameError #83442

Open shuhaowu opened 4 years ago

shuhaowu commented 4 years ago

Describe the bug Creating a bundlerEnv with the gem kubeclient and attempting to require "kubeclient" causes a NameError to be raised upon require.

To Reproduce Steps to reproduce the behavior:

  1. A minimal example with shell.nix, gemset.nix and Gemfile is available here: https://gist.github.com/shuhaowu/0c54e9051d41ff4b348486793ae6fcd2. In case that becomes unavailable in the future, here's a zipfile of it.
  2. Run nix-shell with the above environment.
  3. Run irb, and in it, run require 'kubeclient'

Immediately, you will see:

/nix/store/r84snw8z4zr3fhaai4cs8j19lgkv76si-ruby2.6.5-http-accept-1.7.0/lib/ruby/gems/2.6.0/gems/http-accept-1.7.0/lib/http/accept/version.rb:23: warning: already initialized constant HTTP::Accept::VERSION
/nix/store/04zfivb2qpnfmz8xk3pg24l3r8qd9s0y-testenv/lib/ruby/gems/2.6.0/gems/http-accept-1.7.0/lib/http/accept/version.rb:23: warning: previous definition of VERSION was here
Traceback (most recent call last):
       16: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:156:in `require'
       15: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
       14: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:168:in `require'
       13: from /nix/store/bv5cb3n2wsrgf7xkr8j5qn0gyjc8kl9x-ruby2.6.5-kubeclient-4.6.0/lib/ruby/gems/2.6.0/gems/kubeclient-4.6.0/lib/kubeclient.rb:16:in `<top (required)>'
       12: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
       11: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
       10: from /nix/store/04zfivb2qpnfmz8xk3pg24l3r8qd9s0y-testenv/lib/ruby/gems/2.6.0/gems/kubeclient-4.6.0/lib/kubeclient/watch_stream.rb:2:in `<top (required)>'
        9: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:155:in `require'
        8: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:155:in `require'
        7: from /nix/store/lx1qgbkkmi2954i5yvzvapmff2blyycp-ruby2.6.5-http-4.4.0/lib/ruby/gems/2.6.0/gems/http-4.4.0/lib/http.rb:14:in `<top (required)>'
        6: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        5: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        4: from /nix/store/04zfivb2qpnfmz8xk3pg24l3r8qd9s0y-testenv/lib/ruby/gems/2.6.0/gems/http-4.4.0/lib/http/response.rb:11:in `<top (required)>'
        3: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        2: from /nix/store/a3wafb77xrn5wcz21sxg8l40kdlm2wny-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        1: from /nix/store/04zfivb2qpnfmz8xk3pg24l3r8qd9s0y-testenv/lib/ruby/gems/2.6.0/gems/http-cookie-1.0.3/lib/http/cookie_jar.rb:8:in `<top (required)>'
NameError (uninitialized constant HTTP::CookieJar)

Expected behavior Expect the ruby module to be imported correctly.

Additional context The warnings complaining about already initialized constants suggests that certain files are being required twice.

Metadata

these paths will be fetched (0.00 MiB download, 0.00 MiB unpacked):
  /nix/store/8pkkw458w4q00gp9yrcg95mxc72nzd85-nix-info
copying path '/nix/store/8pkkw458w4q00gp9yrcg95mxc72nzd85-nix-info' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 5.0.0-1033-gcp, Ubuntu, 18.04.4 LTS (Bionic Beaver)`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.3`
 - channels(shuhao): `"nixpkgs-20.09pre217526.9b3515eb95d"`
 - nixpkgs: `/home/shuhao/.nix-defexpr/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
burke commented 4 years ago

FWIW, we work around this by requiring nix_store_safeguard.rb with RUBYOPT, but the solution is... suboptimal. I wonder if there's some alternative strategy that doesn't involve symlinking code (but also doesn't wastefully copy it all).

stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

lilyball commented 3 years ago

If this is the issue I think it is, it can also be solved by copying all gemfiles instead of symlinking them. Which is also suboptimal but better than monkeypatching. With bundlerEnv you can do this by passing copyGemFiles = true. Unfortunately if you use bundlerApp there's no current parameter for this.

shuhaowu commented 3 years ago

Can confirm the above solves the issue. I observed another case today where if i require "minitest" twice, the second time will double include and cause some exceptions.