bundlerEnv: filter gemset groups

This commit is contained in:
Michael Fellinger 2016-04-17 22:33:13 +02:00 committed by Lluís Batlle i Rossell
parent 00f5f08e05
commit 263d467131
2 changed files with 18 additions and 9 deletions

View File

@ -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;

View File

@ -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