summary refs log tree commit diff
path: root/pkgs/development/r-modules/wrapper-rstudio.nix
blob: dd9b0e9c5381ab6232042b4d1534a6cc58c91604 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
  };
}