misc. cleanup

This commit is contained in:
Charles Strahan 2014-10-28 01:22:17 +00:00
parent 1eb31c0838
commit 857f017a0d
6 changed files with 67 additions and 62 deletions

View File

@ -1,45 +0,0 @@
{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. Optionally, the `ruby_version`
# key can be set to a string. A gem definition looks like this:
#
# rack-test = {
# name = "rack-test-0.6.2";
# src = {
# type = "url";
# url = "https://rubygems.org/downloads/rack-test-0.6.2.gem";
# sha256 = "01mk715ab5qnqf6va8k3hjsvsmplrfqpz6g58qw4m3l8mim0p4ky";
# };
# dependencies = [ "rack" ];
# };
loadRubyEnv = path: config:
let
expr = import path;
gemset = lib.mapAttrs (name: attrs:
attrs // {
src = (builtins.getAttr attrs.src.type sourceInstantiators) attrs.src;
dontBuild = !(attrs.src.type == "git");
}
) expr.gemset;
ruby = config.ruby;
rubyLibs = rubyLibsWith ruby;
gems = rubyLibs.importGems gemset (config.gemOverrides or (gemset: {}));
in {
inherit ruby gems; # TODO: Set ruby using expr.rubyVersion if not given.
gemPath = map (drv: "${drv}") (
builtins.filter (value: lib.isDerivation value) (lib.attrValues gems)
);
};
}

View File

@ -21,21 +21,20 @@
, which, postgresql, v8_3_16_14, clang }: , which, postgresql, v8_3_16_14, clang }:
let let
id = x: x; const = x: y: x;
v8 = v8_3_16_14; v8 = v8_3_16_14;
gems = lib.mapAttrs (name: config: gems = lib.mapAttrs (name: attrs:
if (lib.isDerivation config) then config if (lib.isDerivation attrs) then attrs
else (instantiate name config) else (instantiate name attrs)
) gemset; ) gemset;
instantiate = (name: attrs: instantiate = (name: attrs:
let let
# Turn dependency strings into actual derivations.
gemPath = map (name: gems."${name}") (attrs.dependencies or []); gemPath = map (name: gems."${name}") (attrs.dependencies or []);
fixedAttrs = (fixes."${name}" or id) attrs; fixedAttrs = attrs // (fixes."${name}" or const {}) attrs;
in in
buildRubyGem (fixedAttrs // { inherit gemPath; }) buildRubyGem (fixedAttrs // { name = "${name}-${attrs.version}"; inherit gemPath; })
); );
fixes = { fixes = {

View File

@ -1,13 +1,12 @@
{ ruby, fetchurl, rake, rubygemsFun, makeWrapper, lib, git }: { ruby, fetchurl, rake, rubygemsFun, makeWrapper, lib, git }:
{ name { name
, namePrefix ? "ruby${ruby.majorVersion}" + "-" , namePrefix ? "${ruby.name}" + "-"
, buildInputs ? [] , buildInputs ? []
, doCheck ? false # TODO: fix this , doCheck ? false # TODO: fix this
, dontBuild ? true , dontBuild ? true
, meta ? {} , meta ? {}
, gemPath ? [] , gemPath ? []
, testTask ? "test"
, ...} @ attrs: , ...} @ attrs:
let let
@ -60,7 +59,10 @@ in ruby.stdenv.mkDerivation (attrs // {
gemspec=`find . -name '*.gemspec'` gemspec=`find . -name '*.gemspec'`
output=`gem build $gemspec` output=`gem build $gemspec`
gempkg=`echo $output|grep -oP 'File: \K(.*)'`
gem build $gemspec | tee .output
gempkg=`cat .output | grep -oP 'File: \K(.*)'`
rm .output
echo "Gem package built: $gempkg" echo "Gem package built: $gempkg"
@ -103,7 +105,7 @@ in ruby.stdenv.mkDerivation (attrs // {
mkdir -p $out/nix-support mkdir -p $out/nix-support
cat > $out/nix-support/setup-hook <<EOF cat > $out/nix-support/setup-hook <<EOF
if [[ "$GEM_PATH" != *$out* ]]; then if [[ "\$GEM_PATH" != *$out* ]]; then
addToSearchPath GEM_PATH $out/${ruby.gemPath} addToSearchPath GEM_PATH $out/${ruby.gemPath}
fi fi
EOF EOF

View File

@ -45,12 +45,12 @@ in
# buildInputs = [ postgresql ]; # buildInputs = [ postgresql ];
# }); # });
# }); # });
importGems = file: args: importGems = file: gemOverrides:
let let
# 1. Load set of gem names and versions from a bundix-created expression. # 1. Load set of gem names and versions from a bundix-created expression.
gemset = if (builtins.isAttrs file) then file else (callPackage file { }); gemset = if (builtins.isAttrs file) then file else (callPackage file { });
# 2. Allow gems to be overriden by providing a derivation yourself. # 2. Allow gems to be overriden by providing a derivation yourself.
config = gemset // (args gemset); config = gemset // (gemOverrides gemset);
# 3. # 3.
gems = fixGems config; gems = fixGems config;
in gems; in gems;

View File

@ -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;
};
}

View File

@ -4045,13 +4045,11 @@ let
ruby_2_0 = ruby_2_0_0; ruby_2_0 = ruby_2_0_0;
ruby_2_1 = ruby_2_1_3; ruby_2_1 = ruby_2_1_3;
rubyLibsWith = ruby: callPackage ../development/interpreters/ruby/gems.nix { rubyLibsWith = ruby: callPackage ../development/interpreters/ruby/import-gems.nix {
inherit ruby; inherit ruby;
}; };
loadRubyEnv = (callPackage ../development/interpreters/ruby/bundix.nix { loadRubyEnv = (callPackage ../development/interpreters/ruby/load-ruby-env.nix { }).loadRubyEnv;
inherit rubyLibsWith;
}).loadRubyEnv;
rubyLibs_1_8_7 = rubyLibsWith ruby_1_8_7; rubyLibs_1_8_7 = rubyLibsWith ruby_1_8_7;
rubyLibs_1_9_3 = rubyLibsWith ruby_1_9_3; rubyLibs_1_9_3 = rubyLibsWith ruby_1_9_3;