bundler bin stubs: Squelch sudo warning

@ruby maintainers: please feel free to revert this and let me know,
should it cause any problems.

Stuff that's in the store shouldn't be writable! So let's disable
Bundler's requires_sudo? method, which checks if some files are
writable and suggests using sudo if not, entirely.

Previously, schleuder-cli would print to stderr when run:

Following files may not be writable, so sudo is needed:
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/bin
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/bin
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/build_info
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/bundler
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/cache
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/doc
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/extensions
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/gems
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/plugins
  /nix/store/qg40x0ysrf9x6sag6qgb1klg87lskdp5-schleuder-cli-0.1.0/lib/ruby/gems/2.7.0/specifications
main
Linus Heckemann 2 years ago
parent 1dabedae3e
commit 2dbaea9186
  1. 14
      pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb

@ -41,6 +41,20 @@ Gem.paths = { 'GEM_HOME' => #{bundle_path.dump} }
$LOAD_PATH.unshift #{File.join(bundler_path, "/lib").dump}
require 'bundler'
# Monkey-patch out the check that Bundler performs to determine
# whether the bundler env is writable. It's not writable, even for
# root! And for this use of Bundler, it shouldn't be necessary since
# we're not trying to perform any package management operations, only
# produce a Gem path. Thus, we replace it with a method that will
# always return false, to squelch a warning from Bundler saying that
# sudo may be required.
module Bundler
class <<self
def requires_sudo?
return false
end
end
end
Bundler.setup(#{groups.map(&:dump).join(', ')})
load Gem.bin_path(#{name.dump}, #{exe.dump})

Loading…
Cancel
Save