nixpkgs/pkgs/development/r-modules/generic-builder.nix

55 lines
1.4 KiB
Nix
Raw Permalink Normal View History

2021-05-08 13:45:03 +00:00
{ stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran }:
2014-05-04 21:54:11 +00:00
{ name, buildInputs ? [], requireX ? false, ... } @ attrs:
2014-05-04 21:54:11 +00:00
stdenv.mkDerivation ({
buildInputs = buildInputs ++ [R gettext] ++
2021-05-08 13:45:03 +00:00
lib.optionals requireX [util-linux xvfb-run] ++
lib.optionals stdenv.isDarwin [Cocoa Foundation gfortran];
NIX_CFLAGS_COMPILE =
lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
2014-05-04 21:54:11 +00:00
configurePhase = ''
runHook preConfigure
export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
runHook postBuild
'';
installFlags = if attrs.doCheck or true then
[]
2014-11-21 13:23:36 +00:00
else
[ "--no-test-load" ];
2014-11-21 13:23:36 +00:00
rCommand = if requireX then
2014-11-21 13:23:36 +00:00
# Unfortunately, xvfb-run has a race condition even with -a option, so that
# we acquire a lock explicitly.
2021-05-08 13:45:03 +00:00
"flock ${xvfb-run} xvfb-run -a -e xvfb-error R"
2014-11-21 13:23:36 +00:00
else
"R";
2014-05-04 21:54:11 +00:00
installPhase = ''
runHook preInstall
mkdir -p $out/library
$rCommand CMD INSTALL $installFlags --configure-args="$configureFlags" -l $out/library .
2014-05-04 21:54:11 +00:00
runHook postInstall
'';
postFixup = ''
if test -e $out/nix-support/propagated-build-inputs; then
ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
2014-05-04 21:54:11 +00:00
fi
'';
checkPhase = ''
# noop since R CMD INSTALL tests packages
'';
} // attrs // {
name = "r-" + name;
})