From b4501842723ef19391c7653e0b44a487505d89f2 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Wed, 20 Sep 2023 23:29:39 +0200 Subject: [PATCH 01/26] add Nix link in intro --- README.Rmd | 15 ++++++++------- README.md | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.Rmd b/README.Rmd index 52dad79b..e5f72f3a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -30,13 +30,14 @@ knitr::opts_chunk$set( `{rix}` is an R package that provides functions to help you setup reproducible and isolated development environments that contain R and all the required -packages that you need for your project. This is achieved by using the Nix -package manager that you must install separately. The Nix package manager is -extremely powerful: with it, it is possible to work on totally reproducible -development environments, and even install old releases of R and R packages. -With Nix, it is essentially possible to replace `{renv}` and Docker combined. If -you need other tools or languages like Python or Julia, this can also be done -easily. Nix is available for Linux, macOS and Windows (via WSL2). +packages that you need for your project. This is achieved by using the +[Nix package manager](https://nixos.org) that you must install separately. +The Nix package manager is extremely powerful: with it, it is possible to work +on totally reproducible development environments, and even install old releases +of R and R packages. With Nix, it is essentially possible to replace `{renv}` +and Docker combined. If you need other tools or languages like Python or Julia, +this can also be done easily. Nix is available for Linux, macOS and Windows +(via WSL2). ## From quickstart to deep dive diff --git a/README.md b/README.md index 6111fad8..f8c1b7f0 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,14 @@ rix](https://b-rodrigues.r-universe.dev/badges/rix?scale=1&color=pink&style=roun `{rix}` is an R package that provides functions to help you setup reproducible and isolated development environments that contain R and all the required packages that you need for your project. This is -achieved by using the Nix package manager that you must install -separately. The Nix package manager is extremely powerful: with it, it -is possible to work on totally reproducible development environments, -and even install old releases of R and R packages. With Nix, it is -essentially possible to replace `{renv}` and Docker combined. If you -need other tools or languages like Python or Julia, this can also be -done easily. Nix is available for Linux, macOS and Windows (via WSL2). +achieved by using the [Nix package manager](https://nixos.org) that you +must install separately. The Nix package manager is extremely powerful: +with it, it is possible to work on totally reproducible development +environments, and even install old releases of R and R packages. With +Nix, it is essentially possible to replace `{renv}` and Docker combined. +If you need other tools or languages like Python or Julia, this can also +be done easily. Nix is available for Linux, macOS and Windows (via +WSL2). ## From quickstart to deep dive From 0ef055a9625337b904ee1b777bb699c0ea6bdcf3 Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Thu, 21 Sep 2023 21:49:45 +0200 Subject: [PATCH 02/26] conflicts --- .Rbuildignore | 2 + .gitignore | 2 + README.Rmd | 165 ++++++++++++++++++++++++++++---------------- README.md | 184 ++++++++++++++++++++++++++++++++++---------------- 4 files changed, 236 insertions(+), 117 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 1b0a31f2..9f1d8fab 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,5 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^rix\.Rproj$ +^doc$ +^Meta$ diff --git a/.gitignore b/.gitignore index 0abfa7ce..238a3acc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ default.nix inst/doc docs result +/doc/ +/Meta/ diff --git a/README.Rmd b/README.Rmd index e5f72f3a..311b4789 100644 --- a/README.Rmd +++ b/README.Rmd @@ -28,49 +28,72 @@ knitr::opts_chunk$set( ## Introduction -`{rix}` is an R package that provides functions to help you setup reproducible -and isolated development environments that contain R and all the required -packages that you need for your project. This is achieved by using the -[Nix package manager](https://nixos.org) that you must install separately. -The Nix package manager is extremely powerful: with it, it is possible to work -on totally reproducible development environments, and even install old releases -of R and R packages. With Nix, it is essentially possible to replace `{renv}` -and Docker combined. If you need other tools or languages like Python or Julia, -this can also be done easily. Nix is available for Linux, macOS and Windows -(via WSL2). - -## From quickstart to deep dive - -If you are already familiar with nix and R, you can dive deep quickly. You can -for example check out -[series 4 on nix for data science on Bruno's blog](https://www.brodrigues.co/blog/2023-08-12-nix_for_r_part4/). -Or, in case you like video tutorials, watch -[this one on Reproducible R development environments with Nix](https://www.youtube.com/watch?v=c1LhgeTTxaI). - -First install Nix on your system: +`{rix}` is an R package that provides functions to help you write Nix +expressions: these expressions can then be used by the Nix package manager to +build completely reproducible development environments. These environments can +be used for interactive data analysis or running pipelines in a CI/CD +environment. Environments built with Nix contain R and all the required packages +that you need for your project: there are currently more than 80.000 pieces of +software available through the Nix package manager, including the entirety of +CRAN and Bioconductor packages. The Nix package manager is extremely powerful: +not only it handles all the dependencies of any package extremely well, it is +also possible with it to reproduce environments containing old releases of +software. It is thus possible to build environments that contain R version 4.0.0 +(for example) to run an old project originally developed on that version of R. + +With Nix, it is essentially possible to replace `{renv}` and Docker combined. If +you need other tools or languages like Python or Julia, this can also be done +easily. Nix is available for Linux, macOS and Windows (via WSL2). + +## Returning users + +*If you are not familiar with Nix or `{rix}` skip to the next section.* + +If you are already familiar with Nix and R, and simply want to get started as +quickly as possible, you can start by installing Nix using the installer from +[Determinate +Systems](https://determinate.systems/posts/determinate-nix-installer) a company +that provides services and tools built on Nix: ```{sh, eval=FALSE} curl --proto '=https' --tlsv1.2 -sSf \ -L https://install.determinate.systems/nix | \ sh -s -- install ``` -If you have R installed, you can start straight away from your R session. + +If you have R installed, you can start straight away from your R session by first +installing `{rix}`: ```{r, eval=FALSE} install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev", "https://cloud.r-project.org")) library("rix") +``` + +You can try that everything works well by trying to built the Nix expression +that ships with `{rix}`. Nix expressions are typically saved into files with the +name `default.nix`. This expression installs the latest version of R and `{rix}` +in a separate, reproducible environment: + +```{r, eval=FALSE} file.copy( + # default.nix is the file containing the Nix expression from = system.file("extdata", "default.nix", package = "rix"), to = ".", overwrite = TRUE ) + +# nix_build() is a wrapper around the command line tool `nix-build` nix_build(project_path = ".") ``` -This will build an environment with the latest version of R and `{rix}`. +If everything worked well, you should see a file called `result` next to +`default.nix`. You can now enter this newly built development environment by +starting opening a terminal in that folder and typing `nix-shell`. You should +be immediately dropped into an interactive R session. If you don't have R installed, but have the Nix package manager installed, you -can run a temporary R session with R using this command: +can run a temporary R session with R using this command (it will build the same +environment as the one above): ``` nix-shell --expr "$(curl -sl https://raw.githubusercontent.com/b-rodrigues/rix/master/inst/extdata/default.nix)" @@ -81,38 +104,39 @@ start using them. ## The Nix package manager -Nix is a piece of software that can be installed on your computer (regardless of +Nix is a package manager that can be installed on your computer (regardless of OS) and can be used to install software like with any other package manager. If you're familiar with the Ubuntu Linux distribution, you likely have used `apt-get` to install software. On macOS, you may have used `homebrew` for similar purposes. Nix functions in a similar way, but has many advantages over classic package managers. The main advantage of Nix, at least for our purposes, is that its repository of software is huge. As of writing, it contains more than -80'000 packages, and the entirety of CRAN is available through Nix's -repositories. This means that using Nix, it is possible to install not only R, -but also all the packages required for your project. The obvious question is why -use Nix instead of simply installing R and R packages as usual. The answer is -that Nix makes sure to install every dependency of any package, up to required -system libraries. For example, the `{xlsx}` package requires the Java -programming language to be installed on your computer to successfully install. -This can be difficult to achieve, and `{xlsx}` bullied many R developers -throughout the years (especially those using a Linux distribution, `sudo R CMD -javareconf` still plagues my nightmares). But with Nix, it suffices to declare -that we want the `{xlsx}` package for our project, and Nix figures out -automatically that Java is required and installs and configures it. It all just -happens without any required intervention from the user. The second advantage of -Nix is that it is possible to *pin* a certain *revision* for our project. -Pinning a revision ensures that every package that Nix installs will always be -at exactly the same versions, regardless of when in the future the packages get -installed. +80.000 packages, and the entirety of CRAN and Bioconductor is available through +Nix's repositories. This means that using Nix, it is possible to install not +only R, but also all the packages required for your project. The obvious +question is why use Nix instead of simply installing R and R packages as usual. +The answer is that Nix makes sure to install every dependency of any package, up +to required system libraries. For example, the `{xlsx}` package requires the +Java programming language to be installed on your computer to successfully +install. This can be difficult to achieve, and `{xlsx}` bullied many R +developers throughout the years (especially those using a Linux distribution, +`sudo R CMD javareconf` still plagues my nightmares). But with Nix, it suffices +to declare that we want the `{xlsx}` package for our project, and Nix figures +out automatically that Java is required and installs and configures it. It all +just happens without any required intervention from the user. The second +advantage of Nix is that it is possible to *pin* a certain *revision* of the Nix +packages' repository (called `nixpkgs`) for our project. Pinning a revision +ensures that every package that Nix installs will always be at exactly the same +versions, regardless of when in the future the packages get installed. ## Rix workflow The idea of `{rix}` is for you to declare the environment you need, using the -provided `rix()` function, which in turn generates the required file for Nix to -actually generate that environment. You can then use this environment to either -work interactively, or run R scripts. It is possible to have as many -environments as projects. Each environment is isolated (or not, it's up to you). +provided `rix()` function, which in turn writes the required expression in a +file for Nix to actually build that environment. You can then use this +environment to either work interactively, or run R scripts. It is possible to +have as many environments as projects. Each environment is isolated (or not, +it's up to you). The main function of `{rix}` is called `rix()`. `rix()` has several arguments: @@ -120,21 +144,26 @@ The main function of `{rix}` is called `rix()`. `rix()` has several arguments: - a list of R packages that your project needs - an optional list of additional software (for example, a Python interpreter, or Quarto) - an optional list with packages to install from Github +- an optional list of LaTeX packages - whether you want to use RStudio as an IDE for your project (or VS Code, or another environment) - a path to save a file called `default.nix`. For example: ```{r, eval = FALSE} -rix(r_ver = "latest", r_pkgs = c("dplyr", "chronicler"), ide = "rstudio") +rix(r_ver = "latest", + r_pkgs = c("dplyr", "chronicler"), + ide = "rstudio") ``` The call above writes a `default.nix` file in the current working directory. This `default.nix` can in turn be used by Nix to build an environment containing -RStudio, the latest version of R, and the latest versions of the -`{dplyr}` and `{chronicler}` packages. In the case of RStudio, it actually needs -to be installed for each environment. This is because RStudio changes some -default environment variables and a globally installed RStudio (the one you +RStudio, the latest version of R, and the latest versions of the `{dplyr}` and +`{chronicler}` packages. It should be noted that as of September 2023, RStudio +is not available for macOS through Nix so the expression generated by the call +above will not build successfully. It is also not possible to use RStudio +installed by other means with a Nix environment. This is because RStudio changes +some default environment variables and a globally installed RStudio (the one you install normally) would not recognize the R installed in the Nix environment. This is not the case for other IDEs such as VS code or Emacs. Another example: @@ -147,7 +176,7 @@ This call will generate a `default.nix` that installs R version 4.2.2, with the the `ide` argument was set to "code". This installs the required `{languageserver}` package as well, but unlike `ide = "rstudio"` does not install VS Code in that environment. Users should instead use the globally -installed VS Code. +installed VS Code by starting it from that environment. It's also possible to install specific versions of packages: @@ -163,6 +192,10 @@ specify software to install alongside R and R packages with `rix()`, read the vignette](https://b-rodrigues.github.io/rix/articles/building-reproducible-development-environments-with-rix.html) for more details. +For more details on how to use a Nix environment using an IDE interactively, +read the [Interactive +use](https://b-rodrigues.github.io/rix/articles/interactive-use.html) vignette. + ### default.nix The Nix package manager can be used to build reproducible development @@ -179,8 +212,12 @@ manager to build the environment. Call the following function in a terminal: nix-build ``` -Once Nix done building the environment, you can start working on it interactively -by using the following command: +`{rix}` also has a `nix_build()` helper function, so you can build environments +from an active R session if needed. + +Once Nix is done building the environment, you can start working on it +interactively by using the following command in a terminal emulator (not the R +console): ``` nix-shell @@ -215,7 +252,9 @@ cd /absolute/path/to/housing/ && nix-shell default.nix --run "Rscript -e 'target ``` It's possible to execute the pipeline automatically using a so-called "shell -hook". See the "Non-interactive use" vignette for more details. +hook". See the +[Reproducible analytical pipelines with Nix](https://b-rodrigues.github.io/rix/articles/reproducible-analytical-pipelines-with-nix.html) +vignette for more details. ## Installation @@ -227,9 +266,9 @@ You can install the development version of rix from remotes::install_github("b-rodrigues/rix") ``` -Or you can install it from the -[{rix} r-universe](https://b-rodrigues.r-universe.dev/rix), which serves you -from a CRAN-like R package repository: +Or you can install it from the [{rix} +r-universe](https://b-rodrigues.r-universe.dev/rix), which serves you from a +CRAN-like R package repository: ```r install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev", @@ -324,3 +363,15 @@ inflate the package using `fusen::inflate_all()`. If no errors are found [vignette](https://thinkr-open.github.io/fusen/articles/How-to-use-fusen.html). In our development workflow, we use [semantic versioning](https://semver.org) via [{fledge}](https://fledge.cynkra.com). + +## Recommended reading + +- [Nix for R series from Bruno's blog](https://www.brodrigues.co/). Or, in case you like video tutorials, watch [this one on Reproducible R development environments with Nix](https://www.youtube.com/watch?v=c1LhgeTTxaI) +- [nix.dev tutorials](https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs#pinning-nixpkgs) +- [INRIA's Nix tutorial](https://nix-tutorial.gitlabpages.inria.fr/nix-tutorial/installation.html) +- [Nix pills](https://nixos.org/guides/nix-pills/) +- [Nix for Data Science](https://github.com/nix-community/nix-data-science) +- [NixOS explained](https://christitus.com/nixos-explained/): NixOS is an entire Linux distribution that uses Nix as its package manager. +- [Blog post: Nix with R and devtools](https://rgoswami.me/posts/nix-r-devtools/) +- [Blog post: Statistical Rethinking and Nix](https://rgoswami.me/posts/rethinking-r-nix/) +- [Blog post: Searching and installing old versions of Nix packages](https://lazamar.github.io/download-specific-package-version-with-nix/) diff --git a/README.md b/README.md index f8c1b7f0..a20c4adc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ - [Rix: Reproducible Environments with Nix](#rix-reproducible-environments-with-nix) - [Introduction](#introduction) - - [From quickstart to deep dive](#from-quickstart-to-deep-dive) + - [Returning users](#returning-users) - [The Nix package manager](#the-nix-package-manager) - [Rix workflow](#rix-workflow) - [default.nix](#defaultnix) @@ -15,6 +15,7 @@ installer](#installing-nix-using-the-determinate-systems-installer) - [Docker](#docker) - [Contributing](#contributing) + - [Recommended reading](#recommended-reading) @@ -32,29 +33,35 @@ rix](https://b-rodrigues.r-universe.dev/badges/rix?scale=1&color=pink&style=roun ## Introduction -`{rix}` is an R package that provides functions to help you setup -reproducible and isolated development environments that contain R and -all the required packages that you need for your project. This is -achieved by using the [Nix package manager](https://nixos.org) that you -must install separately. The Nix package manager is extremely powerful: -with it, it is possible to work on totally reproducible development -environments, and even install old releases of R and R packages. With -Nix, it is essentially possible to replace `{renv}` and Docker combined. -If you need other tools or languages like Python or Julia, this can also -be done easily. Nix is available for Linux, macOS and Windows (via -WSL2). - -## From quickstart to deep dive - -If you are already familiar with nix and R, you can dive deep quickly. -You can for example check out [series 4 on nix for data science on -Bruno’s -blog](https://www.brodrigues.co/blog/2023-08-12-nix_for_r_part4/). Or, -in case you like video tutorials, watch [this one on Reproducible R -development environments with -Nix](https://www.youtube.com/watch?v=c1LhgeTTxaI). - -First install Nix on your system: +`{rix}` is an R package that provides functions to help you write Nix +expressions: these expressions can then be used by the Nix package +manager to build completely reproducible development environments. These +environments can be used for interactive data analysis or running +pipelines in a CI/CD environment. Environments built with Nix contain R +and all the required packages that you need for your project: there are +currently more than 80.000 pieces of software available through the Nix +package manager, including the entirety of CRAN and Bioconductor +packages. The Nix package manager is extremely powerful: not only it +handles all the dependencies of any package extremely well, it is also +possible with it to reproduce environments containing old releases of +software. It is thus possible to build environments that contain R +version 4.0.0 (for example) to run an old project originally developed +on that version of R. + +With Nix, it is essentially possible to replace `{renv}` and Docker +combined. If you need other tools or languages like Python or Julia, +this can also be done easily. Nix is available for Linux, macOS and +Windows (via WSL2). + +## Returning users + +*If you are not familiar with Nix or `{rix}` skip to the next section.* + +If you are already familiar with Nix and R, and simply want to get +started as quickly as possible, you can start by installing Nix using +the installer from [Determinate +Systems](https://determinate.systems/posts/determinate-nix-installer) a +company that provides services and tools built on Nix: ``` sh curl --proto '=https' --tlsv1.2 -sSf \ @@ -62,24 +69,40 @@ curl --proto '=https' --tlsv1.2 -sSf \ sh -s -- install ``` -If you have R installed, you can start straight away from your R -session. +If you have R installed, you can start straight away from your R session +by first installing `{rix}`: ``` r install.packages("rix", repos = c("https://b-rodrigues.r-universe.dev", "https://cloud.r-project.org")) library("rix") +``` + +You can try that everything works well by trying to built the Nix +expression that ships with `{rix}`. Nix expressions are typically saved +into files with the name `default.nix`. This expression installs the +latest version of R and `{rix}` in a separate, reproducible environment: + +``` r file.copy( + # default.nix is the file containing the Nix expression from = system.file("extdata", "default.nix", package = "rix"), to = ".", overwrite = TRUE ) + +# nix_build() is a wrapper around the command line tool `nix-build` nix_build(project_path = ".") ``` -This will build an environment with the latest version of R and `{rix}`. +If everything worked well, you should see a file called `result` next to +`default.nix`. You can now enter this newly built development +environment by starting opening a terminal in that folder and typing +`nix-shell`. You should be immediately dropped into an interactive R +session. If you don’t have R installed, but have the Nix package manager -installed, you can run a temporary R session with R using this command: +installed, you can run a temporary R session with R using this command +(it will build the same environment as the one above): nix-shell --expr "$(curl -sl https://raw.githubusercontent.com/b-rodrigues/rix/master/inst/extdata/default.nix)" @@ -88,7 +111,7 @@ and start using them. ## The Nix package manager -Nix is a piece of software that can be installed on your computer +Nix is a package manager that can be installed on your computer (regardless of OS) and can be used to install software like with any other package manager. If you’re familiar with the Ubuntu Linux distribution, you likely have used `apt-get` to install software. On @@ -96,30 +119,31 @@ macOS, you may have used `homebrew` for similar purposes. Nix functions in a similar way, but has many advantages over classic package managers. The main advantage of Nix, at least for our purposes, is that its repository of software is huge. As of writing, it contains more than -80’000 packages, and the entirety of CRAN is available through Nix’s -repositories. This means that using Nix, it is possible to install not -only R, but also all the packages required for your project. The obvious -question is why use Nix instead of simply installing R and R packages as -usual. The answer is that Nix makes sure to install every dependency of -any package, up to required system libraries. For example, the `{xlsx}` -package requires the Java programming language to be installed on your -computer to successfully install. This can be difficult to achieve, and -`{xlsx}` bullied many R developers throughout the years (especially -those using a Linux distribution, `sudo R CMD javareconf` still plagues -my nightmares). But with Nix, it suffices to declare that we want the -`{xlsx}` package for our project, and Nix figures out automatically that -Java is required and installs and configures it. It all just happens -without any required intervention from the user. The second advantage of -Nix is that it is possible to *pin* a certain *revision* for our -project. Pinning a revision ensures that every package that Nix installs -will always be at exactly the same versions, regardless of when in the -future the packages get installed. +80.000 packages, and the entirety of CRAN and Bioconductor is available +through Nix’s repositories. This means that using Nix, it is possible to +install not only R, but also all the packages required for your project. +The obvious question is why use Nix instead of simply installing R and R +packages as usual. The answer is that Nix makes sure to install every +dependency of any package, up to required system libraries. For example, +the `{xlsx}` package requires the Java programming language to be +installed on your computer to successfully install. This can be +difficult to achieve, and `{xlsx}` bullied many R developers throughout +the years (especially those using a Linux distribution, +`sudo R CMD javareconf` still plagues my nightmares). But with Nix, it +suffices to declare that we want the `{xlsx}` package for our project, +and Nix figures out automatically that Java is required and installs and +configures it. It all just happens without any required intervention +from the user. The second advantage of Nix is that it is possible to +*pin* a certain *revision* of the Nix packages’ repository (called +`nixpkgs`) for our project. Pinning a revision ensures that every +package that Nix installs will always be at exactly the same versions, +regardless of when in the future the packages get installed. ## Rix workflow The idea of `{rix}` is for you to declare the environment you need, -using the provided `rix()` function, which in turn generates the -required file for Nix to actually generate that environment. You can +using the provided `rix()` function, which in turn writes the required +expression in a file for Nix to actually build that environment. You can then use this environment to either work interactively, or run R scripts. It is possible to have as many environments as projects. Each environment is isolated (or not, it’s up to you). @@ -132,6 +156,7 @@ arguments: - an optional list of additional software (for example, a Python interpreter, or Quarto) - an optional list with packages to install from Github +- an optional list of LaTeX packages - whether you want to use RStudio as an IDE for your project (or VS Code, or another environment) - a path to save a file called `default.nix`. @@ -139,18 +164,23 @@ arguments: For example: ``` r -rix(r_ver = "latest", r_pkgs = c("dplyr", "chronicler"), ide = "rstudio") +rix(r_ver = "latest", + r_pkgs = c("dplyr", "chronicler"), + ide = "rstudio") ``` The call above writes a `default.nix` file in the current working directory. This `default.nix` can in turn be used by Nix to build an environment containing RStudio, the latest version of R, and the latest -versions of the `{dplyr}` and `{chronicler}` packages. In the case of -RStudio, it actually needs to be installed for each environment. This is -because RStudio changes some default environment variables and a -globally installed RStudio (the one you install normally) would not -recognize the R installed in the Nix environment. This is not the case -for other IDEs such as VS code or Emacs. Another example: +versions of the `{dplyr}` and `{chronicler}` packages. It should be +noted that as of September 2023, RStudio is not available for macOS +through Nix so the expression generated by the call above will not build +successfully. It is also not possible to use RStudio installed by other +means with a Nix environment. This is because RStudio changes some +default environment variables and a globally installed RStudio (the one +you install normally) would not recognize the R installed in the Nix +environment. This is not the case for other IDEs such as VS code or +Emacs. Another example: ``` r rix(r_ver = "4.2.2", r_pkgs = c("dplyr", "chronicler"), ide = "code") @@ -161,7 +191,8 @@ with the `{dplyr}` and `{chronicler}` packages. Because the user wishes to use VS Code, the `ide` argument was set to “code”. This installs the required `{languageserver}` package as well, but unlike `ide = "rstudio"` does not install VS Code in that environment. Users -should instead use the globally installed VS Code. +should instead use the globally installed VS Code by starting it from +that environment. It’s also possible to install specific versions of packages: @@ -178,6 +209,11 @@ environments with rix vignette](https://b-rodrigues.github.io/rix/articles/building-reproducible-development-environments-with-rix.html) for more details. +For more details on how to use a Nix environment using an IDE +interactively, read the [Interactive +use](https://b-rodrigues.github.io/rix/articles/interactive-use.html) +vignette. + ### default.nix The Nix package manager can be used to build reproducible development @@ -193,8 +229,12 @@ Call the following function in a terminal: nix-build -Once Nix done building the environment, you can start working on it -interactively by using the following command: +`{rix}` also has a `nix_build()` helper function, so you can build +environments from an active R session if needed. + +Once Nix is done building the environment, you can start working on it +interactively by using the following command in a terminal emulator (not +the R console): nix-shell @@ -223,7 +263,9 @@ by running: cd /absolute/path/to/housing/ && nix-shell default.nix --run "Rscript -e 'targets::tar_make()'" It’s possible to execute the pipeline automatically using a so-called -“shell hook”. See the “Non-interactive use” vignette for more details. +“shell hook”. See the [Reproducible analytical pipelines with +Nix](https://b-rodrigues.github.io/rix/articles/reproducible-analytical-pipelines-with-nix.html) +vignette for more details. ## Installation @@ -331,3 +373,25 @@ how to use `{fusen}` (don’t worry, it’s super easy), refer to this In our development workflow, we use [semantic versioning](https://semver.org) via [{fledge}](https://fledge.cynkra.com). + +## Recommended reading + +- [Nix for R series from Bruno’s blog](https://www.brodrigues.co/). Or, + in case you like video tutorials, watch [this one on Reproducible R + development environments with + Nix](https://www.youtube.com/watch?v=c1LhgeTTxaI) +- [nix.dev + tutorials](https://nix.dev/tutorials/first-steps/towards-reproducibility-pinning-nixpkgs#pinning-nixpkgs) +- [INRIA’s Nix + tutorial](https://nix-tutorial.gitlabpages.inria.fr/nix-tutorial/installation.html) +- [Nix pills](https://nixos.org/guides/nix-pills/) +- [Nix for Data + Science](https://github.com/nix-community/nix-data-science) +- [NixOS explained](https://christitus.com/nixos-explained/): NixOS is + an entire Linux distribution that uses Nix as its package manager. +- [Blog post: Nix with R and + devtools](https://rgoswami.me/posts/nix-r-devtools/) +- [Blog post: Statistical Rethinking and + Nix](https://rgoswami.me/posts/rethinking-r-nix/) +- [Blog post: Searching and installing old versions of Nix + packages](https://lazamar.github.io/download-specific-package-version-with-nix/) From 9390e28e6495f8167f782a17c529949d50c0948c Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Thu, 21 Sep 2023 22:19:45 +0200 Subject: [PATCH 03/26] detect_os --- R/detect_os.R | 32 ++++++++++++++++++++++++++ R/find_rev.R | 8 +++---- dev/0-dev_history.Rmd | 6 +++++ dev/build_envs.Rmd | 8 +++---- dev/config_fusen.yaml | 39 +++++++++++++++++++++----------- dev/get_os.Rmd | 52 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 R/detect_os.R create mode 100644 dev/get_os.Rmd diff --git a/R/detect_os.R b/R/detect_os.R new file mode 100644 index 00000000..36567c8d --- /dev/null +++ b/R/detect_os.R @@ -0,0 +1,32 @@ +# 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){ + if(detect_os() == "Linux"){ + 'LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";' + } else if(detect_os() == "Darwin") { + '' + } else { + stop("Operating System unsupported") + } +} diff --git a/R/find_rev.R b/R/find_rev.R index fb4f39d9..ed714294 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -488,15 +488,15 @@ flag_rpkgs } # 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 buildInputs = [ %s %s %s system_packages %s ]; %s }', + generate_locale_archive(detect_os()), flag_git_archive, flag_rpkgs, flag_tex_pkgs, diff --git a/dev/0-dev_history.Rmd b/dev/0-dev_history.Rmd index 661d3052..4c9017e8 100755 --- a/dev/0-dev_history.Rmd +++ b/dev/0-dev_history.Rmd @@ -104,6 +104,12 @@ fusen::inflate(flat_file = "dev/zzz.Rmd", overwrite = TRUE) ``` +```{r} +fusen::inflate(flat_file = "dev/get_os.Rmd", + vignette_name = NA, + overwrite = TRUE) +``` + # Vignettes for users ```{r} diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 34ec8dd2..ffdb2bba 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -572,15 +572,15 @@ flag_rpkgs } # 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 buildInputs = [ %s %s %s system_packages %s ]; %s }', + generate_locale_archive(detect_os()), flag_git_archive, flag_rpkgs, flag_tex_pkgs, diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index 7b224e25..19f3c608 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -50,6 +50,19 @@ data_doc.Rmd: check: true document: true overwrite: 'yes' +get_os.Rmd: + path: dev/get_os.Rmd + state: active + R: R/detect_os.R + tests: [] + vignettes: [] + inflate: + flat_file: dev/get_os.Rmd + vignette_name: .na + open_vignette: true + check: true + document: true + overwrite: 'yes' interactive_use.Rmd: path: dev/interactive_use.Rmd state: active @@ -63,6 +76,19 @@ interactive_use.Rmd: check: true document: true overwrite: 'yes' +literate_programming.Rmd: + path: dev/literate_programming.Rmd + state: active + R: [] + tests: [] + vignettes: vignettes/building-an-environment-for-literate-programming.Rmd + inflate: + flat_file: dev/literate_programming.Rmd + vignette_name: Building an environment for literate programming + open_vignette: true + check: true + document: true + overwrite: 'yes' pkgs_with_remotes.Rmd: path: dev/pkgs_with_remotes.Rmd state: active @@ -102,19 +128,6 @@ save_r_nix_revs.Rmd: check: true document: true overwrite: 'yes' -literate_programming.Rmd: - path: dev/literate_programming.Rmd - state: active - R: [] - tests: [] - vignettes: vignettes/building-an-environment-for-literate-programming.Rmd - inflate: - flat_file: dev/literate_programming.Rmd - vignette_name: Building an environment for literate programming - open_vignette: true - check: true - document: true - overwrite: 'yes' zzz.Rmd: path: dev/zzz.Rmd state: active diff --git a/dev/get_os.Rmd b/dev/get_os.Rmd new file mode 100644 index 00000000..6c33a621 --- /dev/null +++ b/dev/get_os.Rmd @@ -0,0 +1,52 @@ +--- +title: "OS detection" +output: html_document +editor_options: + chunk_output_type: console +--- + +```{r development, include=FALSE} +library(testthat) +``` + +```{r development-load} +# Load already included functions if relevant +pkgload::load_all(export_all = FALSE) +``` + +This function detects the operating system: + +```{r function-detect_os} +#' detect_os Detects the current OS +#' @return A character. One of Linux or Darwin (Windows is also Linux) +#' +#' @examples +#' detect_os() +detect_os <- function(){ + os <- Sys.info()["sysname"] + if(os == "Windows"){ + "Linux" + } else { + os + } +} +``` + +This function adds deals with locale on Linux (and WSL2): + +```{r function-generate_locale_archive} +#' generate_locale_archive Adds a line to the shellHook to avoid locale warnings +#' @return A character. +#' +#' @examples +#' generate_locale_archive("Linux") +generate_locale_archive <- function(os){ + if(detect_os() == "Linux"){ + 'LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";' + } else if(detect_os() == "Darwin") { + '' + } else { + stop("Operating System unsupported") + } +} +``` From de1e1cf86f95c66c2eb2d9ad445b4b0ac3e569c4 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Fri, 22 Sep 2023 21:16:07 +0200 Subject: [PATCH 04/26] prepare for v0.3.2 (patch) --- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- inst/extdata/default.nix | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index ed714294..fcfe7425 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -555,7 +555,7 @@ create_default_nix <- function(path = file.path("inst", "extdata", package_name = "rix", repo_url = "https://github.com/b-rodrigues/rix", branch_name = "master", - commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4" + commit = "9390e28e6495f8167f782a17c529949d50c0948c" ) ), ide = "other", diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index ffdb2bba..499eddc9 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -643,7 +643,7 @@ create_default_nix <- function(path = file.path("inst", "extdata", package_name = "rix", repo_url = "https://github.com/b-rodrigues/rix", branch_name = "master", - commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4" + commit = "9390e28e6495f8167f782a17c529949d50c0948c" ) ), ide = "other", diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index ef9ee7cb..19ae64c8 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,41 +1,42 @@ -# This file was generated by the {rix} R package v0.2.1.9002 on 2023-09-10 +# This file was generated by the {rix} R package v0.3.1 on 2023-09-22 # with following call: -# >rix(r_ver = "78058d810644f5ed276804ce7ea9e82d92bee293", +# >rix(r_ver = "fe977679240ac2027b151ecca1bc6ce808c2e8af", # > r_pkgs = NULL, # > system_pkgs = "nix", # > git_pkgs = list(list(package_name = "rix", # > repo_url = "https://github.com/b-rodrigues/rix", # > branch_name = "master", -# > commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4")), +# > commit = "9390e28e6495f8167f782a17c529949d50c0948c")), # > ide = "other", # > project_path = dirname(path), # > overwrite = TRUE, # > shell_hook = "R --vanilla") -# It uses nixpkgs' revision 78058d810644f5ed276804ce7ea9e82d92bee293 for reproducibility purposes +# It uses nixpkgs' revision fe977679240ac2027b151ecca1bc6ce808c2e8af for reproducibility purposes # which will install R version latest # Report any issues to https://github.com/b-rodrigues/rix let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/78058d810644f5ed276804ce7ea9e82d92bee293.tar.gz") {}; + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/fe977679240ac2027b151ecca1bc6ce808c2e8af.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { url = "https://github.com/b-rodrigues/rix"; branchName = "master"; - rev = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4"; - sha256 = "sha256-qi8FXCsKIuoHoERE6ZhTooHH9f94cRIi6mrUVbQU8NY="; + rev = "9390e28e6495f8167f782a17c529949d50c0948c"; + sha256 = "sha256-Ra9pAi0VkDxLmNSLKql5M350BwWjEWi51ktBjdXH4/Q="; }; propagatedBuildInputs = builtins.attrValues { inherit (pkgs.rPackages) httr jsonlite sys; }; }) ]; tex = (pkgs.texlive.combine { - inherit (pkgs.texlive) scheme-basic ; + inherit (pkgs.texlive) scheme-small ; }); system_packages = builtins.attrValues { inherit (pkgs) R nix; }; in pkgs.mkShell { + LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = '' R --vanilla From 453f8914e5b8586fb617a9926954cc3ad2005429 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Fri, 22 Sep 2023 21:32:25 +0200 Subject: [PATCH 05/26] go back to last working (`nix-build`) commit --- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- inst/extdata/default.nix | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index fcfe7425..27ec8de1 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -555,7 +555,7 @@ create_default_nix <- function(path = file.path("inst", "extdata", package_name = "rix", repo_url = "https://github.com/b-rodrigues/rix", branch_name = "master", - commit = "9390e28e6495f8167f782a17c529949d50c0948c" + commit = "b4501842723ef19391c7653e0b44a487505d89f2" ) ), ide = "other", diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 499eddc9..96ae481a 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -643,7 +643,7 @@ create_default_nix <- function(path = file.path("inst", "extdata", package_name = "rix", repo_url = "https://github.com/b-rodrigues/rix", branch_name = "master", - commit = "9390e28e6495f8167f782a17c529949d50c0948c" + commit = "b4501842723ef19391c7653e0b44a487505d89f2" ) ), ide = "other", diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 19ae64c8..c1ff6634 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -6,7 +6,7 @@ # > git_pkgs = list(list(package_name = "rix", # > repo_url = "https://github.com/b-rodrigues/rix", # > branch_name = "master", -# > commit = "9390e28e6495f8167f782a17c529949d50c0948c")), +# > commit = "b4501842723ef19391c7653e0b44a487505d89f2")), # > ide = "other", # > project_path = dirname(path), # > overwrite = TRUE, @@ -21,8 +21,8 @@ let src = pkgs.fetchgit { url = "https://github.com/b-rodrigues/rix"; branchName = "master"; - rev = "9390e28e6495f8167f782a17c529949d50c0948c"; - sha256 = "sha256-Ra9pAi0VkDxLmNSLKql5M350BwWjEWi51ktBjdXH4/Q="; + rev = "b4501842723ef19391c7653e0b44a487505d89f2"; + sha256 = "sha256-pQdRKxzNhDPPWW1T9oaQEtkLTdmU0+Ry0aGzEGfeYFo="; }; propagatedBuildInputs = builtins.attrValues { inherit (pkgs.rPackages) httr jsonlite sys; From 87edbda1005f26fb7e56e8e5c85883be0dd3b822 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Fri, 22 Sep 2023 21:34:27 +0200 Subject: [PATCH 06/26] quick patch! --- inst/extdata/default.nix | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index c1ff6634..ef9ee7cb 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,42 +1,41 @@ -# This file was generated by the {rix} R package v0.3.1 on 2023-09-22 +# This file was generated by the {rix} R package v0.2.1.9002 on 2023-09-10 # with following call: -# >rix(r_ver = "fe977679240ac2027b151ecca1bc6ce808c2e8af", +# >rix(r_ver = "78058d810644f5ed276804ce7ea9e82d92bee293", # > r_pkgs = NULL, # > system_pkgs = "nix", # > git_pkgs = list(list(package_name = "rix", # > repo_url = "https://github.com/b-rodrigues/rix", # > branch_name = "master", -# > commit = "b4501842723ef19391c7653e0b44a487505d89f2")), +# > commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4")), # > ide = "other", # > project_path = dirname(path), # > overwrite = TRUE, # > shell_hook = "R --vanilla") -# It uses nixpkgs' revision fe977679240ac2027b151ecca1bc6ce808c2e8af for reproducibility purposes +# It uses nixpkgs' revision 78058d810644f5ed276804ce7ea9e82d92bee293 for reproducibility purposes # which will install R version latest # Report any issues to https://github.com/b-rodrigues/rix let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/fe977679240ac2027b151ecca1bc6ce808c2e8af.tar.gz") {}; + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/78058d810644f5ed276804ce7ea9e82d92bee293.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { url = "https://github.com/b-rodrigues/rix"; branchName = "master"; - rev = "b4501842723ef19391c7653e0b44a487505d89f2"; - sha256 = "sha256-pQdRKxzNhDPPWW1T9oaQEtkLTdmU0+Ry0aGzEGfeYFo="; + rev = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4"; + sha256 = "sha256-qi8FXCsKIuoHoERE6ZhTooHH9f94cRIi6mrUVbQU8NY="; }; propagatedBuildInputs = builtins.attrValues { inherit (pkgs.rPackages) httr jsonlite sys; }; }) ]; tex = (pkgs.texlive.combine { - inherit (pkgs.texlive) scheme-small ; + inherit (pkgs.texlive) scheme-basic ; }); system_packages = builtins.attrValues { inherit (pkgs) R nix; }; in pkgs.mkShell { - LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = '' R --vanilla From 28201ac0327f7fafcdcb534fb9d76418836866cc Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Mon, 25 Sep 2023 21:12:59 +0200 Subject: [PATCH 07/26] fixed locales --- R/detect_os.R | 2 +- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- dev/get_os.Rmd | 2 +- inst/extdata/default.nix | 34 +++++++++++++++++----------------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/R/detect_os.R b/R/detect_os.R index 36567c8d..112cd25f 100644 --- a/R/detect_os.R +++ b/R/detect_os.R @@ -23,7 +23,7 @@ detect_os <- function(){ #' @noRd generate_locale_archive <- function(os){ if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";' + 'LOCALE_ARCHIVE = \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\";' } else if(detect_os() == "Darwin") { '' } else { diff --git a/R/find_rev.R b/R/find_rev.R index 27ec8de1..90629c5b 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -457,7 +457,7 @@ 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)) diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 96ae481a..f0dc3555 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -541,7 +541,7 @@ 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)) diff --git a/dev/get_os.Rmd b/dev/get_os.Rmd index 6c33a621..d0b20929 100644 --- a/dev/get_os.Rmd +++ b/dev/get_os.Rmd @@ -42,7 +42,7 @@ This function adds deals with locale on Linux (and WSL2): #' generate_locale_archive("Linux") generate_locale_archive <- function(os){ if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";' + 'LOCALE_ARCHIVE = \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\";' } else if(detect_os() == "Darwin") { '' } else { diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index ef9ee7cb..c828135f 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,41 +1,41 @@ -# This file was generated by the {rix} R package v0.2.1.9002 on 2023-09-10 +# This file was generated by the {rix} R package v0.3.1 on 2023-09-25 # with following call: -# >rix(r_ver = "78058d810644f5ed276804ce7ea9e82d92bee293", +# >rix(r_ver = "976fa3369d722e76f37c77493d99829540d43845", # > r_pkgs = NULL, -# > system_pkgs = "nix", -# > git_pkgs = list(list(package_name = "rix", -# > repo_url = "https://github.com/b-rodrigues/rix", +# > system_pkgs = NULL, +# > git_pkgs = list(package_name = "rix", +# > repo_url = "https://github.com/b-rodrigues/rix/", # > branch_name = "master", -# > commit = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4")), +# > commit = "ae39d2142461688b1be41db800752a949ebb3c7b"), # > ide = "other", -# > project_path = dirname(path), -# > overwrite = TRUE, -# > shell_hook = "R --vanilla") -# It uses nixpkgs' revision 78058d810644f5ed276804ce7ea9e82d92bee293 for reproducibility purposes -# which will install R version latest +# > project_path = "inst/extdata", +# > overwrite = TRUE) +# It uses nixpkgs' revision 976fa3369d722e76f37c77493d99829540d43845 for reproducibility purposes +# which will install R as it was as of nixpkgs revision: 976fa3369d722e76f37c77493d99829540d43845 # Report any issues to https://github.com/b-rodrigues/rix let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/78058d810644f5ed276804ce7ea9e82d92bee293.tar.gz") {}; + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { - url = "https://github.com/b-rodrigues/rix"; + url = "https://github.com/b-rodrigues/rix/"; branchName = "master"; - rev = "1bd327c7cf315d22ab69865b6fc96c943cd97bd4"; - sha256 = "sha256-qi8FXCsKIuoHoERE6ZhTooHH9f94cRIi6mrUVbQU8NY="; + rev = "ae39d2142461688b1be41db800752a949ebb3c7b"; + sha256 = "sha256-rOhFnc01CzRE6Hl73xGvaE/bQCoX0d5tZ10jzAoqQ7g="; }; propagatedBuildInputs = builtins.attrValues { inherit (pkgs.rPackages) httr jsonlite sys; }; }) ]; tex = (pkgs.texlive.combine { - inherit (pkgs.texlive) scheme-basic ; + inherit (pkgs.texlive) scheme-small ; }); system_packages = builtins.attrValues { - inherit (pkgs) R nix; + inherit (pkgs) R glibcLocalesUtf8 ; }; in pkgs.mkShell { + LOCALE_ARCHIVE = "${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive"; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = '' R --vanilla From f2d9c6df22823153c8840404c4250073eb4600ac Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Mon, 25 Sep 2023 21:30:24 +0200 Subject: [PATCH 08/26] whole set of locales --- R/detect_os.R | 2 +- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- dev/get_os.Rmd | 2 +- inst/extdata/default.nix | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/detect_os.R b/R/detect_os.R index 112cd25f..9830a009 100644 --- a/R/detect_os.R +++ b/R/detect_os.R @@ -23,7 +23,7 @@ detect_os <- function(){ #' @noRd generate_locale_archive <- function(os){ if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\";' + 'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";' } else if(detect_os() == "Darwin") { '' } else { diff --git a/R/find_rev.R b/R/find_rev.R index 90629c5b..63fd1bf8 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -457,7 +457,7 @@ tex_pkgs) # to add it. generate_system_pkgs <- function(system_pkgs){ sprintf('system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocalesUtf8 %s; + inherit (pkgs) R glibcLocales %s; }; ', get_system_pkgs(system_pkgs)) diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index f0dc3555..c85d4a02 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -541,7 +541,7 @@ tex_pkgs) # to add it. generate_system_pkgs <- function(system_pkgs){ sprintf('system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocalesUtf8 %s; + inherit (pkgs) R glibcLocales %s; }; ', get_system_pkgs(system_pkgs)) diff --git a/dev/get_os.Rmd b/dev/get_os.Rmd index d0b20929..5e85ea25 100644 --- a/dev/get_os.Rmd +++ b/dev/get_os.Rmd @@ -42,7 +42,7 @@ This function adds deals with locale on Linux (and WSL2): #' generate_locale_archive("Linux") generate_locale_archive <- function(os){ if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\";' + 'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";' } else if(detect_os() == "Darwin") { '' } else { diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index c828135f..eb2cf704 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -31,11 +31,11 @@ let inherit (pkgs.texlive) scheme-small ; }); system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocalesUtf8 ; + inherit (pkgs) R glibcLocales ; }; in pkgs.mkShell { - LOCALE_ARCHIVE = "${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive"; + LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = '' R --vanilla From 248fbf731c6db64e6d110e571fe53c687352f072 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 12:38:01 +0200 Subject: [PATCH 09/26] add Darwin nix runner --- .github/workflows/nix.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml index 707684f0..373da456 100644 --- a/.github/workflows/nix.yaml +++ b/.github/workflows/nix.yaml @@ -8,7 +8,7 @@ name: nix-builder jobs: build: - name: nix builder + name: nix builder for Ubuntu runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -18,3 +18,18 @@ jobs: run: | nix-build ./inst/extdata/default.nix nix-shell ./inst/extdata/default.nix + +jobs: + build: + 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 From 94a4c1584e76fa1ed8d9f6684faf2e4f3bb104bc Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 12:38:51 +0200 Subject: [PATCH 10/26] manually edited config to test Darwin runner --- inst/extdata/default.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index eb2cf704..d0896e14 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -31,13 +31,11 @@ let inherit (pkgs.texlive) scheme-small ; }); system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales ; + inherit (pkgs) R glibcLocalesUtf8 ; }; in pkgs.mkShell { - LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive" else ""; buildInputs = [ git_archive_pkgs system_packages ]; - shellHook = '' -R --vanilla -''; + shellHook = "R --vanilla"; } From 39ae2b99475e7c9883708f8ee3fbd0264e2899ab Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 12:47:17 +0200 Subject: [PATCH 11/26] fix syntax error --- .github/workflows/nix.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml index 373da456..236534b5 100644 --- a/.github/workflows/nix.yaml +++ b/.github/workflows/nix.yaml @@ -19,7 +19,6 @@ jobs: nix-build ./inst/extdata/default.nix nix-shell ./inst/extdata/default.nix -jobs: build: name: nix builder for MacOS X86_64 # the DeterminateSystems action currently uses macos-12 From c49bf5cfada3f8bc0a92d45af2395e8d36ac3143 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 12:48:07 +0200 Subject: [PATCH 12/26] another fixing attempt --- .github/workflows/nix.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml index 236534b5..ca717add 100644 --- a/.github/workflows/nix.yaml +++ b/.github/workflows/nix.yaml @@ -19,7 +19,6 @@ jobs: nix-build ./inst/extdata/default.nix nix-shell ./inst/extdata/default.nix - build: 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 From f73da02591562ddd195b900a740c3fb89245de97 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 12:53:43 +0200 Subject: [PATCH 13/26] attempt fixing --- .github/workflows/nix.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml index ca717add..66cb48ad 100644 --- a/.github/workflows/nix.yaml +++ b/.github/workflows/nix.yaml @@ -7,7 +7,7 @@ on: name: nix-builder jobs: - build: + run-x86_64-linux: name: nix builder for Ubuntu runs-on: ubuntu-22.04 steps: @@ -19,6 +19,7 @@ jobs: 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 From e57eca41f93d989517888c706be38e4ebe45e8cf Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 13:05:36 +0200 Subject: [PATCH 14/26] fix locale warnings by setting envvars in nix --- inst/extdata/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index d0896e14..64314526 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -36,6 +36,12 @@ let in pkgs.mkShell { LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/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 = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; } From 432c5962996ae92a99129fb3b72f7c37418a7ca4 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 15:14:20 +0200 Subject: [PATCH 15/26] fix locale --- R/detect_os.R | 7 +++---- R/find_rev.R | 37 ++++++++++++++++++++++++---------- dev/build_envs.Rmd | 37 ++++++++++++++++++++++++---------- dev/get_os.Rmd | 7 +++---- inst/extdata/default.nix | 43 ++++++++++------------------------------ 5 files changed, 69 insertions(+), 62 deletions(-) diff --git a/R/detect_os.R b/R/detect_os.R index 9830a009..98cfcccf 100644 --- a/R/detect_os.R +++ b/R/detect_os.R @@ -22,10 +22,9 @@ detect_os <- function(){ #' generate_locale_archive("Linux") #' @noRd generate_locale_archive <- function(os){ - if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";' - } else if(detect_os() == "Darwin") { - '' + 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") } diff --git a/R/find_rev.R b/R/find_rev.R index 63fd1bf8..c97aef86 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -411,10 +411,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; @@ -462,6 +461,24 @@ tex_pkgs) ', get_system_pkgs(system_pkgs)) } + + generate_locale_variables <- function() { + locale_variables <- getOption( + "rix.nix_locale_variables", + default = 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" + ) + ) + paste( + Map(function(x, nm) paste0(nm, " = ", x), + nm = names(locale_variables), x = locale_variables), + collapse = ";\n " + ) + } generate_rstudio_pkgs <- function(ide, flag_git_archive, flag_rpkgs){ if(ide == "rstudio"){ @@ -477,26 +494,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 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, diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index c85d4a02..07397172 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -495,10 +495,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; @@ -546,6 +545,24 @@ tex_pkgs) ', get_system_pkgs(system_pkgs)) } + + generate_locale_variables <- function() { + locale_variables <- getOption( + "rix.nix_locale_variables", + default = 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" + ) + ) + paste( + Map(function(x, nm) paste0(nm, " = ", x), + nm = names(locale_variables), x = locale_variables), + collapse = ";\n " + ) + } generate_rstudio_pkgs <- function(ide, flag_git_archive, flag_rpkgs){ if(ide == "rstudio"){ @@ -561,26 +578,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 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, diff --git a/dev/get_os.Rmd b/dev/get_os.Rmd index 5e85ea25..1ca46b83 100644 --- a/dev/get_os.Rmd +++ b/dev/get_os.Rmd @@ -41,10 +41,9 @@ This function adds deals with locale on Linux (and WSL2): #' @examples #' generate_locale_archive("Linux") generate_locale_archive <- function(os){ - if(detect_os() == "Linux"){ - 'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";' - } else if(detect_os() == "Darwin") { - '' + 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") } diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 64314526..919febdf 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,47 +1,26 @@ -# This file was generated by the {rix} R package v0.3.1 on 2023-09-25 -# with following call: -# >rix(r_ver = "976fa3369d722e76f37c77493d99829540d43845", -# > r_pkgs = NULL, -# > system_pkgs = NULL, -# > git_pkgs = list(package_name = "rix", -# > repo_url = "https://github.com/b-rodrigues/rix/", -# > branch_name = "master", -# > commit = "ae39d2142461688b1be41db800752a949ebb3c7b"), -# > ide = "other", -# > project_path = "inst/extdata", -# > overwrite = TRUE) -# It uses nixpkgs' revision 976fa3369d722e76f37c77493d99829540d43845 for reproducibility purposes -# which will install R as it was as of nixpkgs revision: 976fa3369d722e76f37c77493d99829540d43845 -# Report any issues to https://github.com/b-rodrigues/rix -let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { - url = "https://github.com/b-rodrigues/rix/"; + url = "https://github.com/b-rodrigues/rix"; branchName = "master"; - rev = "ae39d2142461688b1be41db800752a949ebb3c7b"; - sha256 = "sha256-rOhFnc01CzRE6Hl73xGvaE/bQCoX0d5tZ10jzAoqQ7g="; + rev = "b4501842723ef19391c7653e0b44a487505d89f2"; + sha256 = "sha256-pQdRKxzNhDPPWW1T9oaQEtkLTdmU0+Ry0aGzEGfeYFo="; }; propagatedBuildInputs = builtins.attrValues { inherit (pkgs.rPackages) httr jsonlite sys; }; }) ]; - tex = (pkgs.texlive.combine { - inherit (pkgs.texlive) scheme-small ; -}); - system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocalesUtf8 ; + system_packages = builtins.attrValues { + inherit (pkgs) R glibcLocales nix; }; in pkgs.mkShell { - LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/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"; + LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/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 buildInputs = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; } From ed9bcde7e59163a3d4104260dd2be944dd3df9a1 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 15:27:07 +0200 Subject: [PATCH 16/26] manually fix `inst/extdata/default.nix`, seems git2nix.dev is down --- inst/extdata/default.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 919febdf..1f979cdc 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,3 +1,20 @@ +# This file was generated by the {rix} R package v0.3.1 on 2023-09-25 +# with following call: +# >rix(r_ver = "976fa3369d722e76f37c77493d99829540d43845", +# > r_pkgs = NULL, +# > system_pkgs = NULL, +# > git_pkgs = list(package_name = "rix", +# > repo_url = "https://github.com/b-rodrigues/rix/", +# > branch_name = "master", +# > commit = "ae39d2142461688b1be41db800752a949ebb3c7b"), +# > ide = "other", +# > project_path = "inst/extdata", +# > overwrite = TRUE) +# It uses nixpkgs' revision 976fa3369d722e76f37c77493d99829540d43845 for reproducibility purposes +# which will install R as it was as of nixpkgs revision: 976fa3369d722e76f37c77493d99829540d43845 +# Report any issues to https://github.com/b-rodrigues/rix +let + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { From 0fc293fa0b540a35f01d7933db5aa9ff7a9d1648 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 15:31:58 +0200 Subject: [PATCH 17/26] fix missing ";\n" --- R/find_rev.R | 3 ++- dev/build_envs.Rmd | 3 ++- inst/extdata/default.nix | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index c97aef86..81ab24fb 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -473,11 +473,12 @@ get_system_pkgs(system_pkgs)) LC_PAPER = "en_US.UTF-8" ) ) - paste( + 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){ diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 07397172..04b7fe94 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -557,11 +557,12 @@ get_system_pkgs(system_pkgs)) LC_PAPER = "en_US.UTF-8" ) ) - paste( + 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){ diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 1f979cdc..df518669 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -37,7 +37,7 @@ let 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_PAPER = en_US.UTF-8; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; } From 61999b77d507352e18e53c32543300b601bc3a99 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 15:37:30 +0200 Subject: [PATCH 18/26] fix missing quoting --- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- inst/extdata/default.nix | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index 81ab24fb..599e4152 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -474,7 +474,7 @@ get_system_pkgs(system_pkgs)) ) ) locale_vars <- paste( - Map(function(x, nm) paste0(nm, " = ", x), + Map(function(x, nm) paste0(nm, ' = ', '"', x, '"'), nm = names(locale_variables), x = locale_variables), collapse = ";\n " ) diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 04b7fe94..e7c0c5c2 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -558,7 +558,7 @@ get_system_pkgs(system_pkgs)) ) ) locale_vars <- paste( - Map(function(x, nm) paste0(nm, " = ", x), + Map(function(x, nm) paste0(nm, ' = ', '"', x, '"'), nm = names(locale_variables), x = locale_variables), collapse = ";\n " ) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index df518669..e1d4c4cd 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -33,11 +33,11 @@ let in pkgs.mkShell { LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/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; + 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"; buildInputs = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; } From 058c75eadd7fe0ffbaaa2bb23d8a2730e4e144b4 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 15:43:39 +0200 Subject: [PATCH 19/26] try not inheriting nix for `inst/extdata/default.nix` --- R/find_rev.R | 2 +- dev/build_envs.Rmd | 2 +- inst/extdata/default.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index 599e4152..8e176750 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -565,7 +565,7 @@ 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", diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index e7c0c5c2..3605aad2 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -653,7 +653,7 @@ 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", diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index e1d4c4cd..856cab26 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -28,7 +28,7 @@ let }; }) ]; system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales nix; + inherit (pkgs) R glibcLocales; }; in pkgs.mkShell { From 659500e017e9cd8b81c3ba8618f399712f1fb790 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 16:03:49 +0200 Subject: [PATCH 20/26] get new revision --- inst/extdata/default.nix | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 856cab26..ad2eb9ae 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -1,20 +1,21 @@ -# This file was generated by the {rix} R package v0.3.1 on 2023-09-25 +# This file was generated by the {rix} R package v0.3.1 on 2023-09-26 # with following call: -# >rix(r_ver = "976fa3369d722e76f37c77493d99829540d43845", +# >rix(r_ver = "e12483116b3b51a185a33a272bf351e357ba9a99", # > r_pkgs = NULL, # > system_pkgs = NULL, -# > git_pkgs = list(package_name = "rix", -# > repo_url = "https://github.com/b-rodrigues/rix/", +# > git_pkgs = list(list(package_name = "rix", +# > repo_url = "https://github.com/b-rodrigues/rix", # > branch_name = "master", -# > commit = "ae39d2142461688b1be41db800752a949ebb3c7b"), +# > commit = "b4501842723ef19391c7653e0b44a487505d89f2")), # > ide = "other", -# > project_path = "inst/extdata", -# > overwrite = TRUE) -# It uses nixpkgs' revision 976fa3369d722e76f37c77493d99829540d43845 for reproducibility purposes -# which will install R as it was as of nixpkgs revision: 976fa3369d722e76f37c77493d99829540d43845 +# > project_path = dirname(path), +# > overwrite = TRUE, +# > shell_hook = "R --vanilla") +# It uses nixpkgs' revision e12483116b3b51a185a33a272bf351e357ba9a99 for reproducibility purposes +# which will install R version latest # Report any issues to https://github.com/b-rodrigues/rix let - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {}; + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/e12483116b3b51a185a33a272bf351e357ba9a99.tar.gz") {}; git_archive_pkgs = [(pkgs.rPackages.buildRPackage { name = "rix"; src = pkgs.fetchgit { @@ -28,7 +29,7 @@ let }; }) ]; system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales; + inherit (pkgs) R glibcLocales ; }; in pkgs.mkShell { @@ -38,6 +39,7 @@ let LC_TIME = "en_US.UTF-8"; LC_MONETARY = "en_US.UTF-8"; LC_PAPER = "en_US.UTF-8"; + buildInputs = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; } From a57e6a1ec07d58410f18e0b048b31cf59f71dfaf Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 16:32:45 +0200 Subject: [PATCH 21/26] check for valid locale variables set via options() --- R/find_rev.R | 22 +++++++++++++++------- dev/build_envs.Rmd | 22 +++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index 8e176750..dfefe1e7 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -463,16 +463,24 @@ 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" + ) locale_variables <- getOption( "rix.nix_locale_variables", - default = 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" - ) + 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), diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 3605aad2..526aacd0 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -547,16 +547,24 @@ 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" + ) locale_variables <- getOption( "rix.nix_locale_variables", - default = 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" - ) + 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), From 08ba8ad84f7d93521e5ecab0c031c3485e5f44b5 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 16:51:23 +0200 Subject: [PATCH 22/26] docs; inherit only glibcLocalesUtf8 --- R/find_rev.R | 12 +++++++++++- dev/build_envs.Rmd | 12 +++++++++++- inst/extdata/default.nix | 2 +- man/rix.Rd | 10 ++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index dfefe1e7..3e784949 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -283,6 +283,16 @@ 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`). This is done to ensure locale reproducibility by default +#' in Nix environments. 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, @@ -456,7 +466,7 @@ tex_pkgs) # to add it. generate_system_pkgs <- function(system_pkgs){ sprintf('system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales %s; + inherit (pkgs) R glibcLocalesUtf8 %s; }; ', get_system_pkgs(system_pkgs)) diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 526aacd0..12300850 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -367,6 +367,16 @@ you use another IDE, you can leave the "ide" argument blank: #' 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`). This is done to ensure locale reproducibility by default +#' in Nix environments. 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, @@ -540,7 +550,7 @@ tex_pkgs) # to add it. generate_system_pkgs <- function(system_pkgs){ sprintf('system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales %s; + inherit (pkgs) R glibcLocalesUtf8 %s; }; ', get_system_pkgs(system_pkgs)) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index ad2eb9ae..4abcebf5 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -29,7 +29,7 @@ let }; }) ]; system_packages = builtins.attrValues { - inherit (pkgs) R glibcLocales ; + inherit (pkgs) R glibcLocalesUtf8 ; }; in pkgs.mkShell { diff --git a/man/rix.Rd b/man/rix.Rd index 49425d15..c6e773a3 100644 --- a/man/rix.Rd +++ b/man/rix.Rd @@ -88,4 +88,14 @@ want to use an environment as it would have looked at the time of \code{{ggplot2 version 2.2.1 release, then use the Nix revision closest to that date, by setting \code{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 \code{"en_US.UTF-8"} for the +relevant locale variables (\code{LANG}, \code{LC_ALL}, \code{LC_TIME}, \code{LC_MONETARY}, +\code{LC_PAPER}). This is done to ensure locale reproducibility by default +in Nix environments. If there are good reasons to not stick to the default, +you can set your preferred locale variables via +\verb{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 \code{glibcLocalesUtf8} set only, to not +download the full set of locales and thereby keep the size reasonably +small. } From f62b9c1a86d361d7c12065c2811c04fb1bb40062 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 17:04:52 +0200 Subject: [PATCH 23/26] add back LC_MEASUREMENT --- R/find_rev.R | 10 ++++++---- dev/build_envs.Rmd | 10 ++++++---- man/rix.Rd | 7 ++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/R/find_rev.R b/R/find_rev.R index 3e784949..422e91aa 100644 --- a/R/find_rev.R +++ b/R/find_rev.R @@ -285,9 +285,10 @@ fetchpkgs <- function(git_pkgs, archive_pkgs){ #' 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`). This is done to ensure locale reproducibility by default -#' in Nix environments. If there are good reasons to not stick to the default, -#' you can set your preferred locale variables via +#' `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 @@ -478,7 +479,8 @@ get_system_pkgs(system_pkgs)) 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_PAPER = "en_US.UTF-8", + LC_MEASUREMENT = "en_US.UTF-8" ) locale_variables <- getOption( "rix.nix_locale_variables", diff --git a/dev/build_envs.Rmd b/dev/build_envs.Rmd index 12300850..9f0d8923 100644 --- a/dev/build_envs.Rmd +++ b/dev/build_envs.Rmd @@ -369,9 +369,10 @@ you use another IDE, you can leave the "ide" argument blank: #' 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`). This is done to ensure locale reproducibility by default -#' in Nix environments. If there are good reasons to not stick to the default, -#' you can set your preferred locale variables via +#' `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 @@ -562,7 +563,8 @@ get_system_pkgs(system_pkgs)) 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_PAPER = "en_US.UTF-8", + LC_MEASUREMENT = "en_US.UTF-8" ) locale_variables <- getOption( "rix.nix_locale_variables", diff --git a/man/rix.Rd b/man/rix.Rd index c6e773a3..342cc8ba 100644 --- a/man/rix.Rd +++ b/man/rix.Rd @@ -90,9 +90,10 @@ version 2.2.1 release, then use the Nix revision closest to that date, by settin ensures that Nix builds a completely coherent environment. By default, the nix shell will be configured with \code{"en_US.UTF-8"} for the relevant locale variables (\code{LANG}, \code{LC_ALL}, \code{LC_TIME}, \code{LC_MONETARY}, -\code{LC_PAPER}). This is done to ensure locale reproducibility by default -in Nix environments. If there are good reasons to not stick to the default, -you can set your preferred locale variables via +\code{LC_PAPER}, \code{LC_MEASUREMENT}). This is done to ensure locale +reproducibility by default in Nix environments created with \code{rix()}. +If there are good reasons to not stick to the default, you can set your +preferred locale variables via \verb{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 \code{glibcLocalesUtf8} set only, to not From 52a259cf68d90a3059c6ccc15ecc17fc17a425b6 Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 17:07:23 +0200 Subject: [PATCH 24/26] update default.nix --- inst/extdata/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/extdata/default.nix b/inst/extdata/default.nix index 4abcebf5..f8896a10 100644 --- a/inst/extdata/default.nix +++ b/inst/extdata/default.nix @@ -39,6 +39,7 @@ let 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 = [ git_archive_pkgs system_packages ]; shellHook = "R --vanilla"; From faeae1655ebcd5ce17f5ff28ab2dec698c93cd5c Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 17:32:21 +0200 Subject: [PATCH 25/26] Bump version to 0.4.0 --- DESCRIPTION | 2 +- NEWS.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6e813c0f..890c2fc0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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")), diff --git a/NEWS.md b/NEWS.md index beab98e6..01113ce1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,25 @@ +# 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 From dece23496465223e8ff585341a55ec9d58b2f7ac Mon Sep 17 00:00:00 2001 From: Philipp Baumann Date: Tue, 26 Sep 2023 17:32:44 +0200 Subject: [PATCH 26/26] typo --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 01113ce1..03dced4f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,7 +9,7 @@ `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., + `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.