diff --git a/R/nix_hash.R b/R/nix_hash.R index bb7cadd4..dd55fd2a 100644 --- a/R/nix_hash.R +++ b/R/nix_hash.R @@ -91,6 +91,26 @@ nix_sri_hash <- function(path) { if (isFALSE(has_nix_shell)) { stop_no_nix_shell() } + + # not needed for Nix R sessions, workaround on Debian and Debian-based + # systems with nix installed + LD_LIBRARY_PATH_default <- Sys.getenv("LD_LIBRARY_PATH") + needs_ld_fix <- isFALSE(nzchar(Sys.getenv("NIX_STORE"))) && + nzchar(LD_LIBRARY_PATH_default) + + if (isTRUE(needs_ld_fix)) { + # On Debian and Debian-based systems, like Ubuntu 22.04, we found that a + # preset `LD_LIBRARY_PATH` environment variable in the system's R session + # leads to errors like + # nix-hash: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found (required by nix-hash) + # nix-hash: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/4z754a0vzl98asv0pa95i5d9szw5jqbs-lowdown-1.0.2-lib/lib/liblowdown.so.3) + # etc... + # for both `nix-hash`; it occurs via + # `sys::exec_internal`, `base::system()` or `base::system2()` from R. + # Therefore, we set it to `""` and set back the default (old) + # `LD_LIBRARY_PATH` when `with_nix()` exits. + fix_ld_library_path() + } cmd <- "nix-hash" args <- c("--type", "sha256", "--sri", path) @@ -104,6 +124,12 @@ nix_sri_hash <- function(path) { what = cmd, message_type = "quiet" ) + + if (isTRUE(needs_ld_fix)) { + # set old LD_LIBRARY_PATH (only if non-Nix R session, and if it wasn't + # `""`) + on.exit(Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default)) + } sri_hash <- sys::as_text(proc$stdout) return(sri_hash) diff --git a/R/rix.R b/R/rix.R index eb2ffc66..70139d30 100644 --- a/R/rix.R +++ b/R/rix.R @@ -201,26 +201,14 @@ for more details." project_path <- normalizePath(path = project_path) } - default.nix_path <- if (project_path == ".") { - "default.nix" - } else { - file.path(project_path, "default.nix") - } - - .Rprofile_path <- if (project_path == ".") { - ".Rprofile" - } else { - file.path(project_path, ".Rprofile") - } - + default.nix_path <- file.path(project_path, "default.nix") + .Rprofile_path <- file.path(project_path, ".Rprofile") + # Find url to use # In case of bleeding or frozen edge, the rstats-on-nix/nixpkgs # fork is used. Otherwise, upstream NixOS/nixpkgs nix_repo <- make_nixpkgs_url(r_ver) - default.nix_path <- file.path(default.nix_path) - .Rprofile_path <- file.path(.Rprofile_path) - rix_call <- match.call() # Get the two lists. One list is current CRAN packages @@ -293,6 +281,11 @@ for more details." } if (!file.exists(default.nix_path) || overwrite) { + + if (!dir.exists(project_path)) { + dir.create(project_path) + } + file.create(default.nix_path) writeLines(default.nix, default.nix_path) if (file.exists(.Rprofile_path)) { diff --git a/R/rix_init.R b/R/rix_init.R index c6bbfb45..bab32a1b 100644 --- a/R/rix_init.R +++ b/R/rix_init.R @@ -191,7 +191,7 @@ rix_init <- function(project_path = ".", if (message_type == "verbose") { cat("\n* Current lines of local `.Rprofile` are\n:") - cat(readLines(con = file(rprofile_file)), sep = "\n") + cat(readLines(con = rprofile_file), sep = "\n") } set_message_session_PATH(message_type = message_type) }