ropensci / rix

Reproducible development environments for R with Nix
https://docs.ropensci.org/rix/
GNU General Public License v3.0
136 stars 12 forks source link

Git repo failing when hashing via http://git2nixsha.dev #209

Closed eliocamp closed 1 week ago

eliocamp commented 3 months ago

I'm getting a 500 error for a github package.

library(rix)

metR <- list(package_name = "metR", 
             repo_url = "https://github.com/eliocamp/metR", 
             branch_name = "master", 
             commit = "1dd5d391d5da6a80fde03301671aea5582643914")

rix(r_ver = "4.3.2",
    git_pkgs = metR,
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)
#> Error: Request `curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://github.com/eliocamp/metR&branchName=master&commit=1dd5d391d5da6a80fde03301671aea5582643914')` failed:
#>  The requested URL returned error: 500
#> If it's a Github repo, check the url, branch name and commit.
#> Are these correct? If it's an archived CRAN package, check the name
#> of the package and the version number.

The information of repo, branch and commit sha is correct as far as I can tell: https://github.com/eliocamp/metR/commit/1dd5d391d5da6a80fde03301671aea5582643914

Other similar remotes seem to work correctly.

ggperiodic <- list(package_name = "ggperiodic", 
                   repo_url = "https://github.com/eliocamp/ggperiodic", 
                   branch_name = "master",
                   commit = "74f41571b0f82cf8a46e4f782a0dad148d09df29")
rix(r_ver = "4.3.2",
    git_pkgs = ggperiodic,
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)

This seems to be an issue on the git2nisha thing, though. For some reason it fails with the first repo.

curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://github.com/eliocamp/metR&branchName=master&commit=1dd5d391d5da6a80fde03301671aea5582643914')$status_code
#> [1] 500

Any commit seems to fail, too.

curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://github.com/eliocamp/metR&branchName=master&commit=ff01f509513706facef846887f17a506c0df3563')$status_code
#> [1] 500

Am I missing something in the specification of the remote?

b-rodrigues commented 2 weeks ago

you should generate an expression where ide="code" and then build it using nix-build . Then drop into the shell using nix-shell and run code from that shell . Code will see this R

Sent from Proton Mail Android

-------- Original Message -------- On 9/9/24 17:54, Matthieu Gousseff wrote:

It seems it worked ? Here is the end of the message :

post-installation fixup shrinking RPATHs of ELF executables and libraries in /nix/store/929fx96hhwpbqwcr75c4jwn73kgam79f-r-rix checking for references to /build/ in /nix/store/929fx96hhwpbqwcr75c4jwn73kgam79f-r-rix... patching script interpreter paths in /nix/store/929fx96hhwpbqwcr75c4jwn73kgam79f-r-rix rewriting symlink /nix/store/929fx96hhwpbqwcr75c4jwn73kgam79f-r-rix/nix-support/propagated-user-env-packages to be relative to /nix/store/929fx96hhwpbqwcr75c4jwn73kgam79f-r-rix

Now, what would be the safest next steps to try and buil a rix environment using VSCode (or RStudio if you feel it's more stable). Do you think I have to kill my rig R installation and go for a new R installation with the default directory I don't like so much ? Or can I try and launch VSCode with the R plugin and specify the R interpreter I want and launch rix from there ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

MGousseff commented 2 weeks ago

Well, I think I reached my limit for today :

The rix() returned the same error when I tried to install github packages : Error: Request `curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://github.com/rap4all/housing/&commit=1c860959310b80e67c41f7bbdc3e84cef00df18e')` failed: Failed to connect to git2nixsha.dev port 1506 after 2039 ms: No route to host If it's a Github repo, check the url and commit. Are these correct? If it's an archived CRAN package, check the name of the package and the version number.

Could it be that nix uses a port that my system administrators do not allow ? If so, how could I check this ?

In order to still try to have a small victory, I tried to generate a nix environment with only cran packages and to launch vscode from there. So I ran nix-build and nix-shell in the directory where my default.nix was created. It worked. From there I launched code. And then I had to set, in code, the path to the R interpreter that which R in nix shell returned (here it was /nix/store/fnl3bp7k0qw8cayqz2lciq8sq0xmib2c-R-4.4.1/bin/R). I checked the library janitor was already installed and library(janitor) returned no error.

So for now I'd say :

I'd be grateful if one of you could tell me how to check if the problem comes from my network permissions.

I'll stop for today, my brain is "stack overflowed" for today, thank you for your patience and will to help.

MGousseff commented 2 weeks ago

Here's the morning update. I worked from home today to test : it seems the problem with github packages comes from the way my university network is configured. From home, the packages seem to install. I then can run R in terminal mode inside the nix shell (after nix_build and nix-shell) and housing and fusen packages are installed. AT LAST A SMALL VICTORY. Thanks for your help and sorry that our restrictive network made you(us) lose time.

So I have to ask my sysadmins if they would allow the proper ports. Do you know why ports are different when downloading from CRAN and from github ? Is there a way to specify this in the rix function ? At least, I can create the nix environments from home and use them at work.

One thing not resolved, though, is that I have to add path to nix manually after each reboot. I guess there is a way to include a way to add it in some kind of profile, but I admit there are lots of ".bashrc", ".profile" and such things and I don't know where to specify it.

And last but not least, even though I created the nix.default with the ide="code" argument, when I launch VSCode and specify the Rterm path corresponding to the nix install, when I ctr+shift an instruction, it is sent to the R term with weird formatting characters. For instance ls() in my script is passed as 0~ls()1~. I launched VScode from the nix shell with code & Hav you ever encountered this behaviour ?

PS : the bold font is just to help separate issues, not a way to show any impatience, as I'm on the contrary grateful for the help.

philipp-baumann commented 2 weeks ago

Here's the morning update. I worked from home today to test : it seems the problem with github packages comes from the way my university network is configured. From home, the packages seem to install. I then can run R in terminal mode inside the nix shell (after nix_build and nix-shell) and housing and fusen packages are installed. AT LAST A SMALL VICTORY. Thanks for your help and sorry that our restrictive network made you(us) lose time.

Thanks for the update. I think those diagnostics help to strengthen debugging, although not all is directly related to {rix} but rather general nix tooling. It is however stuff that other users could experience. If we can make debugging smoother, e.g. also how @b-rodrigues has suggested add some diagnostics functions that summarize what we already adjust in {rix} to make it work in different contexts. Especially in mixed computer systems where users have R tooling and libraries and linked system dependences at host system and software cleanly managed at nix level in the Nix store.

Ideally you would achieve to adjust your setup at work so that you can also achieve to hash the github sources of R packages locally. I *think you should have nix-hash enabled in your nix setup. So it seems a matter of why and what shell environmental variable linked to nix is not available.

So I have to ask my sysadmins if they would allow the proper ports. Do you know why ports are different when downloading from CRAN and from github ? Is there a way to specify this in the rix function ? At least, I can create the nix environments from home and use them at work.

One thing not resolved, though, is that I have to add path to nix manually after each reboot. I guess there is a way to include a way to add it in some kind of profile, but I admit there are lots of ".bashrc", ".profile" and such things and I don't know where to specify it.

There is an easy way to do it. You can use your .bashrc or .profile in your $HOME dir. So you just need to add those lines. I don't know your IT settings and maybe the IT has some custom stuff doing with your linux instance, but when you open bash the one in your home should be sourced.

# add these lines in your $HOME/.bashrc or $HOME/.profile substituting your actual username
export PATH=$PATH:/home/<your-username>/.nix-profile/bin:/nix/var/nix/profiles/default/bin

And last but not least, even though I created the nix.default with the ide="code" argument, when I launch VSCode and specify the Rterm path corresponding to the nix install, when I ctr+shift an instruction, it is sent to the R term with weird formatting characters. For instance ls() in my script is passed as 0~ls()1~. I launched VScode from the nix shell with code & Hav you ever encountered this behaviour ?

If you use the R extension which i would recommend, then you need to enable bracketed paste.

https://francojc.github.io/posts/r-in-vscode/ There is a section with the lines to add here.

I think its a matter of preference, but i usually open vscode/vscodium first on my host and then just use nix-shell and then prompt R in a vscode bash terminal to send code to specific code in scripts to nix-R sessions. That works well. You can also manually add languageserver to r_pkgs and this does work as well if you default to ide = "rstudio" and somebody else wants to work in vscode etc.

PS : the bold font is just to help separate issues, not a way to show any impatience, as I'm on the contrary grateful for the help.

No offence taken.

MGousseff commented 2 weeks ago

Thank you. I added the path in my .profile ut added a line to check if it was already in and this didn't seem to work.

I will go back to my workplace and see what the error message is concerning git packages and see what blocks non cran packages and see if I can get a proxy set.

I still encounter small problems using VSCode. I'm not sure if it is just standard use of VSCode with R or a Rix problem, as it only appears after using rix(), and this would be a different issue. But for your curiosity, when I use rix() it seems to create an .Rprofile that seems to create a duplicate space in VSCode, which returns a warning : ``Keeping.Rprofilegenerated byrix::rix_init()`###

Cannot open the connectionwarning messages from top-level task callback 'vsc.workspace' Warning message: In file(con, "w") : cannot open file '/tmp/RtmpVIm7Xe/vscode-R/workspace.json': No such file or directory



But I will explore and ask on stock overflow in case I just wouldn't understand well how to use the R extension. 

About this issue, I will go back to my workplace as soon as possible and try to see with ma admins what proxy is needed to get rix() to work with remotes packages. 

Thank you for your help @philipp-baumann and @b-rodrigues 
b-rodrigues commented 2 weeks ago

I think you might be having the same issue than here https://github.com/b-rodrigues/rix/discussions/281

I will be changing the port serving the api after I'm back from holidays it should work then

philipp-baumann commented 2 weeks ago

Thank you. I added the path in my .profile ut added a line to check if it was already in and this didn't seem to work.

That is unusual. Have you also tried with .bashrc. To make the source happen, you either need to reopen a new bash terminal our do

source $HOME/.bashrc

Then check the updated path that should include the bin folder of the nix profile.

echo $PATH

I will go back to my workplace and see what the error message is concerning git packages and see what blocks non cran packages and see if I can get a proxy set.

I still encounter small problems using VSCode. I'm not sure if it is just standard use of VSCode with R or a Rix problem, as it only appears after using rix(), and this would be a different issue. But for your curiosity, when I use rix() it seems to create an .Rprofile that seems to create a duplicate space in VSCode, which returns a warning : ``Keeping.Rprofilegenerated byrix::rix_init()`###

That is how the function should behave, i.e. create this custom .Rprofile as a side-effect, to make sure the user library is excluded in the library path (what .libPaths() reports). The R built with nix will otherwise inherit R_LIBS_USER, which points to the default installation from the host system R, which is not at all what we want. This is an extra step needed to garantee pure set of nix R libraries from the nix store in the library path. Otherwise, in case you have the path specified in R_LIBS_USER, it would put those entries first in the library search path and you would end up with a polluted nix-R library setup, i.e. on macOS you would even get segmentation faults or sometimes on linux it would just use R packages from the system.

Cannot open the connectionwarning messages from top-level task callback 'vsc.workspace' Warning message: In file(con, "w") : cannot open file '/tmp/RtmpVIm7Xe/vscode-R/workspace.json': No such file or directory

The problem is that you are loading workspace.json from the /tmp subfolder. Why are you using a tmp folder and not a home subdir to host your vscode project?


But I will explore and ask on stock overflow in case I just wouldn't understand well how to use the R extension. 

About this issue, I will go back to my workplace as soon as possible and try to see with ma admins what proxy is needed to get rix() to work with remotes packages. 

Thank you for your help @philipp-baumann and @b-rodrigues 
philipp-baumann commented 2 weeks ago

I have been working with both vscode (packaged in nixpkgs and "natively" via package manager or binary install) and rstudio, Ubuntu, on WSL2 Ubuntu, macOS, it has all been running very smoothly.

@MGousseff there is no duplicate space created by the custom .Rprofile. If you call rix::rix(), it also calls rix_init(), which is a utility that constructs the .Rprofile. As you can see in the code that generates the file, and also the .Rprofile in your project_path dir. Codebase: https://github.com/b-rodrigues/rix/blob/5a95641f03bb9fc4941e7d420adcdcde754adfc2/R/rix_init.R#L394-L442 , which is effectively boilerplated and written here: https://github.com/b-rodrigues/rix/blob/5a95641f03bb9fc4941e7d420adcdcde754adfc2/R/rix_init.R#L138-L148

### File generated by `rix::rix_init()` ###
# 1. Currently, system RStudio does not inherit environmental variables
#   defined in `$HOME/.zshrc`, `$HOME/.bashrc` and alike. This is workaround to
#   make the path of the nix store and hence basic nix commands available
#   in an RStudio session
# 2. For nix-R session, remove `R_LIBS_USER`, system's R user library.`.
#   This guarantees no user libraries from the system are loaded and only
#   R packages in the Nix store are used. This makes Nix-R behave in pure manner
#   at run-time.
{
  is_rstudio <- Sys.getenv("RSTUDIO") == "1"
  is_nix_r <- nzchar(Sys.getenv("NIX_STORE"))
  if (isFALSE(is_nix_r) && isTRUE(is_rstudio)) {
    cat("{rix} detected RStudio R session")
    old_path <- Sys.getenv("PATH")
    nix_path <- "/nix/var/nix/profiles/default/bin"
    has_nix_path <- any(grepl(nix_path, old_path))
    if (isFALSE(has_nix_path)) {
      Sys.setenv(PATH = paste(old_path, nix_path, sep = ":"))
    }
    rm(old_path, nix_path)
  }
  if (isTRUE(is_nix_r)) {
    current_paths <- .libPaths()
    userlib_paths <- Sys.getenv("R_LIBS_USER")
    user_dir <- grep(paste(userlib_paths, collapse = "|"), current_paths, fixed = TRUE)
    new_paths <- current_paths[-user_dir]
    .libPaths(new_paths)
    rm(current_paths, userlib_paths, user_dir, new_paths)
  }
  rm(is_rstudio, is_nix_r)
}

options(dplyr.width = Inf)

So it does all what is explained in ?rix::rix_init.

Once cause of failure, because of your setup, that you do not have proper nix environment variables that are inherited from the shell set up, is that currently we only have adjustments in rstudio, that this is added according to the PATH in the custom .Rprofile.


/nix/var/nix/profiles/default/bin

So when not using rstudio, i see a hidden behavior that i have missed when programming the tweaks.

https://github.com/b-rodrigues/rix/blob/5a95641f03bb9fc4941e7d420adcdcde754adfc2/R/rix_init.R#L275-L295 set_message_session_PATH(), which also calls set_nix_path(), is also not effective when rprofile_action = "overwrite" or rprofile_action = "append". In your rare case, where nix profiles are not correctly in the shell env, this should be also called there, that your in-session PATH is adjusted to included the required nix path.

MGousseff commented 2 weeks ago

I think you might be having the same issue than here #281

I will be changing the port serving the api after I'm back from holidays it should work then

Thank you very much. I'm sorry you had all these notifications while on vacations. I'll wait for you to modify this before I reach to my sys admins, as it is not always very straightforward to add a proxy or modify port opening here (I don't blame them, attacks are very frequent).

MGousseff commented 2 weeks ago

In your rare case, where nix profiles are not correctly in the shell env, this should be also called there, that your in-session PATH is adjusted to included the required nix path.

I think I'm going to have a stroke :-) Seriously, thank you for explaining me all this. I am not very aware of how profils work. I went and searched for the .nix-profile in my home, and I found an interesting thing : the files exists but links to something that doesn't exist : "/nix/var/nix/profiles/per-user//profile". And this file doesn't exist. The only directory in /nix/var/nix/profiles/per-user/ is root, and it is empty. Is there something I can do to create this myusername nix profile file ?

philipp-baumann commented 2 weeks ago

/nix/var/nix/profiles/per-user/

In your rare case, where nix profiles are not correctly in the shell env, this should be also called there, that your in-session PATH is adjusted to included the required nix path.

I think I'm going to have a stroke :-) Seriously, thank you for explaining me all this. I am not very aware of how profils work. I went and searched for the .nix-profile in my home, and I found an interesting thing : the files exists but links to something that doesn't exist : "/nix/var/nix/profiles/per-user//profile". And this file doesn't exist. The only directory in /nix/var/nix/profiles/per-user/ is root, and it is empty. Is there something I can do to create this myusername nix profile file ?

I have exactly the same situation. only root in /nix/var/nix/profiles/per-user/profile, but it is not empty.

/nix/var/nix/profiles/per-user/root$ ll
total 16
drwxr-xr-x 2 root root 4096 Jun 10 10:47 ./
drwxr-xr-x 3 root root 4096 Jun 10 10:47 ../
lrwxrwxrwx 1 root root   14 Jun 10 10:47 profile -> profile-2-link/
lrwxrwxrwx 1 root root   60 Jun 10 10:47 profile-1-link -> /nix/store/9s6w0vyxcbvvw52bgc97vk2bl082xmhi-user-environment/
lrwxrwxrwx 1 root root   60 Jun 10 10:47 profile-2-link -> /nix/store/xr51aqblxflgkh84kvasbmzi1cfi6ih8-user-environment/

This seems a similar issue, and apparently newer nix versions link profiles in $HOME/.nix-profile. -> https://github.com/DeterminateSystems/nix-installer/issues/477 Just checked on my macOS at home, which was created by the Determinate Systems installer.

# on ubuntu it's also some `.../.local/...` folder
➜ ls -l $HOME/.nix-profile
lrwxr-xr-x  1 philipp  staff  48 Dec 16  2023 /Users/philipp/.nix-profile -> /Users/philipp/.local/state/nix/profiles/profile

This explains a bit more about profiles: https://nixos.wiki/wiki/User_Environment

ls -l /nix/var/nix/profiles/ 
total 4
lrwxrwxrwx 1 root root   43 Jun 10 10:47 default -> /nix/var/nix/profiles/per-user/root/profile
drwxr-xr-x 3 root root 4096 Jun 10 10:47 per-user

I'd also be interested to resolve which i consider your main problem, respectively, what might be improved to signal in {rix}.

Error in sys::exec_internal(cmd = cmd, args = args) : 
  Executing 'nix-hash' failed with status 1

Did the .bashrc PATH like suggested work? This would mean if you restart your host R (guess using the version managed by rig in /opt...,), you will have this in your PATH in the R (assuming rig does not do black magic with env vars when starting R; who knows).

# in bash terminal
echo $PATH

Somehow should include in the ":"-separated list: /nix/var/nix/profiles/default/bin

the same in the host rig R session

Sys.getenv("PATH")

Then there is a second hint i'd like to know:

It would be great if you can report the output of these commands in your work ubuntu rig R session

Sys.getenv("LD_LIBRARY_PATH")
Sys.getenv("NIX_STORE")

You seem to have anaconda installed, don't wanna draw premature conclusions but it can fuck envvars up as well.

To get the actual error message of nix-hash (not just the exit status 1 for unsuccessful, it would greatly help if you can report the output of this command you call in the project folder e.g., the current directory

nix-hash --type sha256 --sri .

This is what internal hashing (not via nixsha ...server API) should do with a local nix install you have. What rig does is actually another thing. Stuff like this doesn't convince me that it leaves important standard R mechanisms unchanged: https://github.com/r-lib/rig/issues/203

MGousseff commented 2 weeks ago

Hello, I changed the export PATH in my .profile rather than in my .bashrc and it seems to stick.

But I tried to follow the workaround of the issue you pointed to : https://github.com/DeterminateSystems/nix-installer/issues/477... And now my nix install is broken again. I try to reinstall things. I am afraid that so many tedious installation problems will not help the adoption of rix (and to make it clear, I get that it is a nix problem and not a rix problem).

About the nix-hash, it worked from my home network, so I think it's more a proxy thing.

philipp-baumann commented 2 weeks ago

Hello, I changed the export PATH in my .profile rather than in my .bashrc and it seems to stick.

But I tried to follow the workaround of the issue you pointed to : DeterminateSystems/nix-installer#477... And now my nix install is broken again. I try to reinstall things. I am afraid that so many tedious installation problems will not help the adoption of rix (and to make it clear, I get that it is a nix problem and not a rix problem).

About the nix-hash, it worked from my home network, so I think it's more a proxy thing.

Thanks for your patience. I assume you have systemd and control over you Ubuntu installation. I cannot tell if it is really a problem of the installer, or rather a permission issue. There is a fork of the Determinate Systems installer, called Lix, which is "Lix, like Nix", so all setup and the command line tools are equivalent. Its a fork, and it could be that there are some improvements: https://git.lix.systems/lix-project/lix-installer and https://lix.systems/install/

on my macOS laptop at home i have just updated from NixCpp to Lix, was really smooth.

sudo --preserve-env=PATH nix run \
     --experimental-features "nix-command flakes" \
     --extra-substituters https://cache.lix.systems --extra-trusted-public-keys "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" \
     'git+https://git.lix.systems/lix-project/lix?ref=refs/tags/2.91.0' -- \
     upgrade-nix \
     --extra-substituters https://cache.lix.systems --extra-trusted-public-keys "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o="

Have you tried uninstalling the determinate system installer via (see https://zero-to-nix.com/start/uninstall )

/nix/nix-installer uninstall

?

On top, you might also try uninstalling stuff like described in the docs. Probably, the determinate systems nix uninstaller does the same, but it might be worth doing below manually. Also, have you managed to remove your nix installed via apt completely.

https://nix.dev/manual/nix/2.18/installation/uninstall

# remove nix daemon service
sudo systemctl stop nix-daemon.service
sudo systemctl disable nix-daemon.socket nix-daemon.service
sudo systemctl daemon-reload
# remove files created by nix
sudo rm -rf /etc/nix /etc/profile.d/nix.sh /etc/tmpfiles.d/nix-daemon.conf /nix ~root/.nix-channels ~root/.nix-defexpr ~root/.nix-profile
# remove build users and their groups
for i in $(seq 1 32); do
  sudo userdel nixbld$i
done
sudo groupdel nixbld
MGousseff commented 2 weeks ago

I uninstalled NIX, and reinstalled it with lix. I'm testing it right now.

MGousseff commented 2 weeks ago

I uninstalled lix, reinstalled lix, and also ran the recommended instruction (although I did not understand what this was for)

Then open R in VS code, st the Rterm at the local install so to run the rix() function. It builds the nix. default but I still get, after any subsequent R instruction I send to the terminal :

Keeping `.Rprofile` generated by `rix::rix_init()`###
cannot open the connectionwarning messages from top-level task callback 'vsc.workspace'
Warning message:
In file(con, "w") :
  cannot open file '/tmp/RtmpdT7BnF/vscode-R/workspace.json': No such file or directory

I thought: well, I add complexity from using rix and using vscode, I'll try to build with ide="rstudio". And when I try to launch rstudio from the nix shell, I get :

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/xdg/xdg-ubuntu:/etc/xdg/rstudio/logging.conf'. Logging to '/home/gousseff/.local/share/rstudio/log/rdesktop.log'.
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
Could not initialize GLX
Aborted (core dumped)

Rstudio is installed on my computer and works ok aoutside of nix shell.

I reached my limit for now. I am convinced building reproducible environments to build and distribute packages with R is important, I am sure the nix/rix solution is useful for those for whom ti works, but I just can't spend more time trying to set it up as I am getting behind on my work. I will for a while just code with the up to date CRAN versions hoping my code will be OK, and I'l come back to all this later.

I think NIX should provide a .deb package to make it easy to install and uninstall in the ubuntu/debian community, I think a step-by-step tutorial could be useful (that is first in my general session I do this, then I quit, enter my nix-shell session and launch this and this and then I can run my R scripts into the nix R environment).

@philipp-baumann I hope I'll find some time later to try again. Sorry for the time we lost both without having the release to make it all work, it also must be frustrating for you.

philipp-baumann commented 1 week ago

I uninstalled lix, reinstalled lix, and also ran the recommended instruction (although I did not understand what this was for)

Then open R in VS code, st the Rterm at the local install so to run the rix() function. It builds the nix. default but I still get, after any subsequent R instruction I send to the terminal :

Keeping `.Rprofile` generated by `rix::rix_init()`###
cannot open the connectionwarning messages from top-level task callback 'vsc.workspace'
Warning message:
In file(con, "w") :
  cannot open file '/tmp/RtmpdT7BnF/vscode-R/workspace.json': No such file or directory

I thought: well, I add complexity from using rix and using vscode, I'll try to build with ide="rstudio". And when I try to launch rstudio from the nix shell, I get :

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/xdg/xdg-ubuntu:/etc/xdg/rstudio/logging.conf'. Logging to '/home/gousseff/.local/share/rstudio/log/rdesktop.log'.
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
Could not initialize GLX
Aborted (core dumped)

Rstudio is installed on my computer and works ok aoutside of nix shell.

I reached my limit for now. I am convinced building reproducible environments to build and distribute packages with R is important, I am sure the nix/rix solution is useful for those for whom ti works, but I just can't spend more time trying to set it up as I am getting behind on my work. I will for a while just code with the up to date CRAN versions hoping my code will be OK, and I'l come back to all this later.

I think NIX should provide a .deb package to make it easy to install and uninstall in the ubuntu/debian community, I think a step-by-step tutorial could be useful (that is first in my general session I do this, then I quit, enter my nix-shell session and launch this and this and then I can run my R scripts into the nix R environment).

@philipp-baumann I hope I'll find some time later to try again. Sorry for the time we lost both without having the release to make it all work, it also must be frustrating for you.

i get it no prob. I think it's really something peculiar in your setup. I have managed to get it working on Ubuntu on two systems, so i'm still positive. @b-rodrigues has also tested it on a latest Ubuntu container and all works smoothly there, too, i think. I would generally advise for diagnostics to start simple. Use a plain R session (not rig R, just the one in apt) in a bash terminal, then install newest rix and see if it works.

The other hints are envvars, which depending on the shell environment and IDE might not optimally be loaded for a smooth nix environment. My feeling is we have already done a lot there, there is small things to improve and a diagnostics helper is one of it. Issues like yours are not getting in the way, but are there to learn something. So in that spirit feel free to reiterate over this issue once you have time. We all sometimes want to make it work as simply as possibles and there are trade-offs with deliverables.

Cheers!

philipp-baumann commented 1 week ago

for a project now i for example use ide = "code", but i work with vscode and rstudio using the same setup.

library("rix")

rix_init()

r_pkgs <- c(
  "targets", "tarchetypes", "dplyr", "data.table", "dm", "DiagrammeR", "quarto",
  "R.utils", "here", "yaml", "readxl", "reactable", "writexl",
  # logging framework
  "lgr",
  # development tools
  "devtools", "styler", "lintr"
)

git_pkgs <- list(
  list(
    package_name = "rix",
    repo_url = "https://github.com/b-rodrigues/rix",
    commit = "c64ccaa34eb48ae4dcd78148ace211f72eebcb16"
  ),
  list(
    package_name = "fnmate",
    repo_url = "https://github.com/MilesMcBain/fnmate/",
    commit = "18a4c00536e0deafeb6b3f91e48b53b641f47e6a"
  ),
  list(
    package_name = "rscodeio",
    repo_url = "https://github.com/anthonynorth/rscodeio",
    commit = "88a1a373d64f0bd81b6730eb6fa005fd0baa9078"
  )
)

# Define expressions with software environment
rix::rix(
  r_ver = "9355fa86e6f27422963132c2c9aeedb0fb963d93", # "3c0be6ff38ccf079cb7976a571c5c865a19230a6",
  r_pkgs = r_pkgs,
  system_pkgs = c("git", "quarto"),
  git_pkgs = git_pkgs,
  ide = "rstudio",
  project_path = ".",
  overwrite = TRUE,
  shell_hook = "export QT_XCB_GL_INTEGRATION=none"
)
b-rodrigues commented 1 week ago

@MGousseff for rstudio you need to add

shell_hook = "export QT_XCB_GL_INTEGRATION=none"

in your rix call, as documented (scenario 1).

Too bad it's not working well for you, as @philipp-baumann mentioned I was able to get everything running on an Ubuntu vm and on my rpi5 running ubuntu as well. Really wonder what went wrong for you

MGousseff commented 1 week ago

My guess is that rig and nix don't go along too well, with symbolic links from rig messing with things ? I first discovered rig then tried rix. I may uninstall my rix R version and try from scratch.

b-rodrigues commented 1 week ago

I'll test this setup in a vm, thanks!

to be honest, the best way is to not have a system wide R version, and rely solely on project specific versions of R managed by Nix. But I know this is not really how most people like to work

philipp-baumann commented 1 week ago

I'll test this setup in a vm, thanks!

to be honest, the best way is to not have a system wide R version, and rely solely on project specific versions of R managed by Nix. But I know this is not really how most people like to work

Yeah have to admit me sometimes, too 😅 no reason for it. I think the critical phase is adoption. The transition needs to be frictionless, and i think we are good on track.

MGousseff commented 1 week ago

What ? But you need a system wide R version to create your nix environment with rix. Or you are in a infinite loop : you need nix to launch R to create the rix file which allows you to create the nix environment to launch R to... etc.

I'll try to uninstall rig and my versions of R, install the latest Rbase, install RIX and create a setup. But I need to find a couple of hours, and I'm behind on my job.

By the way, have you tried rix with positron ? The future replacement of Rstudio, or at least the new IDE provided by posit (Rstudio mother company) is in beta public version. It deals with R and python in a fork of VScode. I'm trying it (after the weird messages I get with rix in vscode). It feels not bad, even if debugging capabilites are still behind what I had with intellij (which I loved so much until the plugin broke and we realized only one man was on it and didn't answer anymore).

b-rodrigues commented 1 week ago

as described in the Readme, you can simply run a temporary shell to generate a default.nix by running

nix-shell --expr "$(curl -sl https://raw.githubusercontent.com/b-rodrigues/rix/master/inst/extdata/default.nix)" 

as for Positron: I've been trying to package it for NixOS 😁

MGousseff commented 1 week ago

So here is what I did

What doesn't work:

What works:

What SURPRISINGLY WORKS:

What I'd love: I don't get how positron finds the proper R path when ran from the nix-shell. I'd love a function in the R extension of codium who would do that, or maybe a launcher inside nix which would check nix-shell R path, and launch codium after setting the rpath in the settings parameter of codium. Sorry I'm unable to write such a thing.

Thank you both @b-rodrigues @philipp-baumann. I hope you don't feel this was a waste of time.

I'd like to write a quick summary of this and how to install and use nix/lix and rix, but I don't have any "blogging platform anymore". Maybe some people will find this issue helpful.

b-rodrigues commented 1 week ago

if I launch positron from the nix shell it finds the proper R interpreter.

Yes, this was my experience as well. FYI, this seems to be the case with many other editors, such as emacs and neovim.

In any case, glad it works for you now!

b-rodrigues commented 1 week ago

I think that we can now close this. @MGousseff should you have another problem, don't hesitate to open an issue!