From 263d46713191adbae10839e25e9da11cfd6fb96b Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sun, 17 Apr 2016 22:33:13 +0200 Subject: [PATCH] bundlerEnv: filter gemset groups --- .../ruby-modules/bundler-env/default.nix | 15 +++++++++++---- .../ruby-modules/bundler-env/gen-bin-stubs.rb | 12 +++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkgs/development/ruby-modules/bundler-env/default.nix b/pkgs/development/ruby-modules/bundler-env/default.nix index 597acc25b30d..4ebba0d5b653 100644 --- a/pkgs/development/ruby-modules/bundler-env/default.nix +++ b/pkgs/development/ruby-modules/bundler-env/default.nix @@ -10,6 +10,7 @@ , postBuild ? null , document ? [] , meta ? {} +, groups ? ["default"] , ignoreCollisions ? false , ... }@args: @@ -18,14 +19,19 @@ let shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'"; importedGemset = import gemset; + filteredGemset = (lib.filterAttrs (name: attrs: + if (builtins.hasAttr "groups" attrs) + then (builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups) + else true + ) importedGemset); applyGemConfigs = attrs: (if gemConfig ? "${attrs.gemName}" then attrs // gemConfig."${attrs.gemName}" attrs else attrs); - configuredGemset = lib.flip lib.mapAttrs importedGemset (name: attrs: - applyGemConfigs (attrs // { gemName = name; }) + configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs: + applyGemConfigs (attrs // { inherit ruby; gemName = name; }) ); - hasBundler = builtins.hasAttr "bundler" importedGemset; + hasBundler = builtins.hasAttr "bundler" filteredGemset; bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; }); gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // { @@ -52,7 +58,8 @@ let "${confFiles}/Gemfile" \ "$out/${ruby.gemPath}" \ "${bundler}/${ruby.gemPath}" \ - ${shellEscape (toString envPaths)} + ${shellEscape (toString envPaths)} \ + ${shellEscape (toString groups)} '' + lib.optionalString (postBuild != null) postBuild; passthru = rec { inherit ruby bundler meta gems; diff --git a/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb b/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb index 8609a863e50e..92321d6427dc 100644 --- a/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb +++ b/pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb @@ -10,6 +10,7 @@ gemfile = ARGV[1] bundle_path = ARGV[2] bundler_gem_path = ARGV[3] paths = ARGV[4].split +groups = ARGV[5].split # generate binstubs FileUtils.mkdir_p("#{out}/bin") @@ -29,15 +30,16 @@ paths.each do |path| # this file is here to facilitate running it. # -ENV["BUNDLE_GEMFILE"] = "#{gemfile}" -ENV["BUNDLE_PATH"] = "#{bundle_path}" +ENV["BUNDLE_GEMFILE"] = #{gemfile.dump} +ENV["BUNDLE_PATH"] = #{bundle_path.dump} ENV['BUNDLE_FROZEN'] = '1' -Gem.use_paths("#{bundler_gem_path}", ENV["GEM_PATH"]) +Gem.use_paths(#{bundler_gem_path.dump}, ENV["GEM_PATH"]) -require 'bundler/setup' +require 'bundler' +Bundler.setup(#{groups.map(&:dump).join(', ')}) -load Gem.bin_path(#{name.inspect}, #{exe.inspect}) +load Gem.bin_path(#{name.dump}, #{exe.dump}) EOF FileUtils.chmod("+x", "#{out}/bin/#{exe}") end