2017-05-10 19:00:21 +02:00
|
|
|
{ lib, gemConfig, ... }:
|
2018-12-11 22:18:22 +01:00
|
|
|
|
|
|
|
let
|
2018-12-11 22:19:32 +01:00
|
|
|
inherit (lib) attrValues concatMap converge filterAttrs getAttrs
|
|
|
|
intersectLists;
|
2018-12-11 22:18:22 +01:00
|
|
|
|
|
|
|
in rec {
|
2017-05-31 18:44:46 +02:00
|
|
|
bundlerFiles = {
|
|
|
|
gemfile ? null
|
|
|
|
, lockfile ? null
|
|
|
|
, gemset ? null
|
|
|
|
, gemdir ? null
|
|
|
|
, ...
|
|
|
|
}: {
|
2017-06-26 02:40:22 +02:00
|
|
|
inherit gemdir;
|
|
|
|
|
2017-05-31 18:44:46 +02:00
|
|
|
gemfile =
|
|
|
|
if gemfile == null then assert gemdir != null; gemdir + "/Gemfile"
|
|
|
|
else gemfile;
|
|
|
|
|
|
|
|
lockfile =
|
|
|
|
if lockfile == null then assert gemdir != null; gemdir + "/Gemfile.lock"
|
|
|
|
else lockfile;
|
|
|
|
|
|
|
|
gemset =
|
|
|
|
if gemset == null then assert gemdir != null; gemdir + "/gemset.nix"
|
|
|
|
else gemset;
|
|
|
|
};
|
|
|
|
|
2018-12-11 22:18:22 +01:00
|
|
|
filterGemset = { ruby, groups, ... }: gemset:
|
|
|
|
let
|
|
|
|
platformGems = filterAttrs (_: platformMatches ruby) gemset;
|
|
|
|
directlyMatchingGems = filterAttrs (_: groupMatches groups) platformGems;
|
|
|
|
|
|
|
|
expandDependencies = gems:
|
|
|
|
let
|
|
|
|
depNames = concatMap (gem: gem.dependencies or []) (attrValues gems);
|
|
|
|
deps = getAttrs depNames platformGems;
|
|
|
|
in
|
|
|
|
gems // deps;
|
|
|
|
in
|
|
|
|
converge expandDependencies directlyMatchingGems;
|
2017-05-01 18:07:42 +02:00
|
|
|
|
2018-07-20 21:54:05 +02:00
|
|
|
platformMatches = {rubyEngine, version, ...}: attrs: (
|
2017-04-25 03:45:00 +02:00
|
|
|
!(attrs ? "platforms") ||
|
2017-05-12 18:44:39 +02:00
|
|
|
builtins.length attrs.platforms == 0 ||
|
2017-04-25 03:45:00 +02:00
|
|
|
builtins.any (platform:
|
2017-05-10 19:00:21 +02:00
|
|
|
platform.engine == rubyEngine &&
|
2017-05-12 18:47:00 +02:00
|
|
|
(!(platform ? "version") || platform.version == version.majMin)
|
2017-04-25 03:45:00 +02:00
|
|
|
) attrs.platforms
|
|
|
|
);
|
|
|
|
|
2018-12-11 22:19:32 +01:00
|
|
|
groupMatches = groups: attrs:
|
|
|
|
groups == null || !(attrs ? "groups") ||
|
2018-12-11 22:22:45 +01:00
|
|
|
(intersectLists (groups ++ [ "default" ]) attrs.groups) != [];
|
2017-04-25 03:45:00 +02:00
|
|
|
|
|
|
|
applyGemConfigs = attrs:
|
|
|
|
(if gemConfig ? "${attrs.gemName}"
|
|
|
|
then attrs // gemConfig."${attrs.gemName}" attrs
|
|
|
|
else attrs);
|
|
|
|
|
2017-05-04 05:27:42 +02:00
|
|
|
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
|
2017-04-25 03:45:00 +02:00
|
|
|
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
|
|
|
|
"${ruby}/bin/ruby" \
|
|
|
|
"${confFiles}/Gemfile" \
|
|
|
|
"$out/${ruby.gemPath}" \
|
|
|
|
"${bundler}/${ruby.gemPath}" \
|
|
|
|
${lib.escapeShellArg binPaths} \
|
|
|
|
${lib.escapeShellArg groups}
|
|
|
|
'';
|
|
|
|
|
|
|
|
pathDerivation = { gemName, version, path, ... }:
|
|
|
|
let
|
|
|
|
res = {
|
|
|
|
type = "derivation";
|
|
|
|
bundledByPath = true;
|
|
|
|
name = gemName;
|
|
|
|
version = version;
|
|
|
|
outPath = path;
|
|
|
|
outputs = [ "out" ];
|
|
|
|
out = res;
|
|
|
|
outputName = "out";
|
|
|
|
};
|
|
|
|
in res;
|
|
|
|
|
2017-10-05 10:10:57 +02:00
|
|
|
composeGemAttrs = ruby: gems: name: attrs: ((removeAttrs attrs ["platforms"]) // {
|
2017-04-25 03:45:00 +02:00
|
|
|
inherit ruby;
|
2017-10-05 10:10:57 +02:00
|
|
|
inherit (attrs.source) type;
|
|
|
|
source = removeAttrs attrs.source ["type"];
|
2017-04-25 03:45:00 +02:00
|
|
|
gemName = name;
|
|
|
|
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
|
|
|
|
});
|
|
|
|
}
|