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.
This commit is contained in:
Chris Hodapp
2017-05-01 08:59:43 -04:00
parent e82070382a
commit 29969a5ec7
5 changed files with 52 additions and 47 deletions

View File

@@ -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;
};
};
}
```

View File

@@ -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;
};
}

View File

@@ -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 = {