Rstudio bug Segmentation fault

Rstudio is still not working with a segmentation fault. I am on 25.11, and id like help debugging it or knowing how to find the error to patch it. Regards

❯ rstudio
/bin/sh: line 1: /usr/bin/which: No such file or directory
zsh: segmentation fault (core dumped) rstudio

1 Like

How did you install rstudio? That looks like a package for another distro, you’d need to do extensive patching (which the nixpkgs package should have already done for you) to use that on NixOS.

I’m getting the exact same error message on 25.11; this worked just fine with the same configuration until just recently.My configuration is like this:

{ config, pkgs, lib, ... }:
let
  # Define required R packages:
required_r_packages = with pkgs.rPackages; [
   arrow
   tidymodels
   tidyverse
   # And more packages as needed.
];
  r_w_pkgs = pkgs.rWrapper.override { packages = required_r_packages; };
  rLibsSite = "${r_w_pkgs}/lib/R/library";
in
{
  # Install R with Packages:
  environment.systemPackages = with pkgs; [
    stanc
    r_w_pkgs
    quarto
    pandoc
    which # added this, but doesn't resolve. 
    (rstudioWrapper.override { 
      R = r_w_pkgs; 
      packages = required_r_packages;
      })
  ];
}

I’ll let you know if I figure it out.

@Sejder I think I have it figured out. I added this to my configuration:

systemd.tmpfiles.rules = [
“L+ /usr/bin/which - - - - ${pkgs.which}/bin/which”
];

This just creates a symlink to which and after I ran nixos-rebuild switchmy rstudio is back up and running as it used to! :slight_smile:

Now, what would be ideal is reviewing the packaging code, and submitting a PR to resolve this for others when they install the package without that symlink hack.

1 Like

yes that seemed to fix that bug:)) It feels a bit hacky though

It is; it breaks NixOS’ concept of not having FHS dirs. It won’t be cleaned up if you remove the rule when the underlying issue is fixed, either.

The rstudio package also has code to take care of this, so I wonder if this is actually an upstream bug or the result of some of your configuration: nixpkgs/pkgs/applications/science/math/R/default.nix at 09eb77e94fa25202af8f3e81ddc7353d9970ac1b · NixOS/nixpkgs · GitHub

I’m not an R user, but it strikes me as odd that you’re doubly installing R (both via r_w_pkgs/rWrapper and an override of the rstudioWrapper). Depending on ordering, it’s quite possible you end up with a binary that doesn’t have whatever workarounds apply to which applied.

Additionally, the issue might actually be in one of the R packages rather than R itself. Simplifying the config and incrementally adding that complexity back until you find the root cause would be the first step to writing an issue that can actually be fixed.

well i have just build the package locally without any changes and it still cannot run with the same segmentation fault again /bin/sh: line 1: /usr/bin/which: No such file or directory
zsh: segmentation fault (core dumped) ./result/bin/rstudio. I think we should look at the build process to find the error

If modifiying the postPatch to

postPatch = ''     
  find . -type f \( -name "*.sh" -o -name "*.R" -o -name "*.cpp" -o -name "*.hpp" -o -name "*.js" -o -name "*.ts" \) \    
  -exec sed -i 's|/usr/bin/which|which|g' {} +     
  # fix .desktop Exec field     
  substituteInPlace src/node/desktop/resources/freedesktop/rstudio.desktop.in \       
    --replace-fail "\''${CMAKE_INSTALL_PREFIX}/rstudio" "rstudio" 

  # set install path of freedesktop files     
  substituteInPlace src/node/desktop/CMakeLists.txt \      
    --replace-fail "/usr/share" "$out/share"   
'';

that replaces “/usr/bin/which” with “which” the normal build works. I dont know if it works with the wrappers though. Is this a potential fix?

Absolutely, I just don’t know why the package doesn’t do that already and the maintainers haven’t noticed.

i found that these files contains the problem

[nix-shell:~/rStudioTest/source]$ grep -rl “/usr/bin/which” .
./src/node/desktop/src/main/detect-r.ts
./src/node/desktop/src/main/gwt-callback.ts
./src/cpp/session/modules/clang/CodeCompletion.cpp
./src/cpp/core/system/PosixSystemTests.cpp

so a better solution might be nix’ substituteInPlace method

  postPatch = ''
    substituteInPlace \
    src/node/desktop/src/main/detect-r.ts \
    src/node/desktop/src/main/gwt-callback.ts \
    src/cpp/session/modules/clang/CodeCompletion.cpp \
    src/cpp/core/system/PosixSystemTests.cpp \
    --replace-fail "/usr/bin/which" "which"
    
    # fix .desktop Exec field
    substituteInPlace src/node/desktop/resources/freedesktop/rstudio.desktop.in \
      --replace-fail "\''${CMAKE_INSTALL_PREFIX}/rstudio" "rstudio"

    # set install path of freedesktop files
    substituteInPlace src/node/desktop/CMakeLists.txt \
      --replace-fail "/usr/share" "$out/share"
  '';

EDIT: I have now done a pull request with this change

1 Like

Agreed it is hacky. I just wanted to get some of my work done - and confirm there wasn’t more to it since I also received a bunch of GPU warnings and a subsequent segfault.

Glad you managed to figure it out in a better way, seems theres been a long standing issue since early July in unstable. (https://github.com/NixOS/nixpkgs/issues/422962)

1 Like

Just wanted to share an easy workaround until the proper fix is found:
setting the environment variable RSTUDIO_QUERY_FONTS=0 will skip calling the function that segfaults.
I’ll keep working to try to find a proper fix.

1 Like

Thanks for this info - I wrote my Rstudio configuration when I was brand new to NixOS, and actually haven’t revisited it. If I recall, I was struggling to get R packages to show-up in my environment which is why there’s the bizarre wrapper set-up.

This works for me with export RSTUDIO_QUERY_FONTS=0, allthough the /usr/bin/which error still complains. I think it would still make sense to rewrite this such that it is nixos compatible.

❯ export RSTUDIO_QUERY_FONTS=0

~
❯ rstudio
[5794:1212/082441.242894:ERROR:ui/gl/init/gl_factory.cc:103] Requested GL implementation (gl=none,angle=none) not found in allowed implementations: [(gl=egl-angle,angle=default)].
[5794:1212/082441.244039:ERROR:components/viz/service/main/viz_main_impl.cc:184] Exiting GPU process due to errors during initialization
/bin/sh: line 1: /usr/bin/which: No such file or directory