Merge pull request #12284 from abbradar/bundlerenv-wrapper

bundlerEnv: add wrapper

+50 -6
+32
doc/languages-frameworks/ruby.xml
··· 42 <para>Please check in the <filename>Gemfile</filename>, <filename>Gemfile.lock</filename> and the <filename>gemset.nix</filename> so future updates can be run easily. 43 </para> 44 45 </section> 46
··· 42 <para>Please check in the <filename>Gemfile</filename>, <filename>Gemfile.lock</filename> and the <filename>gemset.nix</filename> so future updates can be run easily. 43 </para> 44 45 + <para>Resulting derivations also have two helpful items, <literal>env</literal> and <literal>wrapper</literal>. The first one allows one to quickly drop into 46 + <command>nix-shell</command> with the specified environment present. E.g. <command>nix-shell -A sensu.env</command> would give you an environment with Ruby preset 47 + so it has all the libraries necessary for <literal>sensu</literal> in its paths. The second one can be used to make derivations from custom Ruby scripts which have 48 + <filename>Gemfile</filename>s with their dependencies specified. It is a derivation with <command>ruby</command> wrapped so it can find all the needed dependencies. 49 + For example, to make a derivation <literal>my-script</literal> for a <filename>my-script.rb</filename> (which should be placed in <filename>bin</filename>) you should 50 + run <command>bundix</command> as specified above and then use <literal>bundlerEnv</literal> lile this:</para> 51 + 52 + <programlisting> 53 + <![CDATA[let env = bundlerEnv { 54 + name = "my-script-env"; 55 + 56 + inherit ruby; 57 + gemfile = ./Gemfile; 58 + lockfile = ./Gemfile.lock; 59 + gemset = ./gemset.nix; 60 + }; 61 + 62 + in stdenv.mkDerivation { 63 + name = "my-script"; 64 + 65 + buildInputs = [ env.wrapper ]; 66 + 67 + script = ./my-script.rb; 68 + 69 + buildCommand = '' 70 + mkdir -p $out/bin 71 + install -D -m755 $script $out/bin/my-script 72 + patchShebangs $out/bin/my-script 73 + ''; 74 + }]]> 75 + </programlisting> 76 + 77 </section> 78
+18 -6
pkgs/development/interpreters/ruby/bundler-env/default.nix
··· 65 "${bundler}/${ruby.gemPath}" \ 66 ${shellEscape (toString envPaths)} 67 '' + lib.optionalString (postBuild != null) postBuild; 68 - passthru = { 69 inherit ruby bundler meta gems; 70 env = let 71 irbrc = builtins.toFile "irbrc" '' 72 if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) ··· 77 ''; 78 in stdenv.mkDerivation { 79 name = "interactive-${name}-environment"; 80 - nativeBuildInputs = [ ruby bundlerEnv ]; 81 shellHook = '' 82 - export BUNDLE_GEMFILE=${confFiles}/Gemfile 83 - export BUNDLE_PATH=${bundlerEnv}/${ruby.gemPath} 84 - export GEM_HOME=${bundlerEnv}/${ruby.gemPath} 85 - export GEM_PATH=${bundlerEnv}/${ruby.gemPath} 86 export OLD_IRBRC="$IRBRC" 87 export IRBRC=${irbrc} 88 '';
··· 65 "${bundler}/${ruby.gemPath}" \ 66 ${shellEscape (toString envPaths)} 67 '' + lib.optionalString (postBuild != null) postBuild; 68 + passthru = rec { 69 inherit ruby bundler meta gems; 70 + 71 + wrapper = stdenv.mkDerivation { 72 + name = "wrapper-${name}"; 73 + nativeBuildInputs = [ makeWrapper ]; 74 + buildCommand = '' 75 + mkdir -p $out/bin 76 + for i in ${ruby}/bin/*; do 77 + makeWrapper "$i" $out/bin/$(basename "$i") \ 78 + --set BUNDLE_GEMFILE ${confFiles}/Gemfile \ 79 + --set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \ 80 + --set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \ 81 + --set GEM_PATH ${bundlerEnv}/${ruby.gemPath} 82 + done 83 + ''; 84 + }; 85 + 86 env = let 87 irbrc = builtins.toFile "irbrc" '' 88 if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) ··· 93 ''; 94 in stdenv.mkDerivation { 95 name = "interactive-${name}-environment"; 96 + nativeBuildInputs = [ wrapper bundlerEnv ]; 97 shellHook = '' 98 export OLD_IRBRC="$IRBRC" 99 export IRBRC=${irbrc} 100 '';