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

70 lines
1.9 KiB
Nix
Raw Normal View History

2014-12-29 06:48:01 +01:00
{ ruby, lib, callPackage, gemFixes, fetchurl, fetchgit, buildRubyGem }@defs:
2014-10-28 02:22:17 +01:00
2014-10-31 03:03:37 +01: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 02:44:57 +01:00
{ gemset, ruby ? defs.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-11-09 00:46:34 +01:00
fetchers.path = attrs: attrs.src.path;
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;
};
2014-12-29 06:48:01 +01:00
fetchers.git = attrs: fetchgit {
2015-01-15 03:19:53 +01:00
inherit (attrs.src) url rev sha256 fetchSubmodules;
2014-12-29 06:48:01 +01:00
leaveDotGit = true;
};
2014-10-30 00:14:19 +01:00
instantiate = (attrs:
2014-10-28 02:22:17 +01:00
let
2015-01-16 02:58:05 +01:00
defaultAttrs = {
name = "${attrs.name}-${attrs.version}";
inherit ruby gemPath;
};
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;
2015-01-16 02:58:05 +01:00
withSource = fixedAttrs //
(if (lib.isDerivation fixedAttrs.src || builtins.isString fixedAttrs.src)
then {}
else { src = (fetchers."${fixedAttrs.src.type}" fixedAttrs); });
2014-10-28 05:16:14 +01:00
in
2015-01-16 02:58:05 +01:00
buildRubyGem (withSource // defaultAttrs)
2014-10-28 05:16:14 +01:00
);
2014-10-31 02:44:57 +01:00
gemset' = if builtins.isAttrs gemset then gemset else import gemset;
2014-10-28 05:16:14 +01:00
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''