Updates to bundlerEnv

This commit is contained in:
Judson 2017-02-19 10:18:54 -08:00
parent 13d6681ce7
commit c765f680e3
No known key found for this signature in database
GPG Key ID: 1817B08954BF0B7D

View File

@ -46,11 +46,20 @@ let
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);
platformMatches = attrs: (
!(attrs ? "platforms") ||
builtins.any (platform:
platform.engine == ruby.rubyEngine &&
(!(platform ? "version") || platform.version == ruby.version.majMin)
) attrs.platforms
);
groupMatches = attrs: (
!(attrs ? "groups") ||
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
);
filteredGemset = lib.filterAttrs (name: attrs: platformMatches attrs && groupMatches attrs) importedGemset;
applyGemConfigs = attrs:
(if gemConfig ? "${attrs.gemName}"
@ -67,25 +76,54 @@ let
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 // {
inherit ruby;
gemName = name;
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
}));
pathDerivation = {
usesGemspec ? false, ...
}@attrs:
let
res = {
inherit usesGemspec;
type = "derivation";
name = attrs.gemName;
version = attrs.version;
outPath = attrs.path;
outputs = [ "out" ];
out = res;
outputName = "out";
};
in res;
buildGem = name: attrs: (
let
gemAttrs = ((removeAttrs attrs ["source"]) // attrs.source // {
inherit ruby;
gemName = name;
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
});
in
if gemAttrs.type == "path" then pathDerivation gemAttrs
else buildRubyGem gemAttrs);
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
maybeCopyAll = { usesGemspec ? false, ...}@main:
(if usesGemspec then ''
cp -a ${gemdir}/* $out/
'' else ""
);
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
# helpful by doing so at run time, causing executables to immediately bail
# out. Yes, I'm serious.
confFiles = runCommand "gemfile-and-lockfile" {} ''
mkdir -p $out
cp ${gemfile'} $out/Gemfile
cp ${lockfile'} $out/Gemfile.lock
${maybeCopyAll mainGem}
cp ${gemfile'} $out/Gemfile || ls -l $out/Gemfile
cp ${lockfile'} $out/Gemfile.lock || ls -l $out/Gemfile.lock
'';
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
binPaths = if mainGem != null then [ mainGem ] else envPaths;
binPaths = if mainGem != null then [ mainGem ] ++ envPaths else envPaths;
bundlerEnv = buildEnv {
inherit ignoreCollisions;