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

95 lines
2.2 KiB
Nix
Raw Normal View History

2014-08-07 22:13:56 +00:00
{ ruby, fetchurl, rake, rubygemsFun, makeWrapper, lib, git }:
{ name
, namePrefix ? "ruby${ruby.majorVersion}" + "-"
, buildInputs ? []
2014-08-08 01:35:36 +00:00
, doCheck ? false
, dontBuild ? true
2014-08-07 22:13:56 +00:00
, meta ? {}
, gemPath ? []
, testTask ? "test"
, ...} @ attrs:
let
2014-08-07 22:13:56 +00:00
rubygems = rubygemsFun ruby;
depsPath = lib.concatStringsSep ":" (map (g: "${g}/${ruby.gemPath}") gemPath);
2014-08-07 22:13:56 +00:00
in ruby.stdenv.mkDerivation (attrs // {
inherit doCheck;
2014-08-07 22:13:56 +00:00
buildInputs = [ rubygems makeWrapper git ] ++ buildInputs;
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;
};
2014-08-07 22:13:56 +00:00
unpackPhase = ''
2014-08-13 19:13:27 +00:00
if test -d $src; then
cd $src
else
gem unpack $src --target=gem-build
cd gem-build/*
fi
2014-08-07 22:13:56 +00:00
'';
buildPhase = ''
runHook preBuild
2014-08-13 19:13:27 +00:00
test -d .git || {
chmod 755 .
${git}/bin/git init
${git}/bin/git add .
}
if gem build *.gemspec; then
export src=*.gem
else
echo >&2 "gemspec missing, not rebuilding gem"
fi
runHook postBuild
2014-08-07 22:13:56 +00:00
'';
2014-08-07 22:13:56 +00:00
installPhase = ''
runHook preInstall
2014-08-08 01:53:17 +00:00
GEM_HOME=$out/${ruby.gemPath} \
2014-08-07 22:13:56 +00:00
gem install -p http://nodtd.invalid \
--build-root / -n "$out/bin" "$src" $gemFlags -- $buildFlags
rm -frv $out/${ruby.gemPath}/cache # don't keep the .gem file here
for prog in $out/bin/*; do
wrapProgram "$prog" \
2014-08-10 01:01:40 +00:00
--prefix GEM_PATH : "$out/${ruby.gemPath}:$GEM_PATH" \
2014-08-07 22:13:56 +00:00
--prefix RUBYLIB : "${rubygems}/lib" \
--set RUBYOPT rubygems \
$extraWrapperFlags ''${extraWrapperFlagsArray[@]}
done
for prog in $out/gems/*/bin/*; do
[[ -e "$out/bin/$(basename $prog)" ]]
done
# looks like useless files which break build repeatability and consume space
rm $out/${ruby.gemPath}/doc/*/*/created.rid || true
rm $out/${ruby.gemPath}/gems/*/ext/*/mkmf.log || true
2014-08-08 01:46:17 +00:00
mkdir -p $out/nix-support
cat > $out/nix-support/setup-hook <<EOF
if [[ "$GEM_PATH" != *$out/${ruby.gemPath}* ]]; then
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
'';
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;
})