2
{
  description = "virtual environment with Rstudio, R, Shiny";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};

        rWrapper=pkgs.rWrapper;
        rstudioWrapper=pkgs.rstudioWrapper;
        rstudioServerWrapper=pkgs.rstudioServerWrapper;
        Rpackages=with pkgs.rPackages;[shiny];

        RwithPackages=   rWrapper.override{ packages =  Rpackages;};
        RStudio-with-my-packages = rstudioWrapper.override{ packages = Rpackages; };


        myDevTools = [
          #qtbase #patch
          RwithPackages
          RStudio-with-my-packages
        ];
      in {
        devShells.default = pkgs.mkShell {
          buildInputs = myDevTools;
        };
      });
}

This flake.nix works.

nix develop 

create a virtual environment

but I try to use rstudio, I get this error:

 rstudio 

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to ''. qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted

I ve read this webpage. I enter this command in my virtual environment:

 export QT_QPA_PLATFORM=offscreen


 rstudio

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to ''. QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/nix-shell.aeqLGO/runtime-pierre' Fontconfig error: Cannot load default config file: No such file: (null) Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed. This plugin does not support propagateSizeHints() This plugin does not support raise() Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlagsQSurfaceFormat::FormatOption(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::NoProfile)

Aborted

1 Answers1

2

I tried running your Flake locally and it works fine, but I don't have any custom configuration - my system never ran RStudio before and /etc/rstudio does not exist. This error is probably caused by RStudio loading non-Nix managed config under /etc/rstudio.

You have this in your startup message:

Logging configuration loaded from '/etc/rstudio/logging.conf'

You probably have local configuration using some plugins from another (non-Nix) RStudio installation, but in nix develop environment they can't be loaded somehow (apparently some Qt plugin). You can try to:

  • Delete or move somewhere else the content of /etc/rstudio to avoid configuration issue / conflict and check if it works
  • If it does, then enable back previously moved config to bisect the one causing failure
Pierre B.
  • 11,612
  • 1
  • 37
  • 58