Skip to contents

This vignette will discuss Linux and Windows-specific topics. If you’re not using either of these systems, you can ignore this vignette, and read the vignette("b2-setting-up-and-using-rix-on-macos") vignette instead.

Introduction

When it comes to Nix, there are really only two supported operating systems: macOS and Linux distributions. Windows is “supported” because it is actually running Linux thanks to WSL2. In practice this means that Linux distributions and Windows can be considered one system, and macOS another, separate, system. Because Windows is really running Linux under the hood thanks to WSL2, this means that WSL2 needs to be running on your Windows system before you attempt to install Nix. But it is important to know that you can run rix even if you don’t have Nix installed, which means you can generate Nix expressions, you just can’t build them. So if you can’t install Nix on your system, but have R already installed, you can skip to the last section of this vignette to simply install the rix package.

Installing Nix

Windows pre-requisites

If you are on Windows, you need the Windows Subsystem for Linux 2 (WSL2) to run Nix. If you are on a recent version of Windows 10 or 11, you can simply run this as an administrator in PowerShell:

wsl --install

You can find further installation notes at this official MS documentation.

We recommend to activate systemd in Ubuntu WSL2, mainly because this supports other users than root running Nix. To set this up, please do as outlined this official Ubuntu blog entry:


# in WSL2 Ubuntu shell

sudo -i
nano /etc/wsl.conf

This will open the /etc/wsl.conf in a nano, a command line text editor. Add the following line:

[boot]
systemd=true

Save the file with CTRL-O and then quit nano with CTRL-X. Then, type the following line in powershell:

wsl --shutdown

and then relaunch WSL (Ubuntu) from the start menu.

Afterwards, you can install Nix like business as usual. You can proceed with the Determinate Systems installer.

Using the Determinate Systems installer

You can use rix to generate Nix expressions even if you don’t have Nix installed on your system, but obviously, you need to install Nix if you actually want to build the defined development environment and use them.

Installing (and uninstalling) Nix is quite simple, thanks to the installer from Determinate Systems, a company that provides services and tools built on Nix.

Do not use your operating system’s package manager to install Nix. Instead, simply open a terminal and run the following line (on Windows, if you cannot or have decided not to activate systemd, then you have to append --init none to the command. You can find more details about this on The Determinate Nix Installer page):

curl --proto '=https' --tlsv1.2 -sSf \
    -L https://install.determinate.systems/nix | \
     sh -s -- install

Once you have Nix installed, you can build the expressions you generate with rix!

On Linux, once Nix is installed, all the software that will be installed through Nix will be saved to the /nix directory on the root partition. It is common for Linux users to have a separate partition for /, which may be small. Complete development environments built with Nix can take up much space, so if the available space on your root partition is limited, we advise you to mount the /nix folder on another partition with more space (for example, a secondary hard drive). For this, edit /etc/fstab and add the following line at the end:

/home/path_to/nix /nix none bind 0 0

This will map /nix to /home/path_to/nix which can be on a larger partition. If you have enough space on your root partition, you can ignore the above instructions.

Case 1: you don’t have R installed and wish to install it using Nix as well

If you have successfully installed Nix, but don’t have yet R installed on your system, you could install R as you would usually do on your operating system, and then install the rix package, and from there, generated project-specific expressions and build them. But you could also install R using Nix. Running the following line in a terminal will drop you in an interactive R session that you can use to start generating expressions:

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

This should immediately start an R session inside your terminal. You can now run something like this:

rix(
  r_ver = "latest",
  r_pkgs = c("dplyr", "ggplot2"),
  system_pkgs = NULL,
  git_pkgs = NULL,
  ide = "other",
  project_path = ".",
  overwrite = TRUE
)

to generate a default.nix, and then use that file to generate an environment with R, dplyr and ggplot2. If you need to add packages for your project, rerun the command above, but add the needed packages to r_pkgs. Beware that if your already have a default.nix file in the working directory, running rix() with the overwrite = TRUE argument will overwrite it! So make sure that you are using a version control system for your projects to avoid bad surprises.

More details about managing project-specific default.nix are detailled in the vignette vignette("d1-installing-r-packages-in-a-nix-environment") and vignette("d2-installing-system-tools-and-texlive-packages-in-a-nix-environment").

You could also include rix in your project-specific environments, by generating a default.nix like so:

rix(
  r_ver = "latest",
  r_pkgs = NULL,
  git_pkgs = list(
    package_name = "rix",
    repo_url = "https://github.com/ropensci/rix",
    commit = "76d1bdd03d78589d399b4b9d473ecde616920a82"
  ),
  ide = "other",
  project_path = ".",
  overwrite = TRUE
)

Change the commit to a more recent one and adapt the project_path argument if needed.

Case 2: you have R installed through your OS’s package manager

If you have installed R on your system through the usual means of installation (so not Nix, as described before), you can install the rix package as usual as well. To install rix, run:

or use r-universe:

install.packages("rix", repos = c(
  "https://ropensci.r-universe.dev",
  "https://cloud.r-project.org"
))

You can then use the rix package to generate expressions. Consult the next vignette vignette("c-using-rix-to-build-project-specific-environments") to learn more.