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

70 lines
1.9 KiB
Nix
Raw Normal View History

2014-12-29 05:48:01 +00:00
{ ruby, lib, callPackage, gemFixes, fetchurl, fetchgit, buildRubyGem }@defs:
2014-10-28 01:22:17 +00:00
2014-10-31 02:03:37 +00:00
# This function builds a set of gems. You first convert your Gemfile to an attrset
# called a "gemset", and then use this function to build the gemset.
#
# A gemset looks like the following:
#
# {
# libv8 = {
# version = "3.16.14.7";
# src = {
# type = "gem";
# sha256 = "...";
# };
# };
# therubyracer = {
# version = "0.12.1";
# dependencies = [ "libv8" ];
# src = {
# type = "gem";
# sha256 = "...";
# };
# };
# }
#
# If you use these gems as build inputs, the GEM_PATH will be updated
# appropriately, and command like `bundle exec` should work out of the box.
2014-10-31 01:44:57 +00:00
{ gemset, ruby ? defs.ruby, fixes ? gemFixes }@args:
2014-10-28 01:22:17 +00:00
2014-10-28 04:16:14 +00:00
let
const = x: y: x;
2014-10-28 01:22:17 +00:00
2014-11-08 23:46:34 +00:00
fetchers.path = attrs: attrs.src.path;
2014-10-29 23:14:19 +00:00
fetchers.gem = attrs: fetchurl {
url = "${attrs.src.source or "https://rubygems.org"}/downloads/${attrs.name}-${attrs.version}.gem";
inherit (attrs.src) sha256;
};
2014-12-29 05:48:01 +00:00
fetchers.git = attrs: fetchgit {
2015-01-15 02:19:53 +00:00
inherit (attrs.src) url rev sha256 fetchSubmodules;
2014-12-29 05:48:01 +00:00
leaveDotGit = true;
};
2014-10-29 23:14:19 +00:00
instantiate = (attrs:
2014-10-28 01:22:17 +00:00
let
2015-01-16 01:58:05 +00:00
defaultAttrs = {
name = "${attrs.name}-${attrs.version}";
inherit ruby gemPath;
};
2014-10-28 04:16:14 +00:00
gemPath = map (name: gemset''."${name}") (attrs.dependencies or []);
2014-10-29 23:14:19 +00:00
fixedAttrs = attrs // (fixes."${attrs.name}" or (const {})) attrs;
2015-01-16 01:58:05 +00:00
withSource = fixedAttrs //
(if (lib.isDerivation fixedAttrs.src || builtins.isString fixedAttrs.src)
then {}
else { src = (fetchers."${fixedAttrs.src.type}" fixedAttrs); });
2014-10-28 04:16:14 +00:00
in
2015-01-16 01:58:05 +00:00
buildRubyGem (withSource // defaultAttrs)
2014-10-28 04:16:14 +00:00
);
2014-10-31 01:44:57 +00:00
gemset' = if builtins.isAttrs gemset then gemset else import gemset;
2014-10-28 04:16:14 +00:00
gemset'' = lib.flip lib.mapAttrs gemset' (name: attrs:
2014-10-29 23:14:19 +00:00
if (lib.isDerivation attrs)
then attrs
else instantiate (attrs // { inherit name; })
2014-10-28 04:16:14 +00:00
);
in gemset''