Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
Merge branch 'master' into 71-with-nix

# Conflicts:
#	.Rbuildignore
  • Loading branch information
Philipp Baumann committed Sep 26, 2023
2 parents f7ac503 + dece234 commit 71462b9
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 177 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^rix\.Rproj$
^result$
^default.nix$
^doc$
^Meta$
18 changes: 16 additions & 2 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
name: nix-builder

jobs:
build:
name: nix builder
run-x86_64-linux:
name: nix builder for Ubuntu
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -18,3 +18,17 @@ jobs:
run: |
nix-build ./inst/extdata/default.nix
nix-shell ./inst/extdata/default.nix
run-x86_64-darwin:
name: nix builder for MacOS X86_64
# the DeterminateSystems action currently uses macos-12
# https://github.com/DeterminateSystems/nix-installer-action/blob/main/.github/workflows/ci.yml
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Run `nix-build ./inst/extdata/default.nix`
run: |
nix-build ./inst/extdata/default.nix
nix-shell ./inst/extdata/default.nix
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ default.nix
inst/doc
docs
result
/doc/
/Meta/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rix
Title: Rix: Reproducible Environments With Nix
Version: 0.3.1
Version: 0.4.0
Authors@R: c(
person("Bruno", "Rodrigues", , "bruno@brodrigues.co", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3211-3689")),
Expand Down
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->

# rix 0.4.0 (2023-09-26)

## Features

- `rix::rix()` now defaults to `"en_US.UTF-8"` for the relevant locale
variables (`LANG`, `LC_ALL`, `LC_TIME`, `LC_MONETARY`, `LC_PAPER`,
`LC_MEASUREMENT`) and sets these environment variables in
the Nix shell. These will be correctly propagated into the Nix R session.
Users can modify the locale setting via
`options(rix.nix_locale_variables = list(LANG = "de_CH.UTF-8", <...>)`, e.g.,
but it needs to be an UTF-8 locale. This is because we only import the
`glibcLocalesUtf8` subset, to not keep the size reasonable.

## Bug fixes

- fix locale warnings when starting R in linux, which uses glibc (closes
[#50](https://github.com/b-rodrigues/rix/issues/50)). Now, we use
`glibcLocalesUtf8` from Nix for "x86_64-linux".


# rix 0.3.1 (2023-09-11)

## Chore
Expand Down
31 changes: 31 additions & 0 deletions R/detect_os.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# WARNING - Generated by {fusen} from dev/get_os.Rmd: do not edit by hand

#' detect_os Detects the current OS
#' @return A character. One of Linux or Darwin (Windows is also Linux)
#'
#' @examples
#' detect_os()
#' @noRd
detect_os <- function(){
os <- Sys.info()["sysname"]
if(os == "Windows"){
"Linux"
} else {
os
}
}

#' generate_locale_archive Adds a line to the shellHook to avoid locale warnings
#' @return A character.
#'
#' @examples
#' generate_locale_archive("Linux")
#' @noRd
generate_locale_archive <- function(os){
os <- detect_os()
if (os == "Linux" || os == "Darwin") {
'LOCALE_ARCHIVE = if pkgs.system == \"x86_64-linux\" then \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\" else \"\";'
} else {
stop("Operating System unsupported")
}
}
72 changes: 54 additions & 18 deletions R/find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ fetchpkgs <- function(git_pkgs, archive_pkgs){
#' version 2.2.1 release, then use the Nix revision closest to that date, by setting
#' `r_ver = "3.1.0"`, which was the version of R current at the time. This
#' ensures that Nix builds a completely coherent environment.
#' By default, the nix shell will be configured with `"en_US.UTF-8"` for the
#' relevant locale variables (`LANG`, `LC_ALL`, `LC_TIME`, `LC_MONETARY`,
#' `LC_PAPER`, `LC_MEASUREMENT`). This is done to ensure locale
#' reproducibility by default in Nix environments created with `rix()`.
#' If there are good reasons to not stick to the default, you can set your
#' preferred locale variables via
#' `options(rix.nix_locale_variables = list(LANG = "de_CH.UTF-8", <...>)`
#' and the aforementioned locale variable names. However, you should use
#' UTF-8 locales since we import the `glibcLocalesUtf8` set only, to not
#' download the full set of locales and thereby keep the size reasonably
#' small.
#' @export
rix <- function(r_ver = "latest",
r_pkgs = NULL,
Expand Down Expand Up @@ -411,10 +422,9 @@ rPackages)

# Texlive packages
generate_tex_pkgs <- function(tex_pkgs) {

tex_pkgs <- paste(tex_pkgs, collapse = ' ')

if (!is.null(tex_pkgs)) {

tex_pkgs <- paste(tex_pkgs, collapse = ' ')

sprintf('tex = (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-small %s;
Expand Down Expand Up @@ -457,11 +467,39 @@ tex_pkgs)
# to add it.
generate_system_pkgs <- function(system_pkgs){
sprintf('system_packages = builtins.attrValues {
inherit (pkgs) R %s;
inherit (pkgs) R glibcLocalesUtf8 %s;
};
',
get_system_pkgs(system_pkgs))
}

generate_locale_variables <- function() {
locale_defaults <- list(
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"
)
locale_variables <- getOption(
"rix.nix_locale_variables",
default = locale_defaults
)
valid_vars <- all(names(locale_variables) %in% names(locale_defaults))
if (!isTRUE(valid_vars)) {
stop("`options(rix.nix_locale_variables = list())` ",
"only allows the following element names (locale variables):\n",
paste(names(locale_defaults), collapse = "; "),
call. = FALSE)
}
locale_vars <- paste(
Map(function(x, nm) paste0(nm, ' = ', '"', x, '"'),
nm = names(locale_variables), x = locale_variables),
collapse = ";\n "
)
paste0(locale_vars, ";\n")
}

generate_rstudio_pkgs <- function(ide, flag_git_archive, flag_rpkgs){
if(ide == "rstudio"){
Expand All @@ -477,26 +515,24 @@ flag_rpkgs
}
}

flag_rstudio <- if(ide == "rstudio"){
"rstudio_pkgs"
} else {
""
}
flag_rstudio <- if (ide == "rstudio") "rstudio_pkgs" else ""

shell_hook <- if(!is.null(shell_hook)){
paste0("shellHook = ''\n", shell_hook, "\n'';")
}
shell_hook <- if (!is.null(shell_hook)) {
paste0('shellHook = "', shell_hook, '";')
}

# Generate the shell
# we should add arguments to this function
# for example, give the option to have a shellhook etc
# for now, keep the shellhook R --vanilla
generate_shell <- function(flag_git_archive, flag_rpkgs){
generate_shell <- function(flag_git_archive,
flag_rpkgs){
sprintf('in
pkgs.mkShell {
%s
%s
buildInputs = [ %s %s %s system_packages %s ];
%s
}',
generate_locale_archive(detect_os()),
generate_locale_variables(),
flag_git_archive,
flag_rpkgs,
flag_tex_pkgs,
Expand Down Expand Up @@ -549,13 +585,13 @@ create_default_nix <- function(path = file.path("inst", "extdata",
rix(
r_ver = "latest",
r_pkgs = NULL,
system_pkgs = "nix",
system_pkgs = NULL,
git_pkgs = list(
list(
package_name = "rix",
repo_url = "https://github.com/b-rodrigues/rix",
branch_name = "master",
commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4"
commit = "b4501842723ef19391c7653e0b44a487505d89f2"
)
),
ide = "other",
Expand Down
Loading

0 comments on commit 71462b9

Please sign in to comment.