NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.36k stars 14.32k forks source link

Bundler warns about non-writable files when in bundlerEnv #101479

Open ryantm opened 4 years ago

ryantm commented 4 years ago

Is it expected that we get this sudo warning from bundler when using bundlerEnv? Is there anything we can do about it?

![image](https://user-images.githubusercontent.com/2377/78890343-5f70da00-7a5d-11ea-80f3-83007a5c1217.png) ``` [nix-shell:~/Developer/web]$ cat $(which rails) #!/nix/store/q96lzix9isfmh9cbhb7ah65naq2v82z2-ruby-2.6.6/bin/ruby # # This file was generated by Nix. # # The application 'rails' is installed as part of a gem, and # this file is here to facilitate running it. # ENV["BUNDLE_GEMFILE"] = "/nix/store/mnsbdlw174p05d8civb7ggixndl3wk5r-gemfile-and-lockfile/Gemfile" ENV.delete 'BUNDLE_PATH' ENV['BUNDLE_FROZEN'] = '1' Gem.paths = { 'GEM_HOME' => "/nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0" } $LOAD_PATH.unshift "/nix/store/vwmskqd95mq5hxb6jzgxplmmb79srf0n-bundler-2.1.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib" require 'bundler' Bundler.setup("default", "assets", "development", "test") load Gem.bin_path("railties", "rails") [nix-shell:~/Developer/web]$ rails console Following files may not be writable, so sudo is needed: /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0 /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/bin /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/bin /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/build_info /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/build_info/libv8-7.3.492.27.1.info /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/build_info/mini_racer-0.2.9.info /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/build_info/nokogiri-1.10.9.info /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/build_info/sassc-2.2.1.info /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/bundler /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/cache /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/doc /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/extensions /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/gems /nix/store/2hz3bsbi0ny5d7chsysac1m5avm7x9mf-gems-for-audioboom/lib/ruby/gems/2.6.0/specifications Running via Spring preloader in process 34287 Loading development environment (Rails 6.0.2.2) irb(main):001:0> ```

It seems harmless but annoying, pops up whenever you run a bundled gem executable.

Originally posted by @jdelStrother in https://github.com/NixOS/nixpkgs/pull/81442#issuecomment-611478478

ryantm commented 4 years ago

Hit this too. It looks like we should patch bundler to check if we are in a bundlerEnv, and silence this warning.

ryantm commented 4 years ago

I made an upstream pr https://github.com/rubygems/rubygems/pull/4032 that would allow us to set an environment variable to avoid these messages.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

jdelStrother commented 3 years ago

In the meantime, I use a hack to silence the warning:

{
  bundler_ = ruby: rec {
    inherit ruby;
    name = "${gemName}-${version}";
    gemName = "bundler";
    version = "2.2.11";
    source = {
      remotes = ["https://rubygems.org"];
      sha256 = "1izx6wsjdm6mnbxazgz1z5qbhwrrisbq0np2nmx4ij6lrqjy18jf";
      type = "gem";
    };
    # silence an annoying warning about sudo being needed:
    postInstall = ''
      sed -i -e '/if sudo_needed/I,+2 d' $out/${ruby.gemPath}/gems/${gemName}-${version}/lib/bundler.rb
    '';
  };

  bundler = bundler_ pkgs.ruby_2_7;
}