simplification / refactoring
This commit is contained in:
parent
857f017a0d
commit
e4a2a7e73e
@ -17,67 +17,51 @@
|
|||||||
# This seperates "what to build" (the exact gem versions) from "how to build"
|
# This seperates "what to build" (the exact gem versions) from "how to build"
|
||||||
# (to make gems behave if necessary).
|
# (to make gems behave if necessary).
|
||||||
|
|
||||||
{ lib, gemset, buildRubyGem, writeScript, ruby, libxml2, libxslt, python, stdenv
|
{ lib, fetchurl, writeScript, ruby, libxml2, libxslt, python, stdenv, which
|
||||||
, which, postgresql, v8_3_16_14, clang }:
|
, postgresql, v8_3_16_14, clang }:
|
||||||
|
|
||||||
let
|
let
|
||||||
const = x: y: x;
|
|
||||||
v8 = v8_3_16_14;
|
v8 = v8_3_16_14;
|
||||||
|
|
||||||
gems = lib.mapAttrs (name: attrs:
|
in
|
||||||
if (lib.isDerivation attrs) then attrs
|
|
||||||
else (instantiate name attrs)
|
|
||||||
) gemset;
|
|
||||||
|
|
||||||
instantiate = (name: attrs:
|
{
|
||||||
let
|
bundler = attrs: {
|
||||||
gemPath = map (name: gems."${name}") (attrs.dependencies or []);
|
dontPatchShebangs = 1;
|
||||||
fixedAttrs = attrs // (fixes."${name}" or const {}) attrs;
|
|
||||||
in
|
|
||||||
buildRubyGem (fixedAttrs // { name = "${name}-${attrs.version}"; inherit gemPath; })
|
|
||||||
);
|
|
||||||
|
|
||||||
fixes = {
|
|
||||||
bundler = attrs: {
|
|
||||||
dontPatchShebangs = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
libv8 = attrs: {
|
|
||||||
buildFlags = [ "--with-system-v8" ];
|
|
||||||
buildInputs = [ which v8 python ];
|
|
||||||
};
|
|
||||||
|
|
||||||
nokogiri = attrs: {
|
|
||||||
buildFlags = [
|
|
||||||
"--with-xml2-dir=${libxml2}"
|
|
||||||
"--with-xml2-include=${libxml2}/include/libxml2"
|
|
||||||
"--with-xslt-dir=${libxslt}"
|
|
||||||
"--use-system-libraries"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
therubyracer = attrs: {
|
|
||||||
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
|
|
||||||
'';
|
|
||||||
|
|
||||||
postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
|
|
||||||
cat >> $out/nix-support/setup-hook <<EOF
|
|
||||||
export DYLD_INSERT_LIBRARIES="$DYLD_INSERT_LIBRARIES''${!DYLD_INSERT_LIBRARIES:+:}${v8}/lib/libv8.dylib"
|
|
||||||
EOF
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildFlags = [
|
|
||||||
"--with-v8-dir=${v8}" "--with-v8-include=${v8}/include"
|
|
||||||
"--with-v8-lib=${v8}/lib"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
in gems
|
libv8 = attrs: {
|
||||||
|
buildFlags = [ "--with-system-v8" ];
|
||||||
|
buildInputs = [ which v8 python ];
|
||||||
|
};
|
||||||
|
|
||||||
|
nokogiri = attrs: {
|
||||||
|
buildFlags = [
|
||||||
|
"--with-xml2-dir=${libxml2}"
|
||||||
|
"--with-xml2-include=${libxml2}/include/libxml2"
|
||||||
|
"--with-xslt-dir=${libxslt}"
|
||||||
|
"--use-system-libraries"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
therubyracer = attrs: {
|
||||||
|
dontBuild = false;
|
||||||
|
|
||||||
|
preInstall = ''
|
||||||
|
ln -s ${clang}/bin/clang $TMPDIR/gcc
|
||||||
|
ln -s ${clang}/bin/clang++ $TMPDIR/g++
|
||||||
|
export PATH=$TMPDIR:$PATH
|
||||||
|
'';
|
||||||
|
|
||||||
|
postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
|
||||||
|
cat >> $out/nix-support/setup-hook <<EOF
|
||||||
|
export DYLD_INSERT_LIBRARIES="$DYLD_INSERT_LIBRARIES''${!DYLD_INSERT_LIBRARIES:+:}${v8}/lib/libv8.dylib"
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildFlags = [
|
||||||
|
"--with-v8-dir=${v8}" "--with-v8-include=${v8}/include"
|
||||||
|
"--with-v8-lib=${v8}/lib"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{ name
|
{ name
|
||||||
, namePrefix ? "${ruby.name}" + "-"
|
, namePrefix ? "${ruby.name}" + "-"
|
||||||
, buildInputs ? []
|
, buildInputs ? []
|
||||||
, doCheck ? false # TODO: fix this
|
, doCheck ? false
|
||||||
, dontBuild ? true
|
, dontBuild ? true
|
||||||
, meta ? {}
|
, meta ? {}
|
||||||
, gemPath ? []
|
, gemPath ? []
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -1,51 +1,25 @@
|
|||||||
{rubyLibsWith, callPackage, lib, fetchurl, fetchgit}:
|
{ pkgs, lib, callPackage, gemFixes }:
|
||||||
|
|
||||||
|
{ gemset, ruby ? pkgs.ruby, fixes ? gemFixes }@args:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
const = x: y: x;
|
||||||
|
|
||||||
sourceInstantiators = {
|
buildRubyGem = callPackage ./gem.nix { inherit ruby; };
|
||||||
# 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
|
instantiate = (name: attrs:
|
||||||
|
|
||||||
{
|
|
||||||
# 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
|
let
|
||||||
expr' =
|
gemPath = map (name: gemset''."${name}") (attrs.dependencies or []);
|
||||||
if builtins.isAttrs expr
|
fixedAttrs = attrs // (fixes."${name}" or (const {})) attrs;
|
||||||
then expr
|
in
|
||||||
else import expr;
|
buildRubyGem (fixedAttrs // { name = "${name}-${attrs.version}"; inherit gemPath; })
|
||||||
gemset = lib.mapAttrs (name: attrs:
|
);
|
||||||
attrs // {
|
|
||||||
src = (sourceInstantiators."${attrs.src.type}") attrs.src;
|
gemset' = if builtins.isAttrs gemset then gemset else callPackage gemset { };
|
||||||
dontBuild = !(attrs.src.type == "git");
|
|
||||||
}
|
gemset'' = lib.flip lib.mapAttrs gemset' (name: attrs:
|
||||||
) expr'.gemset;
|
if (lib.isDerivation attrs) then attrs
|
||||||
ruby = config.ruby;
|
else (instantiate name attrs)
|
||||||
rubyLibs = rubyLibsWith ruby;
|
);
|
||||||
gems = rubyLibs.importGems gemset (config.gemOverrides or (gemset: {}));
|
|
||||||
gemPath = map (drv: "${drv}") (
|
in gemset''
|
||||||
builtins.filter lib.isDerivation (lib.attrValues gems)
|
|
||||||
);
|
|
||||||
in {
|
|
||||||
inherit ruby gems gemPath;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
args : with args;
|
args : with args;
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
|
name = "rubygems-" + version;
|
||||||
version = "2.4.1";
|
version = "2.4.1";
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = "http://production.cf.rubygems.org/rubygems/${name}.tgz";
|
url = "http://production.cf.rubygems.org/rubygems/${name}.tgz";
|
||||||
@ -23,7 +24,6 @@ rec {
|
|||||||
/* doConfigure should be specified separately */
|
/* doConfigure should be specified separately */
|
||||||
phaseNames = ["doPatch" "doInstall"];
|
phaseNames = ["doPatch" "doInstall"];
|
||||||
|
|
||||||
name = "rubygems-" + version;
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Ruby gems package collection";
|
description = "Ruby gems package collection";
|
||||||
longDescription = ''
|
longDescription = ''
|
||||||
|
@ -4030,6 +4030,8 @@ let
|
|||||||
wrapPython = pythonPackages.wrapPython;
|
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_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_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 { });
|
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_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/import-gems.nix {
|
loadRubyEnv = callPackage ../development/interpreters/ruby/load-ruby-env.nix { };
|
||||||
inherit ruby;
|
|
||||||
};
|
|
||||||
|
|
||||||
loadRubyEnv = (callPackage ../development/interpreters/ruby/load-ruby-env.nix { }).loadRubyEnv;
|
rake = ... # TODO
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
rubySqlite3 = callPackage ../development/ruby-modules/sqlite3 { };
|
rubySqlite3 = callPackage ../development/ruby-modules/sqlite3 { };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user