Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundix -m fails on bundler >= 2.0 #70

Open
endgame opened this issue Apr 22, 2020 · 3 comments
Open

bundix -m fails on bundler >= 2.0 #70

endgame opened this issue Apr 22, 2020 · 3 comments

Comments

@endgame
Copy link

endgame commented Apr 22, 2020

Running bundix -m with a modern bundler fails thus:

Fetching gem metadata from https://rubygems.org/.
Writing lockfile to /home/endgame/code/nix-overlay/sorbet/Gemfile.lock
Unknown switches "--all"
Traceback (most recent call last):
	5: from /nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/bin/.bundix-wrapped:18:in `<main>'
	4: from /nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/bin/.bundix-wrapped:18:in `load'
	3: from /nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/lib/ruby/gems/2.6.0/gems/bundix-2.5.0/bin/bundix:5:in `<top (required)>'
	2: from /nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/lib/ruby/gems/2.6.0/gems/bundix-2.5.0/lib/bundix/commandline.rb:22:in `run'
	1: from /nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/lib/ruby/gems/2.6.0/gems/bundix-2.5.0/lib/bundix/commandline.rb:33:in `run'
/nix/store/67mivbf50ixz8nqsvrby4dhp0z16qwkr-bundix-2.5.0/lib/ruby/gems/2.6.0/gems/bundix-2.5.0/lib/bundix/commandline.rb:107:in `handle_magic': unhandled exception

Bundix version: 2.5.0 from nixos-20.03
Bundler version 2.1.4 from nixos-20.03

@lrworth
Copy link

lrworth commented Apr 22, 2020

Related: NixOS/nixpkgs#68089

@tomeon
Copy link

tomeon commented Jul 1, 2020

Relevant commit at the old Bundler repo.

Looks like there's been a lot of churn w.r.t. the bundler {cache,package,pack} --all flag (try git log -G 'feature_flag.*cache_all' -p in the old Bundler repo).

As I read the relevant docs, it looks like the local <app>/.bundle/config overrides BUNDLE_* settings in the environment, which means that restoring the --all flag isn't as simple as setting BUNDLE_CACHE_ALL=false in the controlling environment of bundle pack. On the other handle, also setting BUNDLE_IGNORE_CONFIG=true appears to work:

$ cd "$(mktemp -d)"
$ mkdir -p .bundle
$ printf > .bundle/config -- '---\nBUNDLE_CACHE_ALL: "true"\n'
$ bundle help pack' | grep -e --all
$ printf > .bundle/config -- '---\nBUNDLE_CACHE_ALL: "true"\n'
$ nix-shell --pure -p bundler --run 'BUNDLE_CACHE_ALL=false bundle help pack' | grep -e --all
      [--all-platforms=Include gems for all platforms present in the lockfile, not only the current one], [--no-all-platforms] 
$ rm -f .bundle/config 
$ nix-shell --pure -p bundler --run 'BUNDLE_CACHE_ALL=false bundle help pack' | grep -e --all
      [--all=Include all sources (including path and git).], [--no-all]                                                                                            
      [--all-platforms=Include gems for all platforms present in the lockfile, not only the current one], [--no-all-platforms] 
$ printf > .bundle/config -- '---\nBUNDLE_CACHE_ALL: "true"\n'
$ nix-shell --pure -p bundler --run 'BUNDLE_IGNORE_CONFIG=true BUNDLE_CACHE_ALL=false bundle help pack' | grep -e --all
      [--all=Include all sources (including path and git).], [--no-all]                                                                                            
      [--all-platforms=Include gems for all platforms present in the lockfile, not only the current one], [--no-all-platforms]

Not sure whether it is acceptable or desirable for bundix to ignore the user's Bundler config, though.

@lrworth
Copy link

lrworth commented Feb 1, 2021

--all is a valid command line argument to bundle pack if and only if cache_all is false. Passing --all when it is valid has the side effect of setting cache_all to true, so the next invocation with --all has an error. 👏👏

Since running bundix -m already has the side-effect of setting cache_all (because it executes bundler pack --all), I propose changing the code around https://github.com/nix-community/bundix/blob/master/lib/bundix/commandline.rb#L110 along the lines of:

        fail unless system(
          Bundix::NIX_SHELL, '-p', options[:ruby],
          "bundler.override { ruby = #{options[:ruby]}; }",
          "--command", "bundle config --local cache_all true")
        fail unless system(
          Bundix::NIX_SHELL, '-p', options[:ruby],
          "bundler.override { ruby = #{options[:ruby]}; }",
          "--command", "bundle pack --path #{options[:bundle_pack_path]}")

This will not be needed in bundler 3 according to the documentation for cache_all.

BTW, as a workaround for this bug, I've been running bundix like this:

bundle config --local cache_all false && $(nix-build '<nixpkgs>' -A bundix --no-out-link)/bin/bundix --magic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants