白月初

Home
About
Projects
Blog
Tools
Stats
baiyuechu.dev
Baiyuechu

I am a software engineer with a passion for building web applications and mobile apps. I am a quick learner and I am always looking to improve my skills.

© 2026 Baiyuechu

General

  • Home
  • About
  • Projects
  • Blog
  • Toolbox
  • Stats

Specifics

  • Connections
  • Gallery
  • Community

Extra

  • Links
  • Changelog

Setup project esp32 use platformio and nix
nixesp32platformioembedded

A note about how to setup project esp32 use platformio and nix

2026-01-23By Baiyuechu
...
Your browser does not support the audio element.

Init project with nix

bash
1mkdir -p ~/test/esp32
2cd ~/test/esp32
3nix flake init

Setup environment for nix

  • Edit file flake.nix in project. This is a example i use for my project.
nix
1{
2  description = "ESP32 + PlatformIO devshell";
3  inputs = {
4    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
5  };
6
7  outputs = {
8    self,
9    nixpkgs,
10  }: let
11    system = "x86_64-linux";
12    pkgs = import nixpkgs {inherit system;};
13  in {
14    devShells.${system}.default = pkgs.mkShell {
15      packages = with pkgs; [
16        platformio
17        python3
18        gcc
19        gnumake
20        pkg-config
21        picocom
22        clang-tools # this for my setup lsp and formatter
23      ];
24
25      shellHook = ''
26        if [ -z "$ZSH_VERSION" ]; then
27          export SHELL=${pkgs.zsh}/bin/zsh
28          exec ${pkgs.zsh}/bin/zsh -l
29        fi
30      '';
31    };
32  };
33}
  • Run command nix develop in project.

Init project with platformio

  • For arduino framework:
bash
1pio project init --board esp32dev --project-option "framework=arduino"
  • For espidf framework:
bash
1pio project init --board esp32dev --project-option "framework=espidf"

Compile project

bash
1pio run -t compiledb

Setup clangd to reduce err of lsp

  • Create file .clangd in root of project.
txt
1CompileFlags:
2  Add:
3    - "-ferror-limit=0"
4    - "-Wno-unknown-attributes"
5    - "-Wno-ignored-attributes"
6  Remove:
7    # Xtensa-specific flags unsupported by clang
8    - "-mlongcalls"
9    - "-mtext-section-literals"
10    - "-fstrict-volatile-bitfields"
11    - "-fno-tree-switch-conversion"
12    - "-fno-jump-tables"
13    # ESP-IDF specific
14    - "-fno-rtti"
15    - "-fno-exceptions"
16    - "-mfix-esp32-psram-cache-issue"
17    - "-mfix-esp32-psram-cache-strategy=*"
18    # GCC-specific warnings clang doesn't know
19    - "-Wno-frame-address"
20    - "-Wno-error=unused-but-set-variable"
21    - "-freorder-blocks"
22  Compiler: clang++
23Diagnostics:
24  Suppress:
25    # Missing Arduino/ESP headers (framework quirks)
26    - pp_file_not_found
27    # Arduino Print class overload resolution
28    - ovl_no_viable_member_function_in_call
29    - ovl_no_viable_function_in_call
30    # Template issues with Arduino libraries
31    - typecheck_invalid_operands
32    - typecheck_nonviable_condition
33    # ESP-IDF macro expansions
34    - builtin_requires_header
35    - implicit_function_decl
36  UnusedIncludes: None
37  MissingIncludes: None

Some commnads when use platformio

  • Run/Upload/Monitor project.
bash
1pio run # run project
2pio run -t upload # upload project
3pio device monitor # monitor device
  • Install lib for project. You can install by command or declare in platformio.ini after use pio lib install.
bash
1# use command
2pio lib install <LIB_NAME>
ini
1[env:esp32dev]
2platform = espressif32
3board = esp32dev
4framework = arduino
5monitor_speed = 115200
6
7lib_deps =
8  adafruit/Adafruit SSD1306
9  adafruit/Adafruit GFX Library

Join Baiyuechu Newsletter!

Get notified when I publish new articles, tutorials, and project updates. Subscribe for insights and actionable content.