The method below still works, but https://github.com/bouk/arduino-nix is a way to offload more responsibility to Nix, and I'm migrating my own projects to use that instead.
This is a template for building reproducible Arduino sketches with the help of Nix, with flakes enabled.
$ nix develop
$ make -C blink compile
$ make -C blink uploadnix develop provides a reproducible development environment via a Nix flake: arduino-cli and other system packages are pinned via Nix, but arduino-cli still downloads its own libraries. These are in turn pinned via the the build profile in the sketch.yaml file.
For NixOS: make sure the user is in the dialout group to access the serial port.
users.users.<user>.extraGroups = [ "dialout" ];Current version pinned via nixpkgs: 1.2.0.
Use make for some predefined options to compile and upload the sketch.
You may need to modify the options at the top of the Makefile to make the upload work.
You may need to modify the options in sketch.yaml to make it work on a different device (fqbn/platform). In its original state it's set up for the Wemos D1 Mini.
Hints to compile / upload from command line without the Makefile: https://arduino.github.io/arduino-cli/1.2/getting-started/ .
When you enter the development environment, various ARDUINO_DIRECTORIES_... variables are set. These are respected by arduino-cli.
- If you have set
_ARDUINO_PROJECT_DIRyourself, it will use this directly as the base directory of the cache for this project. - Else, if you have set
_ARDUINO_ROOT_DIRyouself, it will use${_ARDUINO_ROOT_DIR}/${name}wherenameis the project name as defined in the flake. - Else, if you have set
XDG_CACHE_HOMEyouself, it will use${XDG_CACHE_HOME}/arduino/${name}wherenameis the project name as defined in the flake. - Else, it will use
${HOME}/.arduino/${name}wherenameis the project name as defined in the flake.