nixpkgs/pkgs/development/interpreters/ruby/load-ruby-env.nix

38 lines
1,006 B
Nix
Raw Normal View History

2014-10-30 00:14:19 +01:00
{ pkgs, lib, callPackage, gemFixes, fetchurl }:
2014-10-28 02:22:17 +01:00
2014-10-28 05:16:14 +01:00
{ gemset, ruby ? pkgs.ruby, fixes ? gemFixes }@args:
2014-10-28 02:22:17 +01:00
2014-10-28 05:16:14 +01:00
let
const = x: y: x;
2014-10-28 02:22:17 +01:00
2014-10-28 05:16:14 +01:00
buildRubyGem = callPackage ./gem.nix { inherit ruby; };
2014-10-28 02:22:17 +01:00
2014-10-30 00:14:19 +01:00
fetchers.gem = attrs: fetchurl {
url = "${attrs.src.source or "https://rubygems.org"}/downloads/${attrs.name}-${attrs.version}.gem";
inherit (attrs.src) sha256;
};
instantiate = (attrs:
2014-10-28 02:22:17 +01:00
let
2014-10-28 05:16:14 +01:00
gemPath = map (name: gemset''."${name}") (attrs.dependencies or []);
2014-10-30 00:14:19 +01:00
fixedAttrs = attrs // (fixes."${attrs.name}" or (const {})) attrs;
2014-10-28 05:16:14 +01:00
in
2014-10-30 00:14:19 +01:00
buildRubyGem (
fixedAttrs // {
name = "${attrs.name}-${attrs.version}";
src = fetchers."${attrs.src.type}" attrs;
inherit gemPath;
}
)
2014-10-28 05:16:14 +01:00
);
gemset' = if builtins.isAttrs gemset then gemset else callPackage gemset { };
gemset'' = lib.flip lib.mapAttrs gemset' (name: attrs:
2014-10-30 00:14:19 +01:00
if (lib.isDerivation attrs)
then attrs
else instantiate (attrs // { inherit name; })
2014-10-28 05:16:14 +01:00
);
in gemset''