Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rstudio on Mac Failure #451

Open
jgeller112 opened this issue Mar 12, 2025 · 22 comments · Fixed by NixOS/nixpkgs#384339
Open

Rstudio on Mac Failure #451

jgeller112 opened this issue Mar 12, 2025 · 22 comments · Fixed by NixOS/nixpkgs#384339

Comments

@jgeller112
Copy link

I just tried to open a rstudio session within the nix shell and am getting the below error

node:46306) electron: Failed to load URL: http://127.0.0.1:14333/ with error: ERR_CONNECTION_REFUSED
(Use `RStudio --trace-warnings ...` to show where the warning was created)
(electron) 'webContents.clearHistory' is deprecated and will be removed. Please use 'webContents.navigationHistory.clear' instead.

When a session is open I get something like this:

Image

@b-rodrigues
Copy link
Contributor

You can ignore the warnings from the console, the issue here is what’s shown inside the RStudio session. It seems you also have homebrew on this machine, and that homebrew installed some version of ssl, which in turn is causing issues because RStudio (which was installed by Nix) tries to load it. This can unfortunately happen because at runtime, nix shells are not completely isolated from the rest of your machine. So there’s only two, quite radical options:

  • get rid of homebrew altogether and take the nix pill 100%
  • use another IDE that doesn’t need to load ssl at runtime

I’ll also ask in the R for nix matrix channel and see if we can improve the packaging of RStudio to perhaps ignore this kind of things. Maybe that would work

@b-rodrigues
Copy link
Contributor

btw, can you also share your default.nix here? so I can try to reproduce on my mac (which doesn’t have homebrew)

@b-rodrigues
Copy link
Contributor

We might be able to patch rstudio to ignore this kind of thing: to help us debug, could you run:

find / -name rsession 2>/dev/null

in a terminal? you should get something like:

/nix/store/kxjr50in6aaqwyv4jjdbch3361chp4r9-RStudio-2024.04.2+764/Applications/RStudio.app/Contents/Resources/app/bin/rsession

then run:

otool -L /nix/store/kxjr50in6aaqwyv4jjdbch3361chp4r9-RStudio-2024.04.2+764/Applications/RStudio.app/Contents/Resources/app/bin/rsession

and copy and paste the output here

@jgeller112
Copy link
Author

jgeller112 commented Mar 13, 2025

We might be able to patch rstudio to ignore this kind of thing: to help us debug, could you run:

find / -name rsession 2>/dev/null

in a terminal? you should get something like:

/nix/store/kxjr50in6aaqwyv4jjdbch3361chp4r9-RStudio-2024.04.2+764/Applications/RStudio.app/Contents/Resources/app/bin/rsession

then run:

otool -L /nix/store/kxjr50in6aaqwyv4jjdbch3361chp4r9-RStudio-2024.04.2+764/Applications/RStudio.app/Contents/Resources/app/bin/rsession

and copy and paste the output here

dyld[56365]: Library not loaded: /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib
Referenced from: <0E2A913E-7B96-3B62-A7BE-18A4CFAABB7E> /nix/store/1w7281cixl7vi8wyp6gmc1grmj1shw8d-RStudio-2024.04.2+764/Applications/RStudio.app/Contents/Resources/app/bin/rsession
Reason: tried: '/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib' (no such file), '/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib' (no such file), '/usr/local/lib/libssl.3.dylib' (no such file), '/usr/lib/libssl.3.dylib' (no such file, not in dyld cache)
zsh: abort
(base) jasongeller@Jasons-Mac-mini ~ %

@jgeller112
Copy link
Author

I have been using Positron on mac but would like this to work for rstudio.

@TomaSajt
Copy link

Could you tell us what nixpkgs revision you are using?
Also, how are you running the program?
(Are you using flakes? Are you using nix-darwin?)
Any kind of extra information would be appreciated.

It doesn't seem like the rstudio package came from the cache: did you have to build it yourself?

If yes, my main hypothesis is the following: you were trying to download rstudio when it wasn't cached yet (unrelated to rstudio), so it rebuilt it on your system. However, since the sandbox is not completely enabled on darwin, your local openssl installation might have leaked in into the build process.

@b-rodrigues
Copy link
Contributor

b-rodrigues commented Mar 13, 2025

it's this nixpkgs revision https://github.com/rstats-on-nix/nixpkgs/tree/2025-03-03

it's basically a fork of master at that day, looking at the commit history you'll find the nixos/nixpkgs revision it's based on. It's not flakes but a shell generated by rix.

How do you know rstudio wasn't downloaded from the cache.nixos.org ?

However, since the sandbox is not completely enabled on darwin

I wasn't aware of this, interesting

@jgeller112
Copy link
Author

Here is my default.nix file

# This file was generated by the {rix} R package v0.15.6 on 2025-03-12
# with following call:
# >rix(date = "2025-03-03",
#  > r_pkgs = required_packages,
#  > system_pkgs = c("quarto",
#  > "git",
#  > "pandoc",
#  > "cmdstan",
#  > "nix"),
#  > git_pkgs = list(list(package_name = "cmdstanr",
#  > repo_url = "https://github.com/stan-dev/cmdstanr",
#  > commit = "12211d4b35605d416d6e22078db81cfe9e5a64f5")),
#  > tex_pkgs = c("amsmath",
#  > "ninecolors",
#  > "apa7",
#  > "scalerel",
#  > "threeparttable",
#  > "threeparttablex",
#  > "endfloat",
#  > "environ",
#  > "multirow",
#  > "tcolorbox",
#  > "pdfcol",
#  > "tikzfill",
#  > "fontawesome5",
#  > "framed",
#  > "newtx",
#  > "fontaxes",
#  > "xstring",
#  > "wrapfig",
#  >      "tabularray",
#  > "siunitx",
#  > "fvextra",
#  > "geometry",
#  > "setspace",
#  > "fancyvrb",
#  > "anyfontsize"),
#  > ide = "rstudio",
#  > project_path = ".",
#  > overwrite = TRUE,
#  > r_ver = "4.4.3")
# It uses the `rstats-on-nix` fork of `nixpkgs` which provides improved
# compatibility with older R versions and R packages for Linux/WSL and
# Apple Silicon computers.
# Report any issues to https://github.com/ropensci/rix
let
 pkgs = import (fetchTarball "https://github.com/rstats-on-nix/nixpkgs/archive/2025-03-03.tar.gz") {};
 
  rpkgs = builtins.attrValues {
    inherit (pkgs.rPackages) 
      brms
      colorspace
      cowplot
      data_table
      easystats
      emmeans
      flextable
      ggdist
      ggeffects
      ggokabeito
      ggrepel
      ggtext
      here
      hypr
      knitr
      MetBrewer
      modelbased
      patchwork
      posterior
      ragg
      tidybayes
      tidylog
      tidyverse
      tinytable;
  };
 
    cmdstanr = (pkgs.rPackages.buildRPackage {
      name = "cmdstanr";
      src = pkgs.fetchgit {
        url = "https://github.com/stan-dev/cmdstanr";
        rev = "12211d4b35605d416d6e22078db81cfe9e5a64f5";
        sha256 = "sha256-/9YftAbbJCkDoV7M0nctRKpr5Y7ir63aJdCiDzG3KpI=";
      };
      propagatedBuildInputs = builtins.attrValues {
        inherit (pkgs.rPackages) 
          checkmate
          data_table
          jsonlite
          posterior
          processx
          R6
          withr
          rlang;
      };
    });
  
  tex = (pkgs.texlive.combine {
    inherit (pkgs.texlive) 
      scheme-small
      amsmath
      anyfontsize
      apa7
      endfloat
      environ
      fancyvrb
      fontawesome5
      fontaxes
      framed
      fvextra
      geometry
      multirow
      newtx
      ninecolors
      pdfcol
      scalerel
      setspace
      siunitx
      tabularray
      tcolorbox
      threeparttable
      threeparttablex
      tikzfill
      wrapfig
      xstring;
  });
  
  system_packages = builtins.attrValues {
    inherit (pkgs) 
      cmdstan
      git
      glibcLocales
      nix
      pandoc
      quarto
      R;
  };
 
  wrapped_pkgs = pkgs.rstudioWrapper.override {
    packages = [ cmdstanr rpkgs  ];
  };
 
  shell = pkgs.mkShell {
    LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else "";
    LANG = "en_US.UTF-8";
   LC_ALL = "en_US.UTF-8";
   LC_TIME = "en_US.UTF-8";
   LC_MONETARY = "en_US.UTF-8";
   LC_PAPER = "en_US.UTF-8";
   LC_MEASUREMENT = "en_US.UTF-8";

    buildInputs = [ cmdstanr rpkgs tex system_packages  wrapped_pkgs ];
    
  }; 
in
  {
    inherit pkgs shell;
  }




@TomaSajt
Copy link

TomaSajt commented Mar 13, 2025

I looked at the git history, and yes, this snapshot was taken between two electron changes. This way Hydra (the cache CI) never built it.
Unfortunate timing.

Should be solved by using a later revision, where rstudio is cached.

@TomaSajt
Copy link

TomaSajt commented Mar 13, 2025

AFAICT NixOS/nixpkgs#384339 will fix the issue permanently.

It was only fixed accidentally by upstream: they renamed CMakeGlobals.txt to cmake/globals.cmake.
This fixes it because nixpkgs's cmake tooling goes through all .cmake files and makes sure that no path beginning with /opt remains.

@b-rodrigues
Copy link
Contributor

@TomaSajt many thanks for your help !

@jgeller112 could you try with the 2025-03-10?

@jgeller112
Copy link
Author

Fixed! Thanks for your help!

@jgeller112
Copy link
Author

You can ignore the warnings from the console, the issue here is what’s shown inside the RStudio session. It seems you also have homebrew on this machine, and that homebrew installed some version of ssl, which in turn is causing issues because RStudio (which was installed by Nix) tries to load it. This can unfortunately happen because at runtime, nix shells are not completely isolated from the rest of your machine. So there’s only two, quite radical options:

  • get rid of homebrew altogether and take the nix pill 100%
  • use another IDE that doesn’t need to load ssl at runtime

I’ll also ask in the R for nix matrix channel and see if we can improve the packaging of RStudio to perhaps ignore this kind of things. Maybe that would work

I have removed homebrew but still getting the above errors. I am not sure what is going on. I was able to get rstudio running on another mac, but not my home macs.

@jgeller112
Copy link
Author

You can ignore the warnings from the console, the issue here is what’s shown inside the RStudio session. It seems you also have homebrew on this machine, and that homebrew installed some version of ssl, which in turn is causing issues because RStudio (which was installed by Nix) tries to load it. This can unfortunately happen because at runtime, nix shells are not completely isolated from the rest of your machine. So there’s only two, quite radical options:

  • get rid of homebrew altogether and take the nix pill 100%
  • use another IDE that doesn’t need to load ssl at runtime

I’ll also ask in the R for nix matrix channel and see if we can improve the packaging of RStudio to perhaps ignore this kind of things. Maybe that would work

I have removed homebrew but still getting the above errors. I am not sure what is going on. I was able to get rstudio running on another mac, but not my home macs.

I have reinstalled everything.

@b-rodrigues
Copy link
Contributor

did that other mac have hombrew ? did you use the latest available date (2025-03-10)? maybe remove the result file in the folder of your project, run nix-store --gc and build the environment with the latest date again

@TomaSajt
Copy link

My first guess would be that your rstudio build (which referenced the old location for openssl) is still locally cached by the nix store.

If you don't care about having to download some packages again, try garbage-collecting your store. Maybe that fixes it.

In any case, NixOS/nixpkgs#384339 is close to being merged. That should fix your problem in theory.

Would you be willing to try that branch out?

@jgeller112
Copy link
Author

did that other mac have hombrew ? did you use the latest available date (2025-03-10)? maybe remove the result file in the folder of your project, run nix-store --gc and build the environment with the latest date again

It did have homebrew. I try building it again.

@b-rodrigues
Copy link
Contributor

Would you be willing to try that branch out?

to try the branch, replace rstats-on-nix in your default.nix with TomaSajt and the date in the same url with rstudio, and you should be able to try out this fixed rstudio version! then, once it's merged you could go back to rstats-on-nix on nix with a date posterior to the merge

@jgeller112
Copy link
Author

Would you be willing to try that branch out?

to try the branch, replace rstats-on-nix in your default.nix with TomaSajt and the date in the same url with rstudio, and you should be able to try out this fixed rstudio version! then, once it's merged you could go back to rstats-on-nix on nix with a date posterior to the merge

@TomaSajt and @b-rodrigues that worked!

@b-rodrigues
Copy link
Contributor

That's great news!

@jgeller112
Copy link
Author

I'll hold off on sharing with collaborators until the merge is complete

@TomaSajt
Copy link

The PR is merged so I assume the latest snapshots will work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants