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'; importedGemset = import gemset';
filteredGemset = (lib.filterAttrs (name: attrs: platformMatches = attrs: (
if (builtins.hasAttr "groups" attrs) !(attrs ? "platforms") ||
then (builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups) builtins.any (platform:
else true platform.engine == ruby.rubyEngine &&
) importedGemset); (!(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: applyGemConfigs = attrs:
(if gemConfig ? "${attrs.gemName}" (if gemConfig ? "${attrs.gemName}"
@ -67,25 +76,54 @@ let
if hasBundler then gems.bundler if hasBundler then gems.bundler
else defs.bundler.override (attrs: { inherit ruby; }); else defs.bundler.override (attrs: { inherit ruby; });
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: pathDerivation = {
buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // { 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; inherit ruby;
gemName = name; gemName = name;
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []); 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 # We have to normalize the Gemfile.lock, otherwise bundler tries to be
# helpful by doing so at run time, causing executables to immediately bail # helpful by doing so at run time, causing executables to immediately bail
# out. Yes, I'm serious. # out. Yes, I'm serious.
confFiles = runCommand "gemfile-and-lockfile" {} '' confFiles = runCommand "gemfile-and-lockfile" {} ''
mkdir -p $out mkdir -p $out
cp ${gemfile'} $out/Gemfile ${maybeCopyAll mainGem}
cp ${lockfile'} $out/Gemfile.lock 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; 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 { bundlerEnv = buildEnv {
inherit ignoreCollisions; inherit ignoreCollisions;