about summary refs log tree commit diff
path: root/pkgs/development/interpreters/ruby/load-ruby-env.nix
diff options
context:
space:
mode:
authorCharles Strahan <charles.c.strahan@gmail.com>2014-10-28 01:22:17 +0000
committerCharles Strahan <charles.c.strahan@gmail.com>2014-10-28 01:22:17 +0000
commit857f017a0d28a48fce37d8a71a3633b9f48e0950 (patch)
tree5ff21c181ad9b1b53cba5d9f6647bc60d34e3bc1 /pkgs/development/interpreters/ruby/load-ruby-env.nix
parent1eb31c08388ae5197a172c4c45480d217dc48f3b (diff)
downloadnixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar.gz
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar.bz2
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar.lz
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar.xz
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.tar.zst
nixlib-857f017a0d28a48fce37d8a71a3633b9f48e0950.zip
misc. cleanup
Diffstat (limited to 'pkgs/development/interpreters/ruby/load-ruby-env.nix')
-rw-r--r--pkgs/development/interpreters/ruby/load-ruby-env.nix51
1 files changed, 51 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/ruby/load-ruby-env.nix b/pkgs/development/interpreters/ruby/load-ruby-env.nix
new file mode 100644
index 000000000000..e2f61d82d8bf
--- /dev/null
+++ b/pkgs/development/interpreters/ruby/load-ruby-env.nix
@@ -0,0 +1,51 @@
+{rubyLibsWith, callPackage, lib, fetchurl, fetchgit}:
+
+let
+
+  sourceInstantiators = {
+    # Many ruby people use `git ls-files` to compose their gemspecs.
+    git = (attrs: fetchgit { inherit (attrs) url rev sha256 leaveDotGit; });
+    url = (attrs: fetchurl { inherit (attrs) url sha256; });
+  };
+
+in
+
+{
+  # Loads a set containing a ruby environment definition. The set's `gemset`
+  # key is expected to contain a set of gems. A gemset definition looks like this:
+  #
+  #  {
+  #    gemset = {
+  #      rack-test = {
+  #        version = "0.6.2";
+  #        src = {
+  #          type = "url";
+  #          url = "https://rubygems.org/downloads/rack-test-0.6.2.gem";
+  #          sha256 = "01mk715ab5qnqf6va8k3hjsvsmplrfqpz6g58qw4m3l8mim0p4ky";
+  #        };
+  #        dependencies = [ "rack" ];
+  #      };
+  #    };
+  #  }
+  loadRubyEnv = expr: config:
+    let
+      expr' =
+        if builtins.isAttrs expr
+        then expr
+        else import expr;
+      gemset = lib.mapAttrs (name: attrs:
+        attrs // {
+          src = (sourceInstantiators."${attrs.src.type}") attrs.src;
+          dontBuild = !(attrs.src.type == "git");
+        }
+      ) expr'.gemset;
+      ruby = config.ruby;
+      rubyLibs = rubyLibsWith ruby;
+      gems = rubyLibs.importGems gemset (config.gemOverrides or (gemset: {}));
+      gemPath = map (drv: "${drv}") (
+        builtins.filter lib.isDerivation (lib.attrValues gems)
+      );
+    in {
+      inherit ruby gems gemPath;
+    };
+}