about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2017-01-29 21:13:58 +0100
committerGitHub <noreply@github.com>2017-01-29 21:13:58 +0100
commit456b9f849dea2527fba3a352e78f334cde6681d9 (patch)
treed2a88a22d19fd7d20d1242745c05c984a689d132 /pkgs
parentc1c0cf3de704df474fc3820adb11ba2f63a9f8bb (diff)
parent7638578342fa7b053095a4f89cc65cba8c70b3a2 (diff)
downloadnixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar.gz
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar.bz2
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar.lz
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar.xz
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.tar.zst
nixlib-456b9f849dea2527fba3a352e78f334cde6681d9.zip
Merge pull request #22219 from Hodapp87/master
RStudio: Optionally allow packages from custom R environment
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/editors/rstudio/default.nix22
-rw-r--r--pkgs/development/r-modules/README.md31
-rw-r--r--pkgs/development/r-modules/wrapper.nix20
3 files changed, 69 insertions, 4 deletions
diff --git a/pkgs/applications/editors/rstudio/default.nix b/pkgs/applications/editors/rstudio/default.nix
index 82bcc485da3c..5fef166e663f 100644
--- a/pkgs/applications/editors/rstudio/default.nix
+++ b/pkgs/applications/editors/rstudio/default.nix
@@ -1,4 +1,14 @@
-{ stdenv, fetchurl, makeDesktopItem, cmake, boost155, zlib, openssl, R, qt4, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper }:
+{ stdenv, fetchurl, makeDesktopItem, cmake, boost155, zlib, openssl,
+R, qt4, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper,
+# If you have set up an R wrapper with other packages by following
+# something like https://nixos.org/nixpkgs/manual/#r-packages, RStudio
+# by default not be able to access any of those R packages. In order
+# to do this, override the argument "R" here with your respective R
+# wrapper, and set "useRPackages" to true.  This will add the
+# environment variable R_PROFILE_USER to the RStudio wrapper, pointing
+# to an R script which will allow R to use these packages.
+useRPackages ? false
+}:
 
 let
   version = "0.98.110";
@@ -72,8 +82,14 @@ stdenv.mkDerivation rec {
     mimeType = "text/x-r-source;text/x-r;text/x-R;text/x-r-doc;text/x-r-sweave;text/x-r-markdown;text/x-r-html;text/x-r-presentation;application/x-r-data;application/x-r-project;text/x-r-history;text/x-r-profile;text/x-tex;text/x-markdown;text/html;text/css;text/javascript;text/x-chdr;text/x-csrc;text/x-c++hdr;text/x-c++src;";
   };
 
-  postInstall = ''
-      wrapProgram $out/bin/rstudio --suffix PATH : ${gnumake}/bin
+  postInstall = let rProfile =
+    # RStudio seems to bypass the environment variables that the R
+    # wrapper already applies, and so this sets R_PROFILE_USER to
+    # again make those R packages accessible:
+    if useRPackages
+    then "--set R_PROFILE_USER ${R}/${R.passthru.fixLibsR}" else "";
+    in ''
+      wrapProgram $out/bin/rstudio --suffix PATH : ${gnumake}/bin ${rProfile}
       mkdir $out/share
       cp -r ${desktopItem}/share/applications $out/share
       mkdir $out/share/icons
diff --git a/pkgs/development/r-modules/README.md b/pkgs/development/r-modules/README.md
index e384b375460a..9a7ccc55ac91 100644
--- a/pkgs/development/r-modules/README.md
+++ b/pkgs/development/r-modules/README.md
@@ -53,6 +53,37 @@ in with pkgs; {
 and then run `nix-shell .` to be dropped into a shell with those packages
 available.
 
+## RStudio
+
+RStudio by default will not use the libraries installed like above.
+You must override its R version with your custom R environment, and
+set `useRPackages` to `true`, like below:
+
+```nix
+{
+    packageOverrides = super: let self = super.pkgs; in
+    {
+
+        rEnv = super.rWrapper.override {
+            packages = with self.rPackages; [ 
+                devtools
+                ggplot2
+                reshape2
+                yaml
+                optparse
+                ];
+        };
+        rstudioEnv = super.rstudio.override {
+            R = rEnv;
+            useRPackages = true;
+        };
+    };
+}
+```
+
+Then like above, `nix-env -f "<nixpkgs>" -iA rstudioEnv` will install
+this into your user profile.
+
 ## Updating the package set
 
 ```bash
diff --git a/pkgs/development/r-modules/wrapper.nix b/pkgs/development/r-modules/wrapper.nix
index 3b9a9b184506..25c765060279 100644
--- a/pkgs/development/r-modules/wrapper.nix
+++ b/pkgs/development/r-modules/wrapper.nix
@@ -1,12 +1,19 @@
 { stdenv, R, makeWrapper, recommendedPackages, packages }:
 
-stdenv.mkDerivation {
+stdenv.mkDerivation rec {
   name = R.name + "-wrapper";
 
   buildInputs = [makeWrapper R] ++ recommendedPackages ++ packages;
 
   unpackPhase = ":";
 
+  # This filename is used in 'installPhase', but needs to be
+  # referenced elsewhere.  This will be relative to this package's
+  # path.
+  passthru = {
+    fixLibsR = "fix_libs.R";
+  };
+  
   installPhase = ''
     mkdir -p $out/bin
     cd ${R}/bin
@@ -14,6 +21,17 @@ stdenv.mkDerivation {
       makeWrapper ${R}/bin/$exe $out/bin/$exe \
         --prefix "R_LIBS_SITE" ":" "$R_LIBS_SITE"
     done
+    # RStudio (and perhaps other packages) overrides the R_LIBS_SITE
+    # which the wrapper above applies, and as a result packages
+    # installed in the wrapper (as in the method described in
+    # https://nixos.org/nixpkgs/manual/#r-packages) aren't visible.
+    # The below turns R_LIBS_SITE into some R startup code which can
+    # correct this.
+    echo "# Autogenerated by wrapper.nix from R_LIBS_SITE" > $out/${passthru.fixLibsR}
+    echo -n ".libPaths(c(.libPaths(), \"" >> $out/${passthru.fixLibsR}
+    echo -n $R_LIBS_SITE | sed -e 's/:/", "/g' >> $out/${passthru.fixLibsR}
+    echo -n "\"))" >> $out/${passthru.fixLibsR}
+    echo >> $out/${passthru.fixLibsR}
   '';
 
   meta = {