nixpkgs/pkgs/development/ruby-modules/bundled-common/functions.nix

94 lines
2.6 KiB
Nix
Raw Normal View History

{ lib, gemConfig, ... }:
let
inherit (lib) attrValues concatMap converge filterAttrs getAttrs
intersectLists;
in rec {
bundlerFiles = {
gemfile ? null
, lockfile ? null
, gemset ? null
, gemdir ? null
, ...
}: {
2017-06-26 01:40:22 +01:00
inherit gemdir;
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;
};
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 17:07:42 +01:00
platformMatches = {rubyEngine, version, ...}: attrs: (
2019-08-13 22:52:01 +01:00
!(attrs ? platforms) ||
2017-05-12 17:44:39 +01:00
builtins.length attrs.platforms == 0 ||
2017-04-25 02:45:00 +01:00
builtins.any (platform:
platform.engine == rubyEngine &&
2019-08-13 22:52:01 +01:00
(!(platform ? version) || platform.version == version.majMin)
2017-04-25 02:45:00 +01:00
) attrs.platforms
);
groupMatches = groups: attrs:
2019-08-13 22:52:01 +01:00
groups == null || !(attrs ? groups) ||
(intersectLists (groups ++ [ "default" ]) attrs.groups) != [];
2017-04-25 02:45:00 +01:00
applyGemConfigs = attrs:
2019-08-13 22:52:01 +01:00
(if gemConfig ? ${attrs.gemName}
then attrs // gemConfig.${attrs.gemName} attrs
2017-04-25 02:45:00 +01:00
else attrs);
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
2017-04-25 02:45:00 +01:00
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
"${ruby}/bin/ruby" \
"${confFiles}/Gemfile" \
"$out/${ruby.gemPath}" \
"${bundler}/${ruby.gemPath}/gems/bundler-${bundler.version}" \
2017-04-25 02:45:00 +01:00
${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;
composeGemAttrs = ruby: gems: name: attrs: ((removeAttrs attrs ["platforms"]) // {
2017-04-25 02:45:00 +01:00
inherit ruby;
inherit (attrs.source) type;
source = removeAttrs attrs.source ["type"];
2017-04-25 02:45:00 +01:00
gemName = name;
2019-08-13 22:52:01 +01:00
gemPath = map (gemName: gems.${gemName}) (attrs.dependencies or []);
2017-04-25 02:45:00 +01:00
});
}