bundix
bundix copied to clipboard
"Could not find nokogiri..." when starting a new Rails project on macOS 11.4
On an empty directory, I generated a new rails project and ran bundix.
nix-shell \
-p "ruby_3_0.withPackages (ps: with ps; [ rails ])" \
-p bundix \
--run "rails new . && bundle lock && bundix --ruby=ruby_3_0"
Then I wrote a shell.nix
.
with (import <nixpkgs> {});
let
ruby = ruby_3_0;
gems = bundlerEnv {
name = "project-bundler-env";
inherit ruby;
gemdir = ./.;
};
in mkShell { packages = [ gems gems.wrappedRuby ]; }
After running nix-shell
, I got a wrong hash error for the nokogiri
gem.
trying https://rubygems.org/gems/nokogiri-1.11.7.gem
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9134k 100 9134k 0 0 9330k 0 --:--:-- --:--:-- --:--:-- 9320k
hash mismatch in fixed-output derivation '/nix/store/a35hgacdgwh9a52mx6ssf0ijb60axkcn-nokogiri-1.11.7.gem':
wanted: sha256:09gvjipcs9yq3hdxk1cvyjmkrsykg2y6vmcyhr36bcmcpb3xjqc7
got: sha256:1vrn31385ix5k9b0yalnlzv360isv6dincbcvi8psllnwz4sjxj9
cannot build derivation '/nix/store/rn68g11q177bvb95s5bps2vxki8p5lsx-ruby3.0.2-nokogiri-1.11.7.drv': 1 dependencies couldn't be built
I changed the hash in gemset.nix
to the correct one, re-ran nix-shell
and I got a shell. But, all commands complain that nokogiri
is missing and I'm stuck:
$ rails --help
Warning: the running version of Bundler (2.2.20) is older than the version that created the lockfile (2.2.22). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.2.22`.
/nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/spec_set.rb:95:in `block in materialize': Could not find nokogiri-1.11.7-x86_64-darwin in any of the sources (Bundler::GemNotFound)
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/spec_set.rb:90:in `map!'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/spec_set.rb:90:in `materialize'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/definition.rb:189:in `specs'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/definition.rb:258:in `specs_for'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/definition.rb:240:in `requested_specs'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/runtime.rb:91:in `block in definition_method'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler/runtime.rb:20:in `setup'
from /nix/store/9jd5clm6bgqiyxpnlchr4iqm9n490kk4-bundler-2.2.20/lib/ruby/gems/3.0.0/gems/bundler-2.2.20/lib/bundler.rb:149:in `setup'
from /nix/store/p8wa7vvcjq5rxl56rr8wmbgmrfq8r6z2-oioi/bin/rails:18:in `<main>'
Any idea of what I'm doing wrong?
I've the exact same issue on NixOS. Did you manage to find a fix or workaround?
Ok, I've found a workaround.
First the same issue seems to be happening here: https://github.com/NixOS/nixpkgs/pull/132708
So after changing the hash in the gemset.nix
I edited the Gemfile.lock
to remove the platform specific suffix.
- nokogiri (1.11.7-x86_64-linux)
+ nokogiri (1.11.7)
And it worked.
Ah, interesting. Yes, we recently updated our version of bundler
but have been having to delete that whole platform-specific section from the Gemfile.lock
every time we add a new gem
.
I'm having a very similar issue. Gemfile:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 6.1', '>= 6.1.4.1'
shell.nix:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
env = bundlerEnv {
name = "rails-template";
gemdir = ./.;
ruby = ruby_3_0;
};
in mkShell {
buildInputs = [ env env.wrappedRuby ];
}
Here's the trace:
error: hash mismatch in fixed-output derivation '/nix/store/45dir7w67m4bix82ix2r9dh0yh62ac00-nokogiri-1.12.5.gem.drv':
specified: sha256-CGjI0KFHkE1N7aqgWvXwZlby08Z+RDJgFxhVm/adbOo=
got: sha256-KyCQWUKsxYBpfIxJbQ0Wcqthf6y50w0Vazx2duZ5Auw=
error: 1 dependencies of derivation '/nix/store/nmy9l3sf834ibwkk2ppc4ggds8589vd3-ruby3.0.2-nokogiri-1.12.5.drv' failed to build
error: 1 dependencies of derivation '/nix/store/dim8jkkvbzacz03xk192431hmas15s4x-rails-template.drv' failed to build
error: build of '/nix/store/dim8jkkvbzacz03xk192431hmas15s4x-rails-template.drv', '/nix/store/dw9kgq7biihbgp933whidik9ihijb0ph-wrapped-ruby-rails-template.drv' failed
If I change the hash in gemset.nix
, this happens:
/nix/store/62v0v1c8gnxd77gfgkzml4ih68nqqrss-ruby-3.0.2/lib/ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'mini_portile2' (~> 2.6.1) among 79 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/nix/store/rwznrv9bdy94s012risa9p150a9582z7-ruby3.0.2-racc-1.6.0/lib/ruby/gems/3.0.0:/nix/store/62v0v1c8gnxd77gfgkzml4ih68nqqrss-ruby-3.0.2/lib/ruby/gems/3.0.0:/nix/store/g2iizar0gic1bl31avf60dqdpnwzvmbs-ruby3.0.2-nokogiri-1.12.5/lib/ruby/gems/3.0.0' , execute `gem env` for more information
from /nix/store/62v0v1c8gnxd77gfgkzml4ih68nqqrss-ruby-3.0.2/lib/ruby/3.0.0/rubygems/dependency.rb:323:in `to_spec'
from /nix/store/62v0v1c8gnxd77gfgkzml4ih68nqqrss-ruby-3.0.2/lib/ruby/3.0.0/rubygems/core_ext/kernel_gem.rb:62:in `gem'
from extconf.rb:407:in `process_recipe'
from extconf.rb:900:in `<main>'
I'm kind of stuck here...
Looks like I've found an easy way to fix it! Simply run bundler config set force_ruby_platform true
and then bundler won't use platform specific gems anymore! No other actions needed.
bundler config set --local force_ruby_platform true
will make the change to your project local bundler config instead of system wide.
Also hit this issue. In my case platform-specific gem were likely not a factor. I'm was trying to setup a local jekyll environment for my github pages website.
Still hitting this. struggled for a while, and the things in this thread aren't working.
I changed the hash in gemset.nix to the correct one
Can this be explained to me please? gemset.nix
contains strings that get hashed, I think, not the hashes that start with sha256-
and end with =
.
For example, here's my gemset.nix
on nokogiri
nokogiri = {
dependencies = ["racc"];
groups = ["default" "development" "test"];
platforms = [];
source = {
remotes = ["https://rubygems.org"];
sha256 = "1l5940v0s2yr4im2j7fjgi4k1cj21554cprinfqyg0jpwza6zcyw";
type = "gem";
};
version = "1.13.7";
};
Whereas the message, that I could presumably use to correct the sha256
field, looks like this:
error: hash mismatch in fixed-output derivation '/nix/store/vzx1dmrzwgfskl51xs2abfnr4gir96cv-nokogiri-1.13.7.gem.drv':
specified: sha256-3LNv1OdXguexszFfRkoJQrIwSXzSHSlqJNkLDTYgqdA=
got: sha256-bKHXUzNEGOdJvrm7aVFakGRRyav7mlsGCjZlBBm2EFI=
error: 1 dependencies of derivation '/nix/store/i4imakx9sl6nyqq0g4hx2jms11j90hb5-ruby2.7.6-nokogiri-1.13.7.drv' failed to build
error: 1 dependencies of derivation '/nix/store/lz6l6il5zg37xcfvh6ilp24dzkb16wpr-guesstimate-backend-gems.drv' failed to build
error: 1 dependencies of derivation '/nix/store/kmaxw9d6l3s1y0g80gnlwi1shxdis8l4-guesstimate-server-development-env.drv' failed to build
There are different ways to represent the hash.
Replace this:
sha256 = "1l5940v0s2yr4im2j7fjgi4k1cj21554cprinfqyg0jpwza6zcyw";
with this:
sha256 = "sha256-bKHXUzNEGOdJvrm7aVFakGRRyav7mlsGCjZlBBm2EFI=";
Or of course:
hash = "sha256-bKHXUzNEGOdJvrm7aVFakGRRyav7mlsGCjZlBBm2EFI=";
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/issues-with-nix-reproducibility-on-macos-trying-to-build-nokogiri-ruby-error-unknown-warning-option/22019/7
FYI: If you don't have a .bundle/config
yet you need to run BUNDLE_APP_CONFIG="$PWD/.bundle" bundler config set --local force_ruby_platform true
to apply @ymarkus / @jonknapp's fix.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/nokogiri-error-with-jekyll-on-nixos/23933/2
I just put BUNDLE_FORCE_RUBY_PLATFORM = "true";
in my call to mkShell. I had x86_64-linux
in my Gemfile.lock PLATFORMS
and it wouldn't work correctly until I removed that file then re-ran bundler. Then re-ran Bundix of course.