2017-05-10 20:00:21 +03:00
|
|
|
{ lib, gemConfig, ... }:
|
2017-04-25 04:45:00 +03:00
|
|
|
rec {
|
2017-05-31 19:44:46 +03:00
|
|
|
bundlerFiles = {
|
|
|
|
gemfile ? null
|
|
|
|
, lockfile ? null
|
|
|
|
, gemset ? null
|
|
|
|
, gemdir ? null
|
|
|
|
, ...
|
|
|
|
}: {
|
2017-06-26 03:40:22 +03:00
|
|
|
inherit gemdir;
|
|
|
|
|
2017-05-31 19:44:46 +03: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;
|
|
|
|
};
|
|
|
|
|
2017-05-10 20:00:21 +03:00
|
|
|
filterGemset = {ruby, groups,...}@env: gemset: lib.filterAttrs (name: attrs: platformMatches ruby attrs && groupMatches groups attrs) gemset;
|
2017-05-01 19:07:42 +03:00
|
|
|
|
2017-05-10 20:00:21 +03:00
|
|
|
platformMatches = {rubyEngine, version, ...}@ruby: attrs: (
|
2017-04-25 04:45:00 +03:00
|
|
|
!(attrs ? "platforms") ||
|
2017-05-12 19:44:39 +03:00
|
|
|
builtins.length attrs.platforms == 0 ||
|
2017-04-25 04:45:00 +03:00
|
|
|
builtins.any (platform:
|
2017-05-10 20:00:21 +03:00
|
|
|
platform.engine == rubyEngine &&
|
2017-05-12 19:47:00 +03:00
|
|
|
(!(platform ? "version") || platform.version == version.majMin)
|
2017-04-25 04:45:00 +03:00
|
|
|
) attrs.platforms
|
|
|
|
);
|
|
|
|
|
2017-05-10 20:00:21 +03:00
|
|
|
groupMatches = groups: attrs: (
|
2017-04-25 04:45:00 +03:00
|
|
|
!(attrs ? "groups") ||
|
|
|
|
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
|
|
|
|
);
|
|
|
|
|
|
|
|
applyGemConfigs = attrs:
|
|
|
|
(if gemConfig ? "${attrs.gemName}"
|
|
|
|
then attrs // gemConfig."${attrs.gemName}" attrs
|
|
|
|
else attrs);
|
|
|
|
|
2017-05-04 06:27:42 +03:00
|
|
|
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
|
2017-04-25 04:45:00 +03: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-05-10 20:00:21 +03:00
|
|
|
composeGemAttrs = ruby: gems: name: attrs: ((removeAttrs attrs ["source" "platforms"]) // attrs.source // {
|
2017-04-25 04:45:00 +03:00
|
|
|
inherit ruby;
|
|
|
|
gemName = name;
|
|
|
|
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
|
|
|
|
});
|
|
|
|
}
|