bundix
bundix copied to clipboard
`bundix -m` fails on bundler >= 2.0
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
Related: https://github.com/NixOS/nixpkgs/issues/68089
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.
--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