woodpecker-{agent,cli,server}: 3.0.0 -> 3.0.1
[NixPkgs.git] / pkgs / development / r-modules / generic-builder.nix
blob6e3f93f5232132c6c748abf16be0413741aaab7e
1 { stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran, libiconv }:
3 { name, buildInputs ? [], requireX ? false, ... } @ attrs:
5 stdenv.mkDerivation ({
6   buildInputs = buildInputs ++ [R gettext] ++
7                 lib.optionals requireX [util-linux xvfb-run] ++
8                 lib.optionals stdenv.hostPlatform.isDarwin [Cocoa Foundation gfortran libiconv];
10   env.NIX_CFLAGS_COMPILE =
11     lib.optionalString stdenv.hostPlatform.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
13   enableParallelBuilding = true;
15   configurePhase = ''
16     runHook preConfigure
17     export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}"
18     export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
19     runHook postConfigure
20   '';
22   buildPhase = ''
23     runHook preBuild
24     runHook postBuild
25   '';
27   installFlags = if attrs.doCheck or true then
28     []
29   else
30     [ "--no-test-load" ];
32   rCommand = if requireX then
33     # Unfortunately, xvfb-run has a race condition even with -a option, so that
34     # we acquire a lock explicitly.
35     "flock ${xvfb-run} xvfb-run -a -e xvfb-error R"
36   else
37     "R";
39   installPhase = ''
40     runHook preInstall
41     mkdir -p $out/library
42     $rCommand CMD INSTALL --built-timestamp='1970-01-01 00:00:00 UTC' $installFlags --configure-args="$configureFlags" -l $out/library .
43     runHook postInstall
44   '';
46   postFixup = ''
47     if test -e $out/nix-support/propagated-build-inputs; then
48         ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
49     fi
50   '';
52   checkPhase = ''
53     # noop since R CMD INSTALL tests packages
54   '';
55 } // attrs // {
56   name = "r-" + name;