From 75358ad0e7a143ad6849882a1967ef6a5c2e6e68 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 6 Jan 2016 21:43:22 +0300 Subject: [PATCH 1/2] bundlerEnv: add wrapper --- .../interpreters/ruby/bundler-env/default.nix | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pkgs/development/interpreters/ruby/bundler-env/default.nix b/pkgs/development/interpreters/ruby/bundler-env/default.nix index c7570d815e3..fdafa5f8f12 100644 --- a/pkgs/development/interpreters/ruby/bundler-env/default.nix +++ b/pkgs/development/interpreters/ruby/bundler-env/default.nix @@ -65,8 +65,24 @@ let "${bundler}/${ruby.gemPath}" \ ${shellEscape (toString envPaths)} '' + lib.optionalString (postBuild != null) postBuild; - passthru = { + passthru = rec { inherit ruby bundler meta gems; + + wrapper = stdenv.mkDerivation { + name = "wrapper-${name}"; + nativeBuildInputs = [ makeWrapper ]; + buildCommand = '' + mkdir -p $out/bin + for i in ${ruby}/bin/*; do + makeWrapper "$i" $out/bin/$(basename "$i") \ + --set BUNDLE_GEMFILE ${confFiles}/Gemfile \ + --set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \ + --set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \ + --set GEM_PATH ${bundlerEnv}/${ruby.gemPath} + done + ''; + }; + env = let irbrc = builtins.toFile "irbrc" '' if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) @@ -77,12 +93,8 @@ let ''; in stdenv.mkDerivation { name = "interactive-${name}-environment"; - nativeBuildInputs = [ ruby bundlerEnv ]; + nativeBuildInputs = [ wrapper bundlerEnv ]; shellHook = '' - export BUNDLE_GEMFILE=${confFiles}/Gemfile - export BUNDLE_PATH=${bundlerEnv}/${ruby.gemPath} - export GEM_HOME=${bundlerEnv}/${ruby.gemPath} - export GEM_PATH=${bundlerEnv}/${ruby.gemPath} export OLD_IRBRC="$IRBRC" export IRBRC=${irbrc} ''; From a98dfaa6b96a00b6822f25ca7638d4ae7d57a855 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 21 Jan 2016 13:07:56 +0300 Subject: [PATCH 2/2] nix manual: add bundlerEnv.env and .wrapper items descriptions --- doc/languages-frameworks/ruby.xml | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doc/languages-frameworks/ruby.xml b/doc/languages-frameworks/ruby.xml index a2b4475a4a5..d81422b610e 100644 --- a/doc/languages-frameworks/ruby.xml +++ b/doc/languages-frameworks/ruby.xml @@ -42,5 +42,37 @@ and scalable."; Please check in the Gemfile, Gemfile.lock and the gemset.nix so future updates can be run easily. +Resulting derivations also have two helpful items, env and wrapper. The first one allows one to quickly drop into +nix-shell with the specified environment present. E.g. nix-shell -A sensu.env would give you an environment with Ruby preset +so it has all the libraries necessary for sensu in its paths. The second one can be used to make derivations from custom Ruby scripts which have +Gemfiles with their dependencies specified. It is a derivation with ruby wrapped so it can find all the needed dependencies. +For example, to make a derivation my-script for a my-script.rb (which should be placed in bin) you should +run bundix as specified above and then use bundlerEnv lile this: + + + + +