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

# add this entry

[boot]
systemd=true

# then restart running instance from PowerShell

wsl --shutdown

# relaunch Ubuntu WSL2

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

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. 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/b-rodrigues/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/b-rodrigues/rix",
                   branch_name = "master",
                   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 decribed before), you can install the rix package as usual as well. Because rix is not yet on CRAN, the easiest way is to install it from its r-universe:

install.packages("rix", repos = c("https://b-rodrigues.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.