Skip to content

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.

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.

Nix still ships flakes and the nix command line as experimental features. If nix develop fails with:

experimental Nix feature 'flakes' is disabled

enable both features in ~/.config/nix/nix.conf (or /etc/nix/nix.conf):

experimental-features = nix-command flakes

On NixOS, set the same option declaratively:

nix.settings.experimental-features = [ "nix-command" "flakes" ];

More details on flakes can be found in the Nix Wiki.

From the RIOT repository root:

Terminal window
nix develop

The 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:

Terminal window
nix develop .#native
nix develop .#rp-pico
nix develop .#esp
nix develop .#nrf
nix develop .#arm
nix develop .#avr
[...]

Once inside the shell (after running nix develop), use make as usual:

Terminal window
BOARD=native64 make -C examples/basic/hello-world
BOARD=samr21-xpro make -C examples/basic/hello-world
BOARD=arduino-uno make -C examples/basic/hello-world

For non-interactive use, pass the command to nix develop:

Terminal window
nix develop --command make -C examples/basic/hello-world

BUILD_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.

The flake pins nixpkgs and the ESP toolchains in flake.lock. Update them with:

Terminal window
nix flake update

Format the Nix files with:

Terminal window
nix fmt

Validate the flake and build the native64 smoke test with:

Terminal window
nix flake check
  • When building on ARM, expect the same issues that would occur when building RIOT natively on ARM. E.g., issues with the native32/64 boards, 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.