summary refs log tree commit diff
path: root/pkgs/development/r-modules/generic-builder.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/r-modules/generic-builder.nix')
-rw-r--r--pkgs/development/r-modules/generic-builder.nix25
1 files changed, 21 insertions, 4 deletions
diff --git a/pkgs/development/r-modules/generic-builder.nix b/pkgs/development/r-modules/generic-builder.nix
index da63566f38b..45c377635c9 100644
--- a/pkgs/development/r-modules/generic-builder.nix
+++ b/pkgs/development/r-modules/generic-builder.nix
@@ -1,9 +1,10 @@
-R:
+{ stdenv, R, xvfb_run, utillinux }:
 
 { name, buildInputs ? [], ... } @ attrs:
 
-R.stdenv.mkDerivation ({
-  buildInputs = buildInputs ++ [R];
+stdenv.mkDerivation ({
+  buildInputs = buildInputs ++ [R] ++
+                stdenv.lib.optionals attrs.requireX [utillinux xvfb_run];
 
   configurePhase = ''
     runHook preConfigure
@@ -16,10 +17,22 @@ R.stdenv.mkDerivation ({
     runHook postBuild
   '';
 
+  installFlags = if attrs.doCheck or true then
+    []
+  else
+    [ "--no-test-load" ];
+
+  rCommand = if attrs.requireX or false then
+    # Unfortunately, xvfb-run has a race condition even with -a option, so that
+    # we acquire a lock explicitly.
+    "flock ${xvfb_run} xvfb-run -a -e xvfb-error R"
+  else
+    "R";
+
   installPhase = ''
     runHook preInstall
     mkdir -p $out/library
-    R CMD INSTALL -l $out/library .
+    $rCommand CMD INSTALL $installFlags --configure-args="$configureFlags" -l $out/library .
     runHook postInstall
   '';
 
@@ -28,6 +41,10 @@ R.stdenv.mkDerivation ({
         ln -s $out/nix-support/propagated-native-build-inputs $out/nix-support/propagated-user-env-packages
     fi
   '';
+
+  checkPhase = ''
+    # noop since R CMD INSTALL tests packages
+  '';
 } // attrs // {
   name = "r-" + name;
 })