2023-02-09 11:40:11 +00:00
|
|
|
{ stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran, libiconv }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
{ name, buildInputs ? [], requireX ? false, ... } @ attrs:
|
|
|
|
|
|
|
|
stdenv.mkDerivation ({
|
|
|
|
buildInputs = buildInputs ++ [R gettext] ++
|
2021-05-20 23:08:51 +00:00
|
|
|
lib.optionals requireX [util-linux xvfb-run] ++
|
2023-02-09 11:40:11 +00:00
|
|
|
lib.optionals stdenv.isDarwin [Cocoa Foundation gfortran libiconv];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE =
|
2021-05-20 23:08:51 +00:00
|
|
|
lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2024-05-15 15:35:15 +00:00
|
|
|
export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}"
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
[]
|
|
|
|
else
|
|
|
|
[ "--no-test-load" ];
|
|
|
|
|
|
|
|
rCommand = if requireX then
|
|
|
|
# Unfortunately, xvfb-run has a race condition even with -a option, so that
|
|
|
|
# we acquire a lock explicitly.
|
2021-05-20 23:08:51 +00:00
|
|
|
"flock ${xvfb-run} xvfb-run -a -e xvfb-error R"
|
2020-04-24 23:36:52 +00:00
|
|
|
else
|
|
|
|
"R";
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/library
|
2021-12-19 01:06:50 +00:00
|
|
|
$rCommand CMD INSTALL --built-timestamp='1970-01-01 00:00:00 UTC' $installFlags --configure-args="$configureFlags" -l $out/library .
|
2020-04-24 23:36:52 +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
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhase = ''
|
|
|
|
# noop since R CMD INSTALL tests packages
|
|
|
|
'';
|
|
|
|
} // attrs // {
|
|
|
|
name = "r-" + name;
|
|
|
|
})
|