nix-community / bundix

Generates a Nix expression for your Bundler-managed application. [maintainer=@manveru]
163 stars 55 forks source link

gemspec and rake does not work together #73

Open shuhaowu opened 4 years ago

shuhaowu commented 4 years ago

If a gem is created with gemspec within the Gemfile and with rake, then rake doesn't work as it is trying to find the gemspec in /nix/store as opposed to the current directory in nix-shell. This problem has been discussed in IRC in the past, but I don't see an issue for it?

19:35 <emptyfl4sk> I'm having an issue with nix/ruby/bundix/rake: https://gist.github.com/emptyflask/7cab84936deeba15a89090cc16ab0bf2
19:35 <emptyfl4sk> rake is trying to find the gemspec in it's /nix/store directory instead of the current one
19:36 <emptyfl4sk> output is in the above gist 
20:01 <manveru> emptyfl4sk: does your Gemfile happen to have a `gemspec` line in it?
20:02 <manveru> emptyfl4sk: because that's not supported

To reproduce

  1. Create a Gemfile:
source "https://rubygems.org"

gemspec
gem "rake"
  1. Create a gemspec file:
Gem::Specification.new do |spec|
  spec.name          = "abc"
  spec.version       = "1.0"
  spec.authors       = ["1234"]
  spec.email         = ["a@example.com"]

  spec.summary       = %q{Write a short summary, because RubyGems requires one.}
  spec.description   = %q{Write a longer description or delete this line.}
  spec.homepage      = "https://github.com"
end
  1. Run bundix -l and bundix -i to generate the Gemfile.lock, gemset.nix, and shell.nix
  2. Run nix-shell --run "rake" and see the following error:
Traceback (most recent call last):
        8: from /nix/store/svs5z5yvmg3nqgnfnp3zk9gkr7rk3zqn-hi-bundler-env/bin/rake:18:in `<main>'
        7: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:143:in `setup'
        6: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:195:in `definition'
        5: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/definition.rb:34:in `build'
        4: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:12:in `evaluate'
        3: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:47:in `eval_gemfile'
        2: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:47:in `instance_eval'
        1: from /nix/store/ylbnnp1qzwxckvdkamyv7q5pazlhfbwm-gemfile-and-lockfile/Gemfile:3:in `eval_gemfile'
/nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:87:in `gemspec': There are no gemspecs at /nix/store/ylbnnp1qzwxckvdkamyv7q5pazlhfbwm-gemfile-and-lockfile (Bundler::InvalidOption)
        8: from /nix/store/svs5z5yvmg3nqgnfnp3zk9gkr7rk3zqn-hi-bundler-env/bin/rake:18:in `<main>'
        7: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:143:in `setup'
        6: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:195:in `definition'
        5: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/definition.rb:34:in `build'
        4: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:12:in `evaluate'
        3: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:47:in `eval_gemfile'
        2: from /nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:47:in `instance_eval'
        1: from /nix/store/ylbnnp1qzwxckvdkamyv7q5pazlhfbwm-gemfile-and-lockfile/Gemfile:3:in `eval_gemfile'
/nix/store/vi5dq1dhdy60jbz4mjqh86dq777wmbl7-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/dsl.rb:87:in `gemspec':  (Bundler::Dsl::DSLError)
[!] There was an error parsing `Gemfile`: There are no gemspecs at /nix/store/ylbnnp1qzwxckvdkamyv7q5pazlhfbwm-gemfile-and-lockfile. Bundler cannot continue.

 #  from /nix/store/ylbnnp1qzwxckvdkamyv7q5pazlhfbwm-gemfile-and-lockfile/Gemfile:3
 #  -------------------------------------------
 #  
 >  gemspec
 #  gem "rake"
 #  -------------------------------------------

To work around

Do not use gemspec and hard code the dependencies in Gemfile

floehopper commented 2 years ago

I'm having a very similar problem. My use case is that I want to set up a development environment using nix-shell to work on development of a Ruby gem. Most Ruby gems make use of a Gemfile containing a call to gemspec which (by default) looks for a *.gemspec file in the project root directory.

I can successfully create a Gemfile.lock & gemset.nix containing the dependencies specified in the gemspec using nix-shell -p bundix --run 'bundix -l'. However, when I then run nix-shell --pure and try to make use of the bundled gems, I see an error:

$ irb
irb(main):001:0> require 'bundler/setup'

[!] There was an error parsing `Gemfile`: There are no gemspecs at /nix/store/bl4d9v4gfm80l15kfzivgvjzs9y0s2gh-gemfile-and-lockfile. Bundler cannot continue.

 #  from /nix/store/bl4d9v4gfm80l15kfzivgvjzs9y0s2gh-gemfile-and-lockfile/Gemfile:3
 #  -------------------------------------------
 #  
 >  gemspec
 #  
 #  -------------------------------------------

Relevant documentation references:

I'd be happy to work on a fix for this, but I don't really know where to start. Any pointers would be welcome!

floehopper commented 2 years ago

This other issue (https://github.com/nix-community/bundix/issues/76) looks closely related.

ericnorris commented 1 year ago

For posterity, I encountered this error when trying to contribute to a third-party library. Doing some additional Google searches led me to these chat logs:

[15:41] <manveru> joko: https://github.com/asciidoctor/asciidoctor-reveal.js/blob/master/asciidoctor-revealjs.gemspec#L32-L45 those should be in the Gemfile
[15:41] <manveru> and replace the `gemspec` call with them
[15:42] <manveru> i got a bundix v3 in the works that will fix that... but it's pretty low prio atm :|

This confirms that the workaround of moving the gemspec dependencies into the Gemfile is the official solution.

I don't want to propose a change to the upstream library just because bundix doesn't work with gemspecs, and while I can just make the edit locally and not include it in my PR, it'd be nice to see support for gemspecs in bundix.