1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-25 07:00:43 +00:00

simplification / refactoring

This commit is contained in:
Charles Strahan 2014-10-28 04:16:14 +00:00
parent 857f017a0d
commit e4a2a7e73e
6 changed files with 67 additions and 178 deletions

View file

@ -17,27 +17,15 @@
# This seperates "what to build" (the exact gem versions) from "how to build"
# (to make gems behave if necessary).
{ lib, gemset, buildRubyGem, writeScript, ruby, libxml2, libxslt, python, stdenv
, which, postgresql, v8_3_16_14, clang }:
{ lib, fetchurl, writeScript, ruby, libxml2, libxslt, python, stdenv, which
, postgresql, v8_3_16_14, clang }:
let
const = x: y: x;
v8 = v8_3_16_14;
gems = lib.mapAttrs (name: attrs:
if (lib.isDerivation attrs) then attrs
else (instantiate name attrs)
) gemset;
instantiate = (name: attrs:
let
gemPath = map (name: gems."${name}") (attrs.dependencies or []);
fixedAttrs = attrs // (fixes."${name}" or const {}) attrs;
in
buildRubyGem (fixedAttrs // { name = "${name}-${attrs.version}"; inherit gemPath; })
);
fixes = {
{
bundler = attrs: {
dontPatchShebangs = 1;
};
@ -60,8 +48,6 @@ let
dontBuild = false;
preInstall = ''
addToSearchPath RUBYLIB "${gems.libv8}/gems/libv8-3.16.14.3/lib"
addToSearchPath RUBYLIB "${gems.libv8}/gems/libv8-3.16.14.3/ext"
ln -s ${clang}/bin/clang $TMPDIR/gcc
ln -s ${clang}/bin/clang++ $TMPDIR/g++
export PATH=$TMPDIR:$PATH
@ -78,6 +64,4 @@ let
"--with-v8-lib=${v8}/lib"
];
};
};
in gems
}

View file

@ -3,7 +3,7 @@
{ name
, namePrefix ? "${ruby.name}" + "-"
, buildInputs ? []
, doCheck ? false # TODO: fix this
, doCheck ? false
, dontBuild ? true
, meta ? {}
, gemPath ? []

View file

@ -1,57 +0,0 @@
# is a pretty good interface for calling rubygems
#
# since there are so many rubygems, and we don't want to manage them all,
# proposed design pattern is keep your gem dependencies in a local file
# (hopefully managed with nix-bundle)
#
# use rubyLibs.importGems to call the local file, which has access to all
# the stuff in here
{ ruby, callPackage, pkgs }:
let
buildRubyGem = callPackage ./gem.nix { inherit ruby; };
lib = ruby.stdenv.lib;
# A set of gems that everyone needs.
common = {
bundler = {
name = "bundler-1.6.5";
sha256 = "1s4x0f5by9xs2y24jk6krq5ky7ffkzmxgr4z1nhdykdmpsi2zd0l";
};
rake = {
name = "rake-10.3.2";
sha256 = "0nvpkjrpsk8xxnij2wd1cdn6arja9q11sxx4aq4fz18bc6fss15m";
dependencies = [ "bundler" ];
};
};
fixGems = gemset: callPackage ./fixes.nix { inherit buildRubyGem gemset ruby; };
in
(fixGems common) // {
inherit buildRubyGem;
# Import an attribute set of gems and apply a set of overrides. Nixpkgs fixes
# popular gems that don't behave. If you specify your own override for a gem,
# the one distributed with nixpgks will not be applied.
#
# Example:
#
# importGems ./gems.nix (gemset: {
# pg = buildRubyGem (gemset.pg // {
# buildInputs = [ postgresql ];
# });
# });
importGems = file: gemOverrides:
let
# 1. Load set of gem names and versions from a bundix-created expression.
gemset = if (builtins.isAttrs file) then file else (callPackage file { });
# 2. Allow gems to be overriden by providing a derivation yourself.
config = gemset // (gemOverrides gemset);
# 3.
gems = fixGems config;
in gems;
}

View file

@ -1,51 +1,25 @@
{rubyLibsWith, callPackage, lib, fetchurl, fetchgit}:
{ pkgs, lib, callPackage, gemFixes }:
{ gemset, ruby ? pkgs.ruby, fixes ? gemFixes }@args:
let
const = x: y: x;
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; });
};
buildRubyGem = callPackage ./gem.nix { inherit ruby; };
instantiate = (name: attrs:
let
gemPath = map (name: gemset''."${name}") (attrs.dependencies or []);
fixedAttrs = attrs // (fixes."${name}" or (const {})) attrs;
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)
buildRubyGem (fixedAttrs // { name = "${name}-${attrs.version}"; inherit gemPath; })
);
in {
inherit ruby gems gemPath;
};
}
gemset' = if builtins.isAttrs gemset then gemset else callPackage gemset { };
gemset'' = lib.flip lib.mapAttrs gemset' (name: attrs:
if (lib.isDerivation attrs) then attrs
else (instantiate name attrs)
);
in gemset''

View file

@ -1,6 +1,7 @@
args : with args;
rec {
name = "rubygems-" + version;
version = "2.4.1";
src = fetchurl {
url = "http://production.cf.rubygems.org/rubygems/${name}.tgz";
@ -23,7 +24,6 @@ rec {
/* doConfigure should be specified separately */
phaseNames = ["doPatch" "doInstall"];
name = "rubygems-" + version;
meta = {
description = "Ruby gems package collection";
longDescription = ''

View file

@ -4030,6 +4030,8 @@ let
wrapPython = pythonPackages.wrapPython;
};
gemFixes = callPackage ../development/interpreters/ruby/fixes.nix { };
ruby_1_8_7 = callPackage ../development/interpreters/ruby/ruby-1.8.7.nix { };
ruby_1_9_3 = callPackage ../development/interpreters/ruby/ruby-1.9.3.nix { };
ruby_2_0_0 = lowPrio (callPackage ../development/interpreters/ruby/ruby-2.0.0.nix { });
@ -4045,23 +4047,9 @@ let
ruby_2_0 = ruby_2_0_0;
ruby_2_1 = ruby_2_1_3;
rubyLibsWith = ruby: callPackage ../development/interpreters/ruby/import-gems.nix {
inherit ruby;
};
loadRubyEnv = callPackage ../development/interpreters/ruby/load-ruby-env.nix { };
loadRubyEnv = (callPackage ../development/interpreters/ruby/load-ruby-env.nix { }).loadRubyEnv;
rubyLibs_1_8_7 = rubyLibsWith ruby_1_8_7;
rubyLibs_1_9_3 = rubyLibsWith ruby_1_9_3;
rubyLibs_2_0_0 = rubyLibsWith ruby_2_0_0;
rubyLibs_2_1_0 = rubyLibsWith ruby_2_1_0;
rubyLibs_2_1_1 = rubyLibsWith ruby_2_1_1;
rubyLibs_2_1_2 = rubyLibsWith ruby_2_1_2;
rubyLibs_2_1_3 = rubyLibsWith ruby_2_1_3;
rubyLibs = recurseIntoAttrs rubyLibs_1_9_3;
rake = rubyLibs.rake;
rake = ... # TODO
rubySqlite3 = callPackage ../development/ruby-modules/sqlite3 { };