mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 23:43:30 +00:00
106d0920d9
Setting a Bundler version with GEM_PATH doesn't seem to work in Ruby 2.7, so we need to use the LOAD_PATH instead. Without this, bundlerEnv environments will always use the version of Bundler that comes with Ruby, which won't necessarily work because it isn't the version that was used to generate the bundle. For example, building ronn with Ruby 2.7 without this change results in a broken executable, but it works (when built with all packaged Ruby versions) after this change.
94 lines
2.6 KiB
Nix
94 lines
2.6 KiB
Nix
{ lib, gemConfig, ... }:
|
|
|
|
let
|
|
inherit (lib) attrValues concatMap converge filterAttrs getAttrs
|
|
intersectLists;
|
|
|
|
in rec {
|
|
bundlerFiles = {
|
|
gemfile ? null
|
|
, lockfile ? null
|
|
, gemset ? null
|
|
, gemdir ? null
|
|
, ...
|
|
}: {
|
|
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;
|
|
|
|
platformMatches = {rubyEngine, version, ...}: attrs: (
|
|
!(attrs ? platforms) ||
|
|
builtins.length attrs.platforms == 0 ||
|
|
builtins.any (platform:
|
|
platform.engine == rubyEngine &&
|
|
(!(platform ? version) || platform.version == version.majMin)
|
|
) attrs.platforms
|
|
);
|
|
|
|
groupMatches = groups: attrs:
|
|
groups == null || !(attrs ? groups) ||
|
|
(intersectLists (groups ++ [ "default" ]) attrs.groups) != [];
|
|
|
|
applyGemConfigs = attrs:
|
|
(if gemConfig ? ${attrs.gemName}
|
|
then attrs // gemConfig.${attrs.gemName} attrs
|
|
else attrs);
|
|
|
|
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
|
|
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
|
|
"${ruby}/bin/ruby" \
|
|
"${confFiles}/Gemfile" \
|
|
"$out/${ruby.gemPath}" \
|
|
"${bundler}/${ruby.gemPath}/gems/bundler-${bundler.version}" \
|
|
${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"]) // {
|
|
inherit ruby;
|
|
inherit (attrs.source) type;
|
|
source = removeAttrs attrs.source ["type"];
|
|
gemName = name;
|
|
gemPath = map (gemName: gems.${gemName}) (attrs.dependencies or []);
|
|
});
|
|
}
|