Merge pull request #19180 from zimbatm/bundler-env-bins

Bundler env bins
This commit is contained in:
zimbatm 2016-10-14 11:51:23 +01:00 committed by GitHub
commit 6351c4d24b
9 changed files with 89 additions and 116 deletions

View File

@ -6,7 +6,14 @@
, tree
}@defs:
{ name, gemset, gemfile, lockfile, ruby ? defs.ruby, gemConfig ? defaultGemConfig
{ name ? null
, pname ? null
, gemdir ? null
, gemfile ? null
, lockfile ? null
, gemset ? null
, ruby ? defs.ruby
, gemConfig ? defaultGemConfig
, postBuild ? null
, document ? []
, meta ? {}
@ -16,54 +23,95 @@
}@args:
let
importedGemset = import gemset;
drvName =
if name != null then name
else if pname != null then "${toString pname}-${mainGem.version}"
else throw "bundlerEnv: either pname or name must be set";
mainGem =
if pname == null then null
else gems."${pname}" or (throw "bundlerEnv: gem ${pname} not found");
gemfile' =
if gemfile == null then gemdir + "/Gemfile"
else gemfile;
lockfile' =
if lockfile == null then gemdir + "/Gemfile.lock"
else lockfile;
gemset' =
if gemset == null then gemdir + "/gemset.nix"
else gemset;
importedGemset = import gemset';
filteredGemset = (lib.filterAttrs (name: attrs:
if (builtins.hasAttr "groups" attrs)
then (builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups)
else true
) importedGemset);
applyGemConfigs = attrs:
(if gemConfig ? "${attrs.gemName}"
then attrs // gemConfig."${attrs.gemName}" attrs
else attrs);
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
applyGemConfigs (attrs // { inherit ruby; gemName = name; })
);
hasBundler = builtins.hasAttr "bundler" filteredGemset;
bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; });
bundler =
if hasBundler then gems.bundler
else defs.bundler.override (attrs: { inherit ruby; });
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs:
buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // {
inherit ruby;
gemName = name;
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
}));
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
# helpful by doing so at run time, causing executables to immediately bail
# out. Yes, I'm serious.
confFiles = runCommand "gemfile-and-lockfile" {} ''
mkdir -p $out
cp ${gemfile} $out/Gemfile
cp ${lockfile} $out/Gemfile.lock
cp ${gemfile'} $out/Gemfile
cp ${lockfile'} $out/Gemfile.lock
'';
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
binPaths = if mainGem != null then [ mainGem ] else envPaths;
bundlerEnv = buildEnv {
inherit name ignoreCollisions;
inherit ignoreCollisions;
name = drvName;
paths = envPaths;
pathsToLink = [ "/lib" ];
postBuild = ''
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
"${ruby}/bin/ruby" \
"${confFiles}/Gemfile" \
"$out/${ruby.gemPath}" \
"${bundler}/${ruby.gemPath}" \
${lib.escapeShellArg envPaths} \
${lib.escapeShellArg binPaths} \
${lib.escapeShellArg groups}
'' + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta;
passthru = rec {
inherit ruby bundler meta gems;
inherit ruby bundler gems;
wrappedRuby = stdenv.mkDerivation {
name = "wrapped-ruby-${name}";
name = "wrapped-ruby-${drvName}";
nativeBuildInputs = [ makeWrapper ];
buildCommand = ''
mkdir -p $out/bin
@ -87,7 +135,7 @@ let
require 'bundler/setup'
'';
in stdenv.mkDerivation {
name = "interactive-${name}-environment";
name = "interactive-${drvName}-environment";
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
shellHook = ''
export OLD_IRBRC="$IRBRC"
@ -102,7 +150,5 @@ let
};
};
};
in
bundlerEnv
bundlerEnv

View File

@ -1,29 +1,14 @@
{ stdenv, lib, bundlerEnv, ruby }:
{ lib, bundlerEnv, ruby }:
stdenv.mkDerivation rec {
name = "travis-${version}";
version = env.gems.travis.version;
env = bundlerEnv {
inherit ruby;
name = "${name}-gems";
gemset = ./gemset.nix;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
};
phases = ["installPhase"];
installPhase = ''
mkdir -p $out/bin
ln -s ${env}/bin/travis $out/bin/travis
'';
bundlerEnv {
inherit ruby;
pName = "travis";
gemdir = ./.;
meta = with lib; {
description = "CLI and Ruby client library for Travis CI";
homepage = https://github.com/travis-ci/travis.rb;
license = licenses.mit;
maintainers = with maintainers; [ zimbatm ];
platforms = ruby.meta.platforms;
};
}

View File

@ -1,21 +1,9 @@
{ bundlerEnv, lib, stdenv }:
{ bundlerEnv, lib, ruby }:
let
name = "riemann-dash-${env.gems.riemann-dash.version}";
env = bundlerEnv {
inherit name;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
in stdenv.mkDerivation {
inherit name;
buildCommand = ''
mkdir -p $out/bin
ln -s ${env}/bin/riemann-dash $out/bin/riemann-dash
'';
bundlerEnv {
inherit ruby;
pName = "riemann-dash";
gemdir = ./.;
meta = with lib; {
description = "A javascript, websockets-powered dashboard for Riemann";

View File

@ -1,12 +1,10 @@
{ stdenv, lib, bundlerEnv, ruby, curl }:
bundlerEnv {
name = "fluentd-0.14.0";
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
pname = "fluentd";
gemdir = ./.;
meta = with lib; {
description = "A data collector";

View File

@ -2,12 +2,10 @@
, pkgconfig, which }:
bundlerEnv {
name = "lolcat-42.1.0";
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
pname = "lolcat";
gemdir = ./.;
meta = with lib; {
description = "A rainbow version of cat";

View File

@ -1,13 +1,9 @@
{ lib, bundlerEnv, ruby }:
bundlerEnv rec {
name = "fpm-${version}";
version = (import gemset).fpm.version;
inherit ruby;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
pname = "fpm";
gemdir = ./.;
meta = with lib; {
description = "Tool to build packages for multiple platforms with ease";

View File

@ -1,24 +1,9 @@
{ stdenv, lib, ruby, bundlerEnv, makeWrapper }:
{ bundlerEnv, lib, ruby }:
stdenv.mkDerivation rec {
name = "foreman-${env.gems.foreman.version}";
env = bundlerEnv {
inherit ruby;
name = "${name}-gems";
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
phases = ["installPhase"];
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
makeWrapper ${env}/bin/foreman $out/bin/foreman
'';
bundlerEnv {
inherit ruby;
pName = "foreman";
gemdir = ./.;
meta = with lib; {
description = "Process manager for applications with multiple components";

View File

@ -1,22 +1,9 @@
{ lib, bundlerEnv, stdenv }:
{ lib, bundlerEnv, ruby }:
let
name = "hiera-eyaml-${env.gems.hiera-eyaml.version}";
env = bundlerEnv {
inherit name;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
};
in stdenv.mkDerivation {
inherit name;
buildCommand = ''
mkdir -p $out/bin
ln -s ${env}/bin/eyaml $out/bin/eyaml
'';
bundlerEnv {
inherit ruby;
pName = "hiera-eyaml";
gemdir = ./.;
meta = with lib; {
description = "Per-value asymmetric encryption of sensitive data for Hiera";

View File

@ -1,19 +1,9 @@
{ stdenv, lib, bundlerEnv, ruby_2_2, curl }:
bundlerEnv rec {
name = "asciidoctor-${version}";
version = "1.5.4";
pname = "asciidoctor";
ruby = ruby_2_2;
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
# Delete dependencies' executables
postBuild = ''
find $out/bin -type f -not -wholename '*bin/asciidoctor*' -print0 \
| xargs -0 rm
'';
gemdir = ./.;
meta = with lib; {
description = "A faster Asciidoc processor written in Ruby";