Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / r-modules / generic-builder.nix
blob1e96a64a5e286545feb0f8a172040d04d197e217
1 { stdenv, lib, R, libcxx, xvfb_run, util-linux, Cocoa, Foundation, gettext, gfortran }:
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.isDarwin [Cocoa Foundation gfortran];
10   NIX_CFLAGS_COMPILE =
11     lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
13   configurePhase = ''
14     runHook preConfigure
15     export R_LIBS_SITE="$R_LIBS_SITE''${R_LIBS_SITE:+:}$out/library"
16     runHook postConfigure
17   '';
19   buildPhase = ''
20     runHook preBuild
21     runHook postBuild
22   '';
24   installFlags = if attrs.doCheck or true then
25     []
26   else
27     [ "--no-test-load" ];
29   rCommand = if requireX then
30     # Unfortunately, xvfb-run has a race condition even with -a option, so that
31     # we acquire a lock explicitly.
32     "flock ${xvfb_run} xvfb-run -a -e xvfb-error R"
33   else
34     "R";
36   installPhase = ''
37     runHook preInstall
38     mkdir -p $out/library
39     $rCommand CMD INSTALL $installFlags --configure-args="$configureFlags" -l $out/library .
40     runHook postInstall
41   '';
43   postFixup = ''
44     if test -e $out/nix-support/propagated-build-inputs; then
45         ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
46     fi
47   '';
49   checkPhase = ''
50     # noop since R CMD INSTALL tests packages
51   '';
52 } // attrs // {
53   name = "r-" + name;