Skip to content

Template blinky project that uses Nix Flakes to create a clean and reproducible build environment for ZephyrOS projects.

Notifications You must be signed in to change notification settings

dkopka/zephyr_nix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zephyr on Nix

A reproducible Zephyr RTOS project using Nix for dependency management.

Quick Start

Prerequisites

  • Nix with flakes enabled

Setup

  1. Clone the repository:

    mkdir zephyr_workspace
    cd zephyr_workspace
    git clone https://github.com/dkopka/zephyr_nix.git
    cd zephyr_nix
  2. Enter the development environment:

    nix develop
  3. Build the project:

    west build -b nrf52840dk/nrf52840
  4. Flash to device:

    west flash
  5. Debug to device:

    west debug

Project Structure

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

Development Workflow

Building

# Clean build
west build --pristine --board nrf52840dk/nrf52840
# or
west build -p -b nrf52840dk/nrf52840

# Incremental build
west build

Flashing and Debugging

# Flash to device
west flash

# Debug with GDB
west debug

Updating Dependencies

# Update west dependencies
west update

# Update Nix dependencies
nix flake update

Key Features

  • Pinned Versions: Zephyr version is locked in west.yml
  • Reproducible: Nix ensures identical environments across machines
  • Fast Setup: Single nix develop command gets everything ready
  • Clean: No global installation pollution
  • Locked Dependencies: flake.lock ensures exact package versions

Updating nRF Connect SDK Version

  1. Update the revision in west.yml:

    -  revision: v3.1.1
    +  revision: v3.1.2
  2. Update west dependencies:

    west update
  3. Commit the changes:

    git add west.yml
    git commit -m "Update nRF Connect SDK to v3.1.2"

Customization

Adding New Dependencies

  1. Python packages: Add to pythonEnv* in flake.nix
  2. System packages: Add to buildInputs in flake.nix
  3. Zephyr modules: Add to projects in west.yml

Custom Board Support

  1. Add board definition to boards/
  2. Update build commands to use your custom board

Troubleshooting

Common Issues

"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 dialout group (Linux)
  • Use sudo for flashing (not recommended)

Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

About

Template blinky project that uses Nix Flakes to create a clean and reproducible build environment for ZephyrOS projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published