git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #25390 from Hodapp87/rstudio_fix

rstudio: Fix recompilation issue with custom package set

commit287e67046254984718aee61aa28c7fc8027bbc9a authorPeter Simons <simons@cryp.to> dateTue 2 May 2017, 16:43 (10 years ago) parente026fb429969a5
5 files changed+52−47
pkgs/applications/editors/rstudio/default.nix+3−17 pkgs/development/r-modules/README.md+6−11 pkgs/development/r-modules/wrapper-rstudio.nix+33 pkgs/development/r-modules/wrapper.nix+1−19 pkgs/top-level/all-packages.nix+9
pkgs/applications/editors/rstudio/default.nix+3−17
@@ -1,13 +1,5 @@
11{ stdenv, fetchurl, makeDesktopItem, cmake, boost163, zlib, openssl,
2−R, qt5, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper, pandoc,
3−# If you have set up an R wrapper with other packages by following
4−# something like https://nixos.org/nixpkgs/manual/#r-packages, RStudio
5−# by default not be able to access any of those R packages. In order
6−# to do this, override the argument "R" here with your respective R
7−# wrapper, and set "useRPackages" to true. This will add the
8−# environment variable R_PROFILE_USER to the RStudio wrapper, pointing
9−# to an R script which will allow R to use these packages.
10−useRPackages ? false
2+R, qt5, libuuid, hunspellDicts, unzip, ant, jdk, gnumake, makeWrapper, pandoc
113}:
124
135let
@@ -111,14 +103,8 @@ stdenv.mkDerivation rec {
111103 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;";
112104 };
113105
114− postInstall = let rProfile =
115− # RStudio seems to bypass the environment variables that the R
116− # wrapper already applies, and so this sets R_PROFILE_USER to
117− # again make those R packages accessible:
118− if useRPackages
119− then "--set R_PROFILE_USER ${R}/${R.passthru.fixLibsR}" else "";
120− in ''
121− wrapProgram $out/bin/rstudio --suffix PATH : ${gnumake}/bin ${rProfile}
106+ postInstall = ''
107+ wrapProgram $out/bin/rstudio --suffix PATH : ${gnumake}/bin
122108 mkdir $out/share
123109 cp -r ${desktopItem}/share/applications $out/share
124110 mkdir $out/share/icons
pkgs/development/r-modules/README.md+6−11
@@ -55,28 +55,23 @@ available.
5555
5656## RStudio
5757
58−RStudio by default will not use the libraries installed like above.
59−You must override its R version with your custom R environment, and
60−set `useRPackages` to `true`, like below:
58+RStudio uses a standard set of packages and ignores any custom R
59+environments or installed packages you may have. To create a custom
60+environment, see `rstudioWrapper`, which functions similarly to
61+`rWrapper`:
6162
6263```nix
6364{
6465 packageOverrides = super: let self = super.pkgs; in
6566 {
6667
67− rEnv = super.rWrapper.override {
68+ rstudioEnv = super.rstudioWrapper.override {
6869 packages = with self.rPackages; [
69− devtools
70+ dplyr
7071 ggplot2
7172 reshape2
72− yaml
73− optparse
7473 ];
7574 };
76− rstudioEnv = super.rstudio.override {
77− R = rEnv;
78− useRPackages = true;
79− };
8075 };
8176}
8277```
pkgs/development/r-modules/wrapper-rstudio.nixnew file+33
@@ -0,0 +1,33 @@
1+{ stdenv, R, rstudio, makeWrapper, recommendedPackages, packages }:
2+
3+stdenv.mkDerivation rec {
4+
5+ name = rstudio.name + "-wrapper";
6+
7+ buildInputs = [makeWrapper R rstudio] ++ recommendedPackages ++ packages;
8+
9+ unpackPhase = ":";
10+
11+ # rWrapper points R to a specific set of packages by using a wrapper
12+ # (as in https://nixos.org/nixpkgs/manual/#r-packages) which sets
13+ # R_LIBS_SITE. Ordinarily, it would be possible to make RStudio use
14+ # this same set of packages by simply overriding its version of R
15+ # with the wrapped one, however, RStudio internally overrides
16+ # R_LIBS_SITE. The below works around this by turning R_LIBS_SITE
17+ # into an R file (fixLibsR) which achieves the same effect, then
18+ # uses R_PROFILE_USER to load this code at startup in RStudio.
19+ fixLibsR = "fix_libs.R";
20+ installPhase = ''
21+ mkdir $out
22+ echo "# Autogenerated by wrapper-rstudio.nix from R_LIBS_SITE" > $out/${fixLibsR}
23+ echo -n ".libPaths(c(.libPaths(), \"" >> $out/${fixLibsR}
24+ echo -n $R_LIBS_SITE | sed -e 's/:/", "/g' >> $out/${fixLibsR}
25+ echo -n "\"))" >> $out/${fixLibsR}
26+ echo >> $out/${fixLibsR}
27+ makeWrapper ${rstudio}/bin/rstudio $out/bin/rstudio --set R_PROFILE_USER $out/${fixLibsR}
28+ '';
29+
30+ meta = {
31+ platforms = stdenv.lib.platforms.unix;
32+ };
33+}
pkgs/development/r-modules/wrapper.nix+1−19
@@ -1,19 +1,12 @@
11{ stdenv, R, makeWrapper, recommendedPackages, packages }:
22
3−stdenv.mkDerivation rec {
3+stdenv.mkDerivation {
44 name = R.name + "-wrapper";
55
66 buildInputs = [makeWrapper R] ++ recommendedPackages ++ packages;
77
88 unpackPhase = ":";
99
10− # This filename is used in 'installPhase', but needs to be
11− # referenced elsewhere. This will be relative to this package's
12− # path.
13− passthru = {
14− fixLibsR = "fix_libs.R";
15− };
16−
1710 installPhase = ''
1811 mkdir -p $out/bin
1912 cd ${R}/bin
@@ -21,17 +14,6 @@ stdenv.mkDerivation rec {
2114 makeWrapper ${R}/bin/$exe $out/bin/$exe \
2215 --prefix "R_LIBS_SITE" ":" "$R_LIBS_SITE"
2316 done
24− # RStudio (and perhaps other packages) overrides the R_LIBS_SITE
25− # which the wrapper above applies, and as a result packages
26− # installed in the wrapper (as in the method described in
27− # https://nixos.org/nixpkgs/manual/#r-packages) aren't visible.
28− # The below turns R_LIBS_SITE into some R startup code which can
29− # correct this.
30− echo "# Autogenerated by wrapper.nix from R_LIBS_SITE" > $out/${passthru.fixLibsR}
31− echo -n ".libPaths(c(.libPaths(), \"" >> $out/${passthru.fixLibsR}
32− echo -n $R_LIBS_SITE | sed -e 's/:/", "/g' >> $out/${passthru.fixLibsR}
33− echo -n "\"))" >> $out/${passthru.fixLibsR}
34− echo >> $out/${passthru.fixLibsR}
3517 '';
3618
3719 meta = {
pkgs/top-level/all-packages.nix+9
@@ -10610,6 +10610,15 @@ with pkgs;
1061010610 packages = [];
1061110611 };
1061210612
10613+ rstudioWrapper = callPackage ../development/r-modules/wrapper-rstudio.nix {
10614+ recommendedPackages = with rPackages; [
10615+ boot class cluster codetools foreign KernSmooth lattice MASS
10616+ Matrix mgcv nlme nnet rpart spatial survival
10617+ ];
10618+ # Override this attribute to register additional libraries.
10619+ packages = [];
10620+ };
10621+
1061310622 rPackages = callPackage ../development/r-modules {
1061410623 overrides = (config.rPackageOverrides or (p: {})) pkgs;
1061510624 };