2014-10-31 01:44:57 +00:00
|
|
|
{ lib, ruby, rubygemsFun, fetchurl, makeWrapper, git } @ defs:
|
|
|
|
|
|
|
|
lib.makeOverridable (
|
2014-08-07 22:13:56 +00:00
|
|
|
|
|
|
|
{ name
|
2014-10-31 01:44:57 +00:00
|
|
|
, ruby ? defs.ruby
|
|
|
|
, rubygems ? (rubygemsFun ruby)
|
2014-11-09 21:31:48 +00:00
|
|
|
, stdenv ? ruby.stdenv
|
2014-10-28 01:22:17 +00:00
|
|
|
, namePrefix ? "${ruby.name}" + "-"
|
2014-08-07 22:13:56 +00:00
|
|
|
, buildInputs ? []
|
2014-10-28 04:16:14 +00:00
|
|
|
, doCheck ? false
|
2014-08-09 19:55:31 +00:00
|
|
|
, dontBuild ? true
|
2014-08-07 22:13:56 +00:00
|
|
|
, meta ? {}
|
|
|
|
, gemPath ? []
|
|
|
|
, ...} @ attrs:
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2014-11-09 21:31:48 +00:00
|
|
|
stdenv.mkDerivation (attrs // {
|
|
|
|
inherit ruby rubygems;
|
2014-08-07 22:13:56 +00:00
|
|
|
inherit doCheck;
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2014-11-18 03:05:44 +00:00
|
|
|
buildInputs = [ ruby rubygems makeWrapper git ] ++ buildInputs;
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2014-08-07 22:13:56 +00:00
|
|
|
name = namePrefix + name;
|
|
|
|
|
|
|
|
src = if attrs ? src
|
|
|
|
then attrs.src
|
|
|
|
else fetchurl {
|
|
|
|
url = "http://rubygems.org/downloads/${attrs.name}.gem";
|
|
|
|
inherit (attrs) sha256;
|
|
|
|
};
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2015-01-15 02:19:53 +00:00
|
|
|
phases = [ "unpackPhase" "patchPhase" "buildPhase" "checkPhase" "installPhase" "fixupPhase" ];
|
|
|
|
|
2014-09-17 13:06:37 +00:00
|
|
|
# The source is expected to either be a gem package or a directory.
|
|
|
|
#
|
|
|
|
# - Gem packages are already built, so they don't even need to be unpacked.
|
|
|
|
# They will skip the buildPhase.
|
|
|
|
# - A directory containing the sources will need to go through all of the
|
|
|
|
# usual phases.
|
|
|
|
unpackPhase= ''
|
|
|
|
gemRegex="\.gem"
|
|
|
|
if [[ $src =~ $gemRegex ]]
|
|
|
|
then
|
|
|
|
runHook preUnpack
|
2015-01-15 02:19:53 +00:00
|
|
|
echo "source is a gem package, won't unpack"
|
2014-09-17 13:06:37 +00:00
|
|
|
gempkg=$src
|
|
|
|
dontBuild=1
|
|
|
|
runHook postUnpack
|
2014-08-13 19:13:27 +00:00
|
|
|
else
|
2014-09-17 13:06:37 +00:00
|
|
|
# Fall back to the original thing for everything else.
|
|
|
|
unpackPhase
|
2014-08-13 19:13:27 +00:00
|
|
|
fi
|
2014-08-07 22:13:56 +00:00
|
|
|
'';
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2014-10-27 22:13:36 +00:00
|
|
|
checkPhase = "true";
|
2011-01-21 08:25:02 +00:00
|
|
|
|
2014-09-17 13:06:37 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
# TODO: Investigate. The complete working tree is touched by fetchgit.
|
|
|
|
if [ -d .git ]; then
|
|
|
|
git reset
|
|
|
|
fi
|
|
|
|
|
2015-01-15 02:19:53 +00:00
|
|
|
gemspec=$(find . -name '*.gemspec')
|
|
|
|
echo "found the following gemspecs:"
|
|
|
|
echo "$gemspec"
|
|
|
|
|
|
|
|
gemspec=$(echo "$gemspec" | head -n1)
|
|
|
|
echo "building $gemspec"
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
output=$(gem build $gemspec | tee >(cat - >&3))
|
|
|
|
exec 3>&-
|
2014-10-28 01:22:17 +00:00
|
|
|
|
2015-01-15 02:19:53 +00:00
|
|
|
gempkg=$(echo "$output" | grep -oP 'File: \K(.*)')
|
2014-09-17 13:06:37 +00:00
|
|
|
|
2015-01-15 02:19:53 +00:00
|
|
|
echo "gem package built: $gempkg"
|
2014-09-17 13:06:37 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
2014-08-07 22:13:56 +00:00
|
|
|
installPhase = ''
|
2014-08-09 19:55:31 +00:00
|
|
|
runHook preInstall
|
2014-08-31 17:32:34 +00:00
|
|
|
|
|
|
|
# NOTE: This does NOT build the unpacked gem, but installs $src directly.
|
|
|
|
# Gems that have not been downloaded from rubygems.org may need a
|
|
|
|
# separate buildPhase.
|
|
|
|
# --ignore-dependencies is necessary as rubygems otherwise always
|
|
|
|
# connects to the repository, thus breaking pure builds.
|
2014-11-02 22:05:37 +00:00
|
|
|
GEM_HOME=$out/${ruby.gemPath} \
|
2014-10-26 20:13:10 +00:00
|
|
|
gem install \
|
|
|
|
--local \
|
|
|
|
--force \
|
|
|
|
--http-proxy "http://nodtd.invalid" \
|
|
|
|
--ignore-dependencies \
|
|
|
|
--build-root "/" \
|
|
|
|
--backtrace \
|
2014-09-17 13:06:37 +00:00
|
|
|
$gempkg $gemFlags -- $buildFlags
|
2014-10-26 20:13:10 +00:00
|
|
|
|
2015-01-15 02:19:53 +00:00
|
|
|
# Yes, we really do need the $out/${ruby.gemPath}/cache.
|
|
|
|
# This is very important in order for many parts of RubyGems/Bundler to not blow up.
|
|
|
|
# See https://github.com/bundler/bundler/issues/3327
|
2014-08-07 22:13:56 +00:00
|
|
|
|
2014-11-02 22:05:37 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
for prog in $out/${ruby.gemPath}/gems/*/bin/*; do
|
|
|
|
makeWrapper $prog $out/bin/$(basename $prog) \
|
|
|
|
--prefix GEM_PATH : "$out/${ruby.gemPath}:$GEM_PATH" \
|
2014-08-07 22:13:56 +00:00
|
|
|
--prefix RUBYLIB : "${rubygems}/lib" \
|
|
|
|
$extraWrapperFlags ''${extraWrapperFlagsArray[@]}
|
|
|
|
done
|
2015-01-20 01:02:47 +00:00
|
|
|
#--prefix RUBYOPT rubygems \
|
2014-08-07 22:13:56 +00:00
|
|
|
|
|
|
|
# looks like useless files which break build repeatability and consume space
|
2014-11-02 22:05:37 +00:00
|
|
|
rm -fv $out/${ruby.gemPath}/doc/*/*/created.rid || true
|
|
|
|
rm -fv $out/${ruby.gemPath}/gems/*/ext/*/mkmf.log || true
|
2014-08-07 22:13:56 +00:00
|
|
|
|
2014-08-08 01:46:17 +00:00
|
|
|
mkdir -p $out/nix-support
|
|
|
|
|
|
|
|
cat > $out/nix-support/setup-hook <<EOF
|
2014-10-28 01:22:17 +00:00
|
|
|
if [[ "\$GEM_PATH" != *$out* ]]; then
|
2014-08-09 19:55:31 +00:00
|
|
|
addToSearchPath GEM_PATH $out/${ruby.gemPath}
|
|
|
|
fi
|
2014-08-08 01:46:17 +00:00
|
|
|
EOF
|
|
|
|
|
2014-08-07 22:13:56 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2012-02-17 21:40:14 +00:00
|
|
|
|
2014-08-07 22:13:56 +00:00
|
|
|
propagatedBuildInputs = gemPath;
|
|
|
|
propagatedUserEnvPkgs = gemPath;
|
2013-02-06 00:08:04 +00:00
|
|
|
|
2014-08-07 22:13:56 +00:00
|
|
|
passthru.isRubyGem = true;
|
|
|
|
inherit meta;
|
|
|
|
})
|
2014-10-31 01:44:57 +00:00
|
|
|
|
|
|
|
)
|