about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorChris Hodapp <hodapp87@gmail.com>2017-05-01 08:59:43 -0400
committerChris Hodapp <hodapp87@gmail.com>2017-05-01 09:46:40 -0400
commit29969a5ec7df53ca82585d5b7c2e472030c04f54 (patch)
tree0d8a9209a127cdd1303689b50279bbad064e094a /pkgs
parente82070382a37ef7fb6f57b9d10fcc056dba2cd02 (diff)
downloadnixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar.gz
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar.bz2
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar.lz
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar.xz
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.tar.zst
nixlib-29969a5ec7df53ca82585d5b7c2e472030c04f54.zip
rstudio: Fix recompilation issue with custom package set
This attempts to fix the issue described at
https://github.com/NixOS/nixpkgs/pull/22219#issuecomment-291801133.
Any change to the custom packages passed to RStudio causes this to
completely rebuild RStudio, which is completely unnecessary and also a
bit of a hindrance as it's a fairly slow build.

This rolls back most of that old PR, and instead implements something
more like rWrapper.  Existing configurations with the old useRPackages
will break.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/editors/rstudio/default.nix20
-rw-r--r--pkgs/development/r-modules/README.md17
-rw-r--r--pkgs/development/r-modules/wrapper-rstudio.nix33
-rw-r--r--pkgs/development/r-modules/wrapper.nix20
-rw-r--r--pkgs/top-level/all-packages.nix9
5 files changed, 52 insertions, 47 deletions
diff --git a/pkgs/applications/editors/rstudio/default.nix b/pkgs/applications/editors/rstudio/default.nix
index f7ede1a8ea56..eab1228da1ac 100644
--- a/pkgs/applications/editors/rstudio/default.nix
+++ b/pkgs/applications/editors/rstudio/default.nix
@@ -1,13 +1,5 @@
 { stdenv, fetchurl, makeDesktopItem, cmake, boost163, zlib, openssl,
-R, qt5, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper, pandoc,
-# 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
+R, qt5, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper, pandoc
 }:
 
 let
@@ -111,14 +103,8 @@ 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 = 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}
+  postInstall = ''
+      wrapProgram $out/bin/rstudio --suffix PATH : ${gnumake}/bin
       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 fc046ed0627e..477059cbb2c8 100644
--- a/pkgs/development/r-modules/README.md
+++ b/pkgs/development/r-modules/README.md
@@ -55,28 +55,23 @@ 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:
+RStudio uses a standard set of packages and ignores any custom R
+environments or installed packages you may have.  To create a custom
+environment, see `rstudioWrapper`, which functions similarly to
+`rWrapper`:
 
 ```nix
 {
     packageOverrides = super: let self = super.pkgs; in
     {
 
-        rEnv = super.rWrapper.override {
+        rstudioEnv = super.rstudioWrapper.override {
             packages = with self.rPackages; [
-                devtools
+                dplyr
                 ggplot2
                 reshape2
-                yaml
-                optparse
                 ];
         };
-        rstudioEnv = super.rstudio.override {
-            R = rEnv;
-            useRPackages = true;
-        };
     };
 }
 ```
diff --git a/pkgs/development/r-modules/wrapper-rstudio.nix b/pkgs/development/r-modules/wrapper-rstudio.nix
new file mode 100644
index 000000000000..dd9b0e9c5381
--- /dev/null
+++ b/pkgs/development/r-modules/wrapper-rstudio.nix
@@ -0,0 +1,33 @@
+{ stdenv, R, rstudio, makeWrapper, recommendedPackages, packages }:
+
+stdenv.mkDerivation rec {
+
+  name = rstudio.name + "-wrapper";
+
+  buildInputs = [makeWrapper R rstudio] ++ recommendedPackages ++ packages;
+
+  unpackPhase = ":";
+
+  # rWrapper points R to a specific set of packages by using a wrapper
+  # (as in https://nixos.org/nixpkgs/manual/#r-packages) which sets
+  # R_LIBS_SITE.  Ordinarily, it would be possible to make RStudio use
+  # this same set of packages by simply overriding its version of R
+  # with the wrapped one, however, RStudio internally overrides
+  # R_LIBS_SITE.  The below works around this by turning R_LIBS_SITE
+  # into an R file (fixLibsR) which achieves the same effect, then
+  # uses R_PROFILE_USER to load this code at startup in RStudio.
+  fixLibsR = "fix_libs.R";
+  installPhase = ''
+    mkdir $out
+    echo "# Autogenerated by wrapper-rstudio.nix from R_LIBS_SITE" > $out/${fixLibsR}
+    echo -n ".libPaths(c(.libPaths(), \"" >> $out/${fixLibsR}
+    echo -n $R_LIBS_SITE | sed -e 's/:/", "/g' >> $out/${fixLibsR}
+    echo -n "\"))" >> $out/${fixLibsR}
+    echo >> $out/${fixLibsR}
+    makeWrapper ${rstudio}/bin/rstudio $out/bin/rstudio --set R_PROFILE_USER $out/${fixLibsR}
+  '';
+  
+  meta = {
+    platforms = stdenv.lib.platforms.unix;
+  };
+}
diff --git a/pkgs/development/r-modules/wrapper.nix b/pkgs/development/r-modules/wrapper.nix
index 25c765060279..3b9a9b184506 100644
--- a/pkgs/development/r-modules/wrapper.nix
+++ b/pkgs/development/r-modules/wrapper.nix
@@ -1,19 +1,12 @@
 { stdenv, R, makeWrapper, recommendedPackages, packages }:
 
-stdenv.mkDerivation rec {
+stdenv.mkDerivation {
   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
@@ -21,17 +14,6 @@ stdenv.mkDerivation rec {
       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 = {
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index b50973790eb2..67215c456aa7 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -10608,6 +10608,15 @@ with pkgs;
     packages = [];
   };
 
+  rstudioWrapper = callPackage ../development/r-modules/wrapper-rstudio.nix {
+    recommendedPackages = with rPackages; [
+      boot class cluster codetools foreign KernSmooth lattice MASS
+      Matrix mgcv nlme nnet rpart spatial survival
+    ];
+    # Override this attribute to register additional libraries.
+    packages = [];
+  };
+
   rPackages = callPackage ../development/r-modules {
     overrides = (config.rPackageOverrides or (p: {})) pkgs;
   };