Adding RStudio Server (R)

I’m currently using nix to provision singularity containers to run R analyses on a computing cluster. For interactive development I’ll use a nix-shell with the same dependencies running on my work computer. Given the current pandemic I’m using my work computer via ssh. And while emacs over X-forwarding is good enough most of the time, sometimes I want plotting at full speed. Either from the nix-shell or the singularity container.

I’ve had reasonably good experiences using RStudio-server to provide access to R sessions. I think it would be useful to develop a package that provides rstudio server. The first stage of creating this package would be simple. We change the target cmake flag to say server in:

However, I believe that rstudio-server runs as a systemd service, and I don’t have enough experience to know how to get that to work from a non-root user defined shell, particularly on a non-NixOS system.

Does anyone have any ideas on how to get this to work?

Hi @cfhammill, I got a rough version of this working last year. As I recall, besides updating cmakeFlags, the desktop, free server and pro server installations have different ways of calling R which need to be accomodated. I’m just an amateur with nix development, and I difficult plugging into pam for authentication. The server version should also be installed as a service, and I’m not familiar with how to do that in Nix. The Rstudio Pro admin guide is the best reference for what other configurations might be added. I can share my attempt after work, but it’s rough and out of date with the latest RStudio.

Thanks @nathanv! Looking forward to seeing your attempt.

I’m starting to think that running as a service is going to be impossible. I think that isn’t such a big problem because the install produces an rserver binary that lets you create the http server. I have some experience in the past overriding the R pam authentication and wrapping the rsession binaries, eliminating the need to have this connected to the system pam and honour some environment modules, so I’m somewhat familiar with the admin guide.

I’m currently in the process of trying to get it to work not in service mode. And will update if I can get it working or get stuck.

A few small changes were required to get rstudio-server to build

  1. Add a pam dependency (unlikely to work on non-nixos and without root, but required to placate cmake)
  2. Add a readline6 dependency (may not have been necessary)
  3. Change the cmake flags to set DBUILD_TARGET=Server instead of desktop
  4. Remove the icon symlinking (I guess the server version doesn’t build those)
  5. Applying wrapProgram on all of the binaries (this may not have been necessary, I was trying to fix the readline issue, which may have just gone away when I switched nix-shell to --pure).

From there running
nix-shell -p rstudio-server -p R
rserver --auth-none 1

allowed me to connect to the remote session from my home machine.

For now, auth-none is necessary because rserver can’t interact with the system pam.

This presently After that I modified wrapper-rstudio to accomodate the slightly different architecture of rstudio-server. It required wrapping ${rstudio-server}/bin/rsession with the same libPath magic as wrapper-rstudio then wrapping ${rstudio-server}/bin/rserver to point to the wrapped rsession.

I think this should be ready to PR this week.

Nice work! I’ll watch for the PR. Is R within RStudio loading libraries normally from the nix store? How about authentication with pam? For nix package manager, it looks like you might be able to add a systemd unit.

PR is up now:

Since the last message I wrote an rstudioWrapper equivalent, rstudioServerWrapper that does the appropriate libPath munging. So you would run nix-shell -p 'rstudioServerWrapper.override {packages = [ggplot2 dplyr etc ];}'

1 Like

Is anyone able to review this PR

CC @peti @ciil @ehmry ?

I am trying to fix nix run for rstudio-server ( rstudioServerWrapper: inherit meta from rstudio by teto · Pull Request #205122 · NixOS/nixpkgs · GitHub) but I am not sure what the good “official” names for the different executables should be : we have rstudio-server / rserver , are these the same ?