nixpkgs/pkgs/development/interpreters/ruby/gem.nix

120 lines
3 KiB
Nix
Raw Normal View History

2014-08-08 00:13:56 +02:00
{ ruby, fetchurl, rake, rubygemsFun, makeWrapper, lib, git }:
{ name
, namePrefix ? "ruby${ruby.majorVersion}" + "-"
, buildInputs ? []
2014-08-18 23:53:41 +02:00
, doCheck ? false # TODO: fix this
, dontBuild ? true
2014-08-08 00:13:56 +02:00
, meta ? {}
, gemPath ? []
, testTask ? "test"
, ...} @ attrs:
let
2014-08-08 00:13:56 +02:00
rubygems = rubygemsFun ruby;
2014-08-08 00:13:56 +02:00
in ruby.stdenv.mkDerivation (attrs // {
inherit doCheck;
2014-08-08 00:13:56 +02:00
buildInputs = [ rubygems makeWrapper git ] ++ buildInputs;
2014-08-08 00:13:56 +02:00
name = namePrefix + name;
src = if attrs ? src
then attrs.src
else fetchurl {
url = "http://rubygems.org/downloads/${attrs.name}.gem";
inherit (attrs) sha256;
};
2014-09-17 15:06:37 +02: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
echo "Source is a gem package, won't unpack."
gempkg=$src
dontBuild=1
runHook postUnpack
2014-08-13 21:13:27 +02:00
else
2014-09-17 15:06:37 +02:00
# Fall back to the original thing for everything else.
unpackPhase
2014-08-13 21:13:27 +02:00
fi
2014-08-08 00:13:56 +02:00
'';
2014-10-27 23:13:36 +01:00
checkPhase = "true";
2014-09-17 15:06:37 +02:00
buildPhase = ''
runHook preBuild
# TODO: Investigate. The complete working tree is touched by fetchgit.
if [ -d .git ]; then
git reset
fi
gemspec=`find . -name '*.gemspec'`
output=`gem build $gemspec`
gempkg=`echo $output|grep -oP 'File: \K(.*)'`
echo "Gem package built: $gempkg"
runHook postBuild
'';
2014-08-08 00:13:56 +02:00
installPhase = ''
runHook preInstall
# 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-09-17 15:06:37 +02:00
GEM_HOME=$out \
2014-10-26 21:13:10 +01:00
gem install \
--local \
--force \
--http-proxy "http://nodtd.invalid" \
--ignore-dependencies \
--build-root "/" \
--bindir "$out/bin" \
--backtrace \
2014-09-17 15:06:37 +02:00
$gempkg $gemFlags -- $buildFlags
2014-10-26 21:13:10 +01:00
2014-09-17 15:06:37 +02:00
rm -frv $out/cache # don't keep the .gem file here
2014-08-08 00:13:56 +02:00
for prog in $out/bin/*; do
wrapProgram "$prog" \
2014-09-17 15:06:37 +02:00
--prefix GEM_PATH : "$out:$GEM_PATH" \
2014-08-08 00:13:56 +02:00
--prefix RUBYLIB : "${rubygems}/lib" \
--set RUBYOPT rubygems \
$extraWrapperFlags ''${extraWrapperFlagsArray[@]}
done
# looks like useless files which break build repeatability and consume space
2014-09-17 15:06:37 +02:00
rm -fv $out/doc/*/*/created.rid || true
rm -fv $out/gems/*/ext/*/mkmf.log || true
2014-08-08 00:13:56 +02:00
2014-08-08 03:46:17 +02:00
mkdir -p $out/nix-support
cat > $out/nix-support/setup-hook <<EOF
2014-09-17 15:06:37 +02:00
if [[ "$GEM_PATH" != *$out* ]]; then
addToSearchPath GEM_PATH $out/${ruby.gemPath}
fi
2014-08-08 03:46:17 +02:00
EOF
2014-08-08 00:13:56 +02:00
runHook postInstall
'';
2014-08-08 00:13:56 +02:00
propagatedBuildInputs = gemPath;
propagatedUserEnvPkgs = gemPath;
2013-02-06 01:08:04 +01:00
2014-08-08 00:13:56 +02:00
passthru.isRubyGem = true;
inherit meta;
})