bundlerEnv: filter gemset groups
This commit is contained in:
parent
00f5f08e05
commit
263d467131
|
@ -10,6 +10,7 @@
|
||||||
, postBuild ? null
|
, postBuild ? null
|
||||||
, document ? []
|
, document ? []
|
||||||
, meta ? {}
|
, meta ? {}
|
||||||
|
, groups ? ["default"]
|
||||||
, ignoreCollisions ? false
|
, ignoreCollisions ? false
|
||||||
, ...
|
, ...
|
||||||
}@args:
|
}@args:
|
||||||
|
@ -18,14 +19,19 @@ let
|
||||||
|
|
||||||
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
|
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
|
||||||
importedGemset = import gemset;
|
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:
|
applyGemConfigs = attrs:
|
||||||
(if gemConfig ? "${attrs.gemName}"
|
(if gemConfig ? "${attrs.gemName}"
|
||||||
then attrs // gemConfig."${attrs.gemName}" attrs
|
then attrs // gemConfig."${attrs.gemName}" attrs
|
||||||
else attrs);
|
else attrs);
|
||||||
configuredGemset = lib.flip lib.mapAttrs importedGemset (name: attrs:
|
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
|
||||||
applyGemConfigs (attrs // { gemName = name; })
|
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; });
|
bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; });
|
||||||
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs:
|
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs:
|
||||||
buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // {
|
buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // {
|
||||||
|
@ -52,7 +58,8 @@ let
|
||||||
"${confFiles}/Gemfile" \
|
"${confFiles}/Gemfile" \
|
||||||
"$out/${ruby.gemPath}" \
|
"$out/${ruby.gemPath}" \
|
||||||
"${bundler}/${ruby.gemPath}" \
|
"${bundler}/${ruby.gemPath}" \
|
||||||
${shellEscape (toString envPaths)}
|
${shellEscape (toString envPaths)} \
|
||||||
|
${shellEscape (toString groups)}
|
||||||
'' + lib.optionalString (postBuild != null) postBuild;
|
'' + lib.optionalString (postBuild != null) postBuild;
|
||||||
passthru = rec {
|
passthru = rec {
|
||||||
inherit ruby bundler meta gems;
|
inherit ruby bundler meta gems;
|
||||||
|
|
|
@ -10,6 +10,7 @@ gemfile = ARGV[1]
|
||||||
bundle_path = ARGV[2]
|
bundle_path = ARGV[2]
|
||||||
bundler_gem_path = ARGV[3]
|
bundler_gem_path = ARGV[3]
|
||||||
paths = ARGV[4].split
|
paths = ARGV[4].split
|
||||||
|
groups = ARGV[5].split
|
||||||
|
|
||||||
# generate binstubs
|
# generate binstubs
|
||||||
FileUtils.mkdir_p("#{out}/bin")
|
FileUtils.mkdir_p("#{out}/bin")
|
||||||
|
@ -29,15 +30,16 @@ paths.each do |path|
|
||||||
# this file is here to facilitate running it.
|
# this file is here to facilitate running it.
|
||||||
#
|
#
|
||||||
|
|
||||||
ENV["BUNDLE_GEMFILE"] = "#{gemfile}"
|
ENV["BUNDLE_GEMFILE"] = #{gemfile.dump}
|
||||||
ENV["BUNDLE_PATH"] = "#{bundle_path}"
|
ENV["BUNDLE_PATH"] = #{bundle_path.dump}
|
||||||
ENV['BUNDLE_FROZEN'] = '1'
|
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
|
EOF
|
||||||
FileUtils.chmod("+x", "#{out}/bin/#{exe}")
|
FileUtils.chmod("+x", "#{out}/bin/#{exe}")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue