Skip to content

fix(nix): provide libclang in the dev shell - #7

Open
AlexBSoD wants to merge 1 commit into
ergohaven:mainfrom
AlexBSoD:fix/flake-libclang
Open

fix(nix): provide libclang in the dev shell#7
AlexBSoD wants to merge 1 commit into
ergohaven:mainfrom
AlexBSoD:fix/flake-libclang

Conversation

@AlexBSoD

Copy link
Copy Markdown

Problem

Building any nRF firmware from inside nix develop fails in the nrf-mpsl-sys build script:

error: failed to run custom build command for `nrf-mpsl-sys v0.2.1`

  Unable to find libclang: "couldn't find any valid shared libraries matching:
  ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the
  `LIBCLANG_PATH` environment variable to a path where one of these files can
  be found (invalid: [])"

nrf-mpsl-sys and nrf-sdc-sys generate their bindings with bindgen, which dlopens libclang at build-script time. The dev shell ships the full Rust toolchain, the embedded targets, flip-link, probe-rs, cargo-binutils — but no libclang, so anyone building firmware has to find a clang in the store and export LIBCLANG_PATH by hand every time.

Fix

Set LIBCLANG_PATH to pkgs.llvmPackages.libclang in the dev shell env.

Testing

Built keyboards/k04 central from a clean CARGO_TARGET_DIR inside nix develop, with no manually exported variables — nrf-mpsl-sys and nrf-sdc-sys both compile and the build finishes. alejandra --check is clean.

Note

No BINDGEN_EXTRA_CLANG_ARGS is added: a plain cargo build doesn't need it, and scripts/build_k04_matrix.sh already derives its own when it wants ARM headers.

Building any nRF firmware from `nix develop` fails in the build script of
nrf-mpsl-sys:

    Unable to find libclang: "couldn't find any valid shared libraries
    matching: ['libclang.so', ...], set the `LIBCLANG_PATH` environment
    variable to a path where one of these files can be found"

Both nrf-mpsl-sys and nrf-sdc-sys generate their bindings with bindgen, which
dlopens libclang at build time. The dev shell ships a full Rust toolchain and
the embedded tooling but never provided one, so every contributor had to dig a
clang out of the store and pass LIBCLANG_PATH by hand.

Point it at pkgs.llvmPackages.libclang. Verified by building keyboards/k04
central from a clean CARGO_TARGET_DIR inside `nix develop` with no manually
exported variables; nrf-mpsl-sys and nrf-sdc-sys both compile.

No BINDGEN_EXTRA_CLANG_ARGS is needed here — scripts/build_k04_matrix.sh still
derives its own when it wants ARM headers, and a plain cargo build does not.
@AlexBSoD
AlexBSoD force-pushed the fix/flake-libclang branch from 2de3431 to e778907 Compare August 12, 2026 20:58
@AlexBSoD

Copy link
Copy Markdown
Author

Rebased and green where it can be: the Build workflow passes, and the red CI run is not from this change — check and the build (examples/use_rust/*) jobs fail the same way on main itself (runs 31499869616, 31484036006, 31393491006).

This branch only touches flake.nix, so it cannot affect those jobs. Happy to look into the main breakage separately if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant