A reproducible Zephyr RTOS project using Nix for dependency management.
- Nix with flakes enabled
-
Clone the repository:
mkdir zephyr_workspace cd zephyr_workspace git clone https://github.com/dkopka/zephyr_nix.git cd zephyr_nix
-
Enter the development environment:
nix develop
-
Build the project:
west build -b nrf52840dk/nrf52840
-
Flash to device:
west flash
-
Debug to device:
west debug
my-zephyr-project/
├── flake.nix # Nix development environment
├── flake.lock # Nix flake lock file
├── west.yml # West manifest (pins Zephyr version)
├── zephyr/ # Zephyr RTOS (managed by west, gitignored)
├── src/ # Your application source code
├── boards/ # Board definitions (dts overlays)
└── scripts/ # Helper scripts
# Clean build
west build --pristine --board nrf52840dk/nrf52840
# or
west build -p -b nrf52840dk/nrf52840
# Incremental build
west build# Flash to device
west flash
# Debug with GDB
west debug# Update west dependencies
west update
# Update Nix dependencies
nix flake update- Pinned Versions: Zephyr version is locked in
west.yml - Reproducible: Nix ensures identical environments across machines
- Fast Setup: Single
nix developcommand gets everything ready - Clean: No global installation pollution
- Locked Dependencies:
flake.lockensures exact package versions
-
Update the
revisioninwest.yml:- revision: v3.1.1 + revision: v3.1.2
-
Update west dependencies:
west update
-
Commit the changes:
git add west.yml git commit -m "Update nRF Connect SDK to v3.1.2"
- Python packages: Add to
pythonEnv*inflake.nix - System packages: Add to
buildInputsinflake.nix - Zephyr modules: Add to
projectsinwest.yml
- Add board definition to
boards/ - Update build commands to use your custom board
"nix flakes are an experimental feature"
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf"west: command not found"
- Make sure you're in the Nix shell:
nix develop
Build errors after updating
- Try a clean build:
west build --pristine --board nrf52840dk/nrf52840
Permission denied on /dev/ttyACM0
- Add your user to the
dialoutgroup (Linux) - Use
sudofor flashing (not recommended)
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request