ruby: rewrite sup package

This commit is contained in:
Charles Strahan
2015-01-21 15:20:42 -05:00
parent 5f1622e95f
commit f52c32fcfc
10 changed files with 248 additions and 132 deletions

View File

@@ -1,6 +1,5 @@
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
, callPackage , gemFixes, fetchurl, fetchgit, buildRubyGem
#, bundler_PATCHED
, bundler_HEAD
, git
}@defs:
@@ -10,7 +9,9 @@
{ name, gemset, gemfile, lockfile, ruby ? defs.ruby, fixes ? gemFixes
, enableParallelBuilding ? false # TODO: this might not work, given the env-var shinanigans.
, documentation ? false}@args:
, documentation ? false
, meta ? {}
}@args:
let
@@ -127,22 +128,26 @@ let
needsPreInstall = attrs:
(attrs ? preInstall) || (attrs ? buildInputs) || (attrs ? nativeBuildInputs);
createPreInstallers = lib.fold (next: acc:
# TODO: support cross compilation? look at stdenv/generic/default.nix.
runPreInstallers = lib.fold (next: acc:
if !needsPreInstall next
then acc
else acc + ''
cp ${writeScript "${next.name}-pre-install" ''
${writeScript "${next.name}-pre-install" ''
#!${stdenv.shell}
buildInputs="${toString (next.buildInputs or [])}"
nativeBuildInputs="${toString (next.nativeBuildInputs or [])}"
export nativeBuildInputs="${toString ((next.nativeBuildInputs or []) ++ (next.buildInputs or []))}"
source ${stdenv}/setup
header "running pre-install script for ${next.name}"
${next.preInstall or ""}
${ruby}/bin/ruby -e 'print ENV.inspect' > env/${next.name}
''} pre-installers/${next.name}
stopNest
''}
''
) "" (attrValues instantiated);
@@ -245,18 +250,23 @@ in
stdenv.mkDerivation {
inherit name;
buildInputs = [
ruby
bundler
git
];
phases = [ "installPhase" "fixupPhase" ];
outputs = [
"out" # the installed libs/bins
"bundle" # supporting files for bundler
];
installPhase = ''
# Copy the Gemfile and Gemfile.lock
mkdir -p $bundle
export BUNDLE_GEMFILE=$bundle/Gemfile
cp ${gemfile} $BUNDLE_GEMFILE
@@ -273,8 +283,7 @@ stdenv.mkDerivation {
${copyGems}
mkdir env
mkdir pre-installers
${createPreInstallers}
${runPreInstallers}
${allBuildArgs}
@@ -289,8 +298,11 @@ stdenv.mkDerivation {
export RUBYOPT="-rmonkey_patches.rb -I $(pwd -P)"
bundler install --frozen --binstubs ${lib.optionalString enableParallelBuilding "--jobs $NIX_BUILD_CORES"}
'';
passthru = {
inherit ruby;
inherit bundler;
};
inherit meta;
}

View File

@@ -133,14 +133,9 @@ Bundler::Installer.class_eval do
# and then set it back to what it was originally.
alias original_install_gem_from_spec install_gem_from_spec
def install_gem_from_spec(spec, standalone = false, worker = 0)
pre_installer = "pre-installers/#{spec.name}"
if File.exist?(pre_installer)
system(pre_installer)
unless $?.success?
Bundler.ui.error "The pre-installer script for #{spec.name} failed!"
exit 1
end
env = eval(Bundler.read_file("env/#{spec.name}"))
env_dump = "env/#{spec.name}"
if File.exist?(env_dump)
env = eval(Bundler.read_file(env_dump))
unless env
Bundler.ui.error "The environment variables for #{spec.name} could not be loaded!"
exit 1