Skip to content

Commit

Permalink
Update 11-nix.qmd
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rodrigues authored Oct 31, 2023
1 parent 1db0bfe commit f194055
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion 11-nix.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,66 @@ let
}
```
Thi first line imports a specfic hash of nixpkgs (pinning):

I won’t go into much detail, but here are some pointers:
```
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {};
```

Then, I define the set of R packages that we require:

```
rpkgs = builtins.attrValues {
inherit (pkgs.rPackages) quarto Ecdat devtools janitor plm pwt9 rio targets tarchetypes testthat tidyverse usethis formatR;
};
```

I then do something similar for LaTeX packages:

```
tex = (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-small amsmath framed fvextra environ fontawesome5 orcidlink pdfcol tcolorbox tikzfill;
});
```

Finally, I define the set of "system" packages, so the R language itself, and Quarto (and glibcLocalesUtf8 to set the locale variables
to utf-8):

```
system_packages = builtins.attrValues {
inherit (pkgs) R glibcLocalesUtf8 quarto;
};
```

Finally, all these definitions are used to define a *shell*:

```
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 = [rpkgs tex system_packages];
}
```

In this block, a Nix shell environment is defined using pkgs.mkShell. The LOCALE_ARCHIVE variable is conditionally set based on the system architecture.
Several environment variables (LANG, LC_ALL, LC_TIME, LC_MONETARY, LC_PAPER, and LC_MEASUREMENT) are set to "en_US.UTF-8".
The buildInputs attribute specifies the list of inputs needed for this shell environment, which includes the three sets defined above: R packages (rpkgs),
TeX packages (tex), and system packages (system_packages).

This Nix expression defines a development environment with specific R and TeX packages, system packages, and locale settings.
When this expression is evaluated using Nix, it will generate a shell environment that includes all the specified dependencies,
allowing you to work with R and TeX in a controlled and reproducible environment.

This environment can be built using the `nix-build` command, and users can then *drop* into that shell using `nix-shell`.

Writing these Nix expressions is not easy, and there is a lot of boilerplate code. To simplify the process of writing these expressions,
a package I wrote, called `{rix}`, can help you.

## The {rix} package

0 comments on commit f194055

Please sign in to comment.