1 { lib, gemConfig, ... }:
4 inherit (lib) attrValues concatMap converge filterAttrs getAttrs
18 if gemfile == null then assert gemdir != null; gemdir + "/Gemfile"
22 if lockfile == null then assert gemdir != null; gemdir + "/Gemfile.lock"
26 if gemset == null then assert gemdir != null; gemdir + "/gemset.nix"
30 filterGemset = { ruby, groups, ... }: gemset:
32 platformGems = filterAttrs (_: platformMatches ruby) gemset;
33 directlyMatchingGems = filterAttrs (_: groupMatches groups) platformGems;
35 expandDependencies = gems:
37 depNames = concatMap (gem: gem.dependencies or []) (attrValues gems);
38 deps = getAttrs depNames platformGems;
42 converge expandDependencies directlyMatchingGems;
44 platformMatches = {rubyEngine, version, ...}: attrs: (
45 !(attrs ? platforms) ||
46 builtins.length attrs.platforms == 0 ||
47 builtins.any (platform:
48 platform.engine == rubyEngine &&
49 (!(platform ? version) || platform.version == version.majMin)
53 groupMatches = groups: attrs:
54 groups == null || !(attrs ? groups) ||
55 (intersectLists (groups ++ [ "default" ]) attrs.groups) != [];
57 applyGemConfigs = attrs:
58 (if gemConfig ? ${attrs.gemName}
59 then attrs // gemConfig.${attrs.gemName} attrs
62 genStubsScript = { lib, runCommand, ruby, confFiles, bundler, groups, binPaths, ... }:
64 genStubsScript = runCommand "gen-bin-stubs"
67 nativeBuildInputs = [ ruby ];
70 cp ${./gen-bin-stubs.rb} $out
72 patchShebangs --build $out
78 "${confFiles}/Gemfile" \
79 "$out/${ruby.gemPath}" \
80 "${bundler}/${ruby.gemPath}/gems/bundler-${bundler.version}" \
81 ${lib.escapeShellArg binPaths} \
82 ${lib.escapeShellArg groups}
85 pathDerivation = { gemName, version, path, ... }:
101 composeGemAttrs = ruby: gems: name: attrs: ((removeAttrs attrs ["platforms"]) // {
103 inherit (attrs.source) type;
104 source = removeAttrs attrs.source ["type"];
106 gemPath = map (gemName: gems.${gemName}) (attrs.dependencies or []);