Building RIOT in Nix
RIOT provides a Nix flake that contains the cross toolchains, static analysis tools, and host utilities needed to build RIOT for different platforms. It is an alternative to the Docker build environment and does not require root privileges or a Docker daemon while also keeping install sizes smaller and allowing system-wide caching of the toolchains.
Requirements
Section titled “Requirements”To run our Nix flake, you need to first install Nix and enable flakes. For installation instructions see your Linux distro’s instructions, such as the Arch Wiki or the Nix installation guide.
While we try to support both x86 and ARM, some toolchains are only available on x86 and thus will not natively work on ARM. In that case, you can use the Docker image instead.
Enabling Flakes
Section titled “Enabling Flakes”Nix still ships flakes and the nix command line as experimental features.
If nix develop fails with:
experimental Nix feature 'flakes' is disabledenable both features in ~/.config/nix/nix.conf (or /etc/nix/nix.conf):
experimental-features = nix-command flakesOn NixOS, set the same option declaratively:
nix.settings.experimental-features = [ "nix-command" "flakes" ];More details on flakes can be found in the Nix Wiki.
Entering the Development Shell
Section titled “Entering the Development Shell”From the RIOT repository root:
nix developThe default shell contains all supported cross toolchains and the static test tools but comes with a larger install size. Smaller shells are available for specific tasks / platforms:
nix develop .#nativenix develop .#rp-piconix develop .#espnix develop .#nrfnix develop .#armnix develop .#avr[...]Building
Section titled “Building”Once inside the shell (after running nix develop), use make as usual:
BOARD=native64 make -C examples/basic/hello-worldBOARD=samr21-xpro make -C examples/basic/hello-worldBOARD=arduino-uno make -C examples/basic/hello-worldFor non-interactive use, pass the command to nix develop:
nix develop --command make -C examples/basic/hello-worldBUILD_IN_DOCKER is not needed and should not be set inside the Nix shell, that being said
if any build errors occur, the docker is the source of truth and should be used to verify
the build works as expected. Most of the packages are sourced from nixpkgs which can cause
version mismatches in some cases.
Updating the Environment
Section titled “Updating the Environment”The flake pins nixpkgs and the ESP toolchains in flake.lock. Update them with:
nix flake updateFormat the Nix files with:
nix fmtValidate the flake and build the native64 smoke test with:
nix flake checkLimitations
Section titled “Limitations”- When building on ARM, expect the same issues that would occur when building
RIOT natively on ARM. E.g., issues with the
native32/64boards, the esp toolchain, etc. - The ESP8266 toolchain’s GDB is not included. It depends on Python 2.7 and an old ncurses ABI that are not available in current nixpkgs. Use an external GDB for ESP8266 debugging.
- The picolibc variants built into riotdocker are not part of the Nix shell.
Use the Docker image for builds that require
PICOLIBC=1.