Open vincentbernat opened 4 years ago
The rake
derivation is only useful for its executable when you want to execute a Rakefile.
To get a Ruby that can find rake, use this:
nix-shell -p 'ruby.withPackages (p: [ p.rake ])' --run 'ruby -rrake -e "p Rake::VERSION"'
Or for use in nix-shell:
let
pkgs = import (fetchTarball {
url = https://github.com/nixos/nixpkgs-channels/archive/690dd986b2349d2c9cd6437e820954ed400f37f7.tar.gz;
sha256 = "0p7amn7raw5rahyxw3jq21378n7i7ld4122hm5dddlbcvmpw60p0";
}) {};
in pkgs.mkShell {
buildInputs = [
(pkgs.ruby.withPackages (p: [ p.rake ]))
];
}
The ruby.withPackages
will wrap Ruby with the appropriate GEM_PATH
from a large selection of gems:
[nix-shell:~]$ cat $(which ruby)
#! /nix/store/715fljdrspphbdk255r729zxp4w7lcgk-bash-4.4-p23/bin/bash -e
export GEM_PATH='/nix/store/vcm0inyl5y59168ah5g7wy8z5bcfm2rm-ruby-gems/lib/ruby/gems/2.6.0'
exec "/nix/store/nni62pjp1f43x06hdd8mbxzspx7nsdqx-ruby-2.6.5/bin/ruby" "$@"
Thanks for your input! I thought I had already tried to do that, but I've always left ruby.devEnv
in buildInputs
and in this case, this doesn't work. With nix-shell
:
$ nix-shell -p ruby.devEnv 'ruby.withPackages (p: [ p.rake ])' --run 'ruby -rrake -e "p Rake::VERSION"'
Traceback (most recent call last):
1: from /nix/store/c1y1h2qw06sql1vlwxixkqk9fpw33a8s-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/nix/store/c1y1h2qw06sql1vlwxixkqk9fpw33a8s-ruby-2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- rake (LoadError)
How to install gems when using ruby.devEnv
?
Thanks!
The two are mutually exclusive, the ruby.devEnv
is meant to be used with bundlerEnv
, which you'll need to combine with a gemset.nix
generated from Bundix.
You cannot have two ruby
executables be used in your environment at the same time easily.
In my case, the gemspec is requiring rake
, so to be able to generate Gemfile.lock
and gemset.nix
, I need to have both a ruby with rake as a gem and ability to execute bundle
and bundix
.
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.
Describe the bug
I am trying to package a Ruby application. Inside its gemspec, it does:
So, to build
Gemfile.lock
andgemset.nix
, I am using thisshell.nix
:However, when running
bundle lock
, it complains:Unlike
bundix
,rake
doesn't expose its gem for build. Note that I am not very experienced with Nix. Maybe I am missing something obvious.To Reproduce Steps to reproduce the behavior:
git clone git@github.com:jerakia/jerakia.git
cd jerakia
shell.nix
nix-shell
bundle lock
Alternative:
nix-shell -p rake ruby
Expected behavior
require 'rack'
should load the appropriate lib.Metadata
"x86_64-linux"
Linux 5.4.0-3-amd64, Debian GNU/Linux, noversion
no
yes
nix-env (Nix) 2.3.2
"nixpkgs-20.03pre210705.a6b6fe115ea"
/home/bernat/.nix-defexpr/channels/nixpkgs
Maintainer information:
cc @manveru @nicknovitski