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.

@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.

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 e778907 to c7dfeb2 Compare August 24, 2026 20:17
@github-actions

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 425.2 KiB 425.2 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble 472.1 KiB 472.1 KiB +0.00% 0 0 0
use_config/nrf52840_ble_split (central) 542.1 KiB 542.1 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble_split (peripheral) 334.4 KiB 334.4 KiB +0.00% 0 0 0
use_config/pi_pico_w_ble 701.9 KiB 702.0 KiB +0.00% ⬆️ +24 0 0
use_config/rp2040 163.6 KiB 163.6 KiB +0.00% 0 0 0
use_config/rp2040_split (central) 180.5 KiB 180.5 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040_split (peripheral) 30.1 KiB 30.1 KiB +0.00% 0 0 0
use_config/stm32f1 64.8 KiB 64.9 KiB +0.00% ⬆️ +4 0 0
use_config/stm32h7 112.8 KiB 112.8 KiB +0.00% 0 0 0
use_rust/nrf52832_ble 411.4 KiB 411.4 KiB +0.00% 0 0 0
use_rust/nrf52840_ble 465.8 KiB 465.8 KiB +0.00% 0 0 0
use_rust/nrf52840_ble_split (central) 549.7 KiB 549.7 KiB +0.00% ⬇️ -8 0 0
use_rust/nrf52840_ble_split (peripheral) 331.3 KiB 331.3 KiB +0.00% ⬇️ -4 0 0
use_rust/pi_pico_w_ble 701.8 KiB 701.8 KiB +0.00% 0 0 0
use_rust/rp2040 162.8 KiB 162.8 KiB +0.00% 0 0 0
use_rust/rp2040_split (central) 179.0 KiB 179.0 KiB +0.00% ⬆️ +4 0 0
use_rust/rp2040_split (peripheral) 30.5 KiB 30.5 KiB +0.00% 0 0 0
use_rust/stm32f1 64.2 KiB 64.2 KiB +0.00% ⬆️ +4 0 0
use_rust/stm32h7 134.7 KiB 134.7 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52832_ble — 425.2 KiB → 425.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 389604	   4884	  40920	 435408	  6a4d0	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 389608	   4884	  40920	 435412	  6a4d4	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +5.8%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -30  [ = ]       0    .strtab
  -0.0%     -70  [ = ]       0    .debug_info
  -0.0%    -111  [ = ]       0    .debug_str
  -0.0%    -132  [ = ]       0    .debug_line
  -0.0%    -344  -0.0%      -4    TOTAL
use_config/nrf52840_ble — 472.1 KiB → 472.1 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 422592	   5108	  55728	 483428	  76064	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 422592	   5108	  55728	 483428	  76064	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +97  [ = ]       0    .debug_line
  +0.0%     +51  [ = ]       0    .debug_info
  +0.5%     +39  [ = ]       0    .debug_abbrev
  +0.0%     +15  [ = ]       0    .debug_loc
  +1.7%      +1  [ = ]       0    [Unmapped]
  -0.0%    -131  [ = ]       0    .debug_str
  +0.0%     +72  [ = ]       0    TOTAL
use_config/nrf52840_ble_split (central) — 542.1 KiB → 542.1 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 487820	   8972	  58352	 555144	  87888	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 487824	   8972	  58352	 555148	  8788c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +18  [ = ]       0    .debug_info
  +0.0%     +17  [ = ]       0    .debug_line
  +0.0%     +15  [ = ]       0    .debug_loc
  +9.4%      +5  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -17  [ = ]       0    .strtab
  -0.0%     -66  [ = ]       0    .debug_str
  -0.0%     -32  -0.0%      -4    TOTAL
use_config/nrf52840_ble_split (peripheral) — 334.4 KiB → 334.4 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 302428	   8788	  31216	 342432	  539a0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 302428	   8788	  31216	 342432	  539a0	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +234  [ = ]       0    .debug_info
  +0.0%    +123  [ = ]       0    .debug_str
  +0.0%     +97  [ = ]       0    .debug_line
  +0.0%     +15  [ = ]       0    .debug_loc
  -1.6%      -1  [ = ]       0    [Unmapped]
  -0.0%     -12  [ = ]       0    .strtab
  +0.0%    +456  [ = ]       0    TOTAL
use_config/pi_pico_w_ble — 701.9 KiB → 702.0 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 657492	      0	  61312	 718804	  af7d4	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 657468	      0	  61312	 718780	  af7bc	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +857  [ = ]       0    .debug_info
  +0.0%    +605  [ = ]       0    .debug_str
  +0.0%    +181  [ = ]       0    .debug_line
  +0.0%    +107  [ = ]       0    .debug_loc
  +0.0%     +80  [ = ]       0    .debug_ranges
  +0.0%     +24  +0.0%     +24    .text
   +27%     +13  [ = ]       0    [Unmapped]
  -0.0%      -3  [ = ]       0    .strtab
  +0.0% +1.82Ki  +0.0%     +24    TOTAL
use_config/rp2040 — 163.6 KiB → 163.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 150760	      0	  16716	 167476	  28e34	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 150760	      0	  16716	 167476	  28e34	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +15  [ = ]       0    .debug_loc
  +2.4%      +1  [ = ]       0    [Unmapped]
  +0.0%     +16  [ = ]       0    TOTAL
use_config/rp2040_split (central) — 180.5 KiB → 180.5 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 167012	      0	  17852	 184864	  2d220	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 167008	      0	  17852	 184860	  2d21c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +124  [ = ]       0    .debug_line
  +0.0%    +104  [ = ]       0    .debug_str
  +0.0%     +37  [ = ]       0    .debug_info
  +0.0%     +18  [ = ]       0    .debug_loc
  +0.0%      +5  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  -8.3%      -4  [ = ]       0    [Unmapped]
  +0.0%    +288  +0.0%      +4    TOTAL
use_config/rp2040_split (peripheral) — 30.1 KiB → 30.1 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  27712	     60	   3020	  30792	   7848	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  27712	     60	   3020	  30792	   7848	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +2.0%      +1  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .debug_str
  [ = ]       0  [ = ]       0    TOTAL
use_config/stm32f1 — 64.8 KiB → 64.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  58740	     28	   7640	  66408	  10368	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  58736	     28	   7640	  66404	  10364	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +63  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
  -2.9%      -2  [ = ]       0    [Unmapped]
  +0.0%     +80  +0.0%      +4    TOTAL
use_config/stm32h7 — 112.8 KiB → 112.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 105196	    264	  10084	 115544	  1c358	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 105196	    264	  10084	 115544	  1c358	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL
use_rust/nrf52832_ble — 411.4 KiB → 411.4 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 376712	   4604	  39944	 421260	  66d8c	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 376712	   4604	  39944	 421260	  66d8c	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +7.0%      +3  [ = ]       0    [Unmapped]
  -0.2%     -16  [ = ]       0    .debug_abbrev
  -0.0%     -30  [ = ]       0    .strtab
  -0.0%    -111  [ = ]       0    .debug_str
  -0.0%    -132  [ = ]       0    .debug_line
  -0.0%    -206  [ = ]       0    .debug_info
  -0.0%    -492  [ = ]       0    TOTAL
use_rust/nrf52840_ble — 465.8 KiB → 465.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 421000	   4644	  51320	 476964	  74724	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 421000	   4644	  51320	 476964	  74724	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL
use_rust/nrf52840_ble_split (central) — 549.7 KiB → 549.7 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 490652	   8732	  63496	 562880	  896c0	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 490660	   8732	  63496	 562888	  896c8	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +111  [ = ]       0    .debug_str
  +0.0%     +18  [ = ]       0    .strtab
  +0.0%     +15  [ = ]       0    .debug_loc
   +14%      +7  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  -0.5%     -39  [ = ]       0    .debug_abbrev
  -0.0%     -77  [ = ]       0    .debug_line
  -0.0%    -107  [ = ]       0    .debug_info
  -0.0%     -80  -0.0%      -8    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 331.3 KiB → 331.3 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 300816	   8548	  29840	 339204	  52d04	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 300820	   8548	  29840	 339208	  52d08	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +234  [ = ]       0    .debug_info
  +0.0%    +123  [ = ]       0    .debug_str
  +0.0%     +97  [ = ]       0    .debug_line
  +0.0%     +15  [ = ]       0    .debug_loc
   +12%      +7  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -12  [ = ]       0    .strtab
  +0.0%    +460  -0.0%      -4    TOTAL
use_rust/pi_pico_w_ble — 701.8 KiB → 701.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 657116	      0	  61496	 718612	  af714	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 657116	      0	  61496	 718612	  af714	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +44  [ = ]       0    .debug_str
  +0.0%     +22  [ = ]       0    .strtab
  +3.8%      +2  [ = ]       0    [Unmapped]
  +0.0%      +1  [ = ]       0    .debug_line
  -0.0%      -5  [ = ]       0    .debug_info
  +0.0%     +64  [ = ]       0    TOTAL
use_rust/rp2040 — 162.8 KiB → 162.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 150040	      0	  16644	 166684	  28b1c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 150040	      0	  16644	 166684	  28b1c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.08Ki  [ = ]       0    .debug_str
  +0.2%    +219  [ = ]       0    .strtab
  +0.0%     +24  [ = ]       0    .debug_line
  +0.0%      +9  [ = ]       0    .debug_info
  -0.0%     -18  [ = ]       0    .debug_loc
  +0.1% +2.31Ki  [ = ]       0    TOTAL
use_rust/rp2040_split (central) — 179.0 KiB → 179.0 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 165608	      0	  17660	 183268	  2cbe4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 165604	      0	  17660	 183264	  2cbe0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +5.63Ki  [ = ]       0    .debug_str
  +0.4%    +557  [ = ]       0    .strtab
  +0.1%    +124  [ = ]       0    .debug_line
  +0.0%     +37  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .text
 -12.8%      -6  [ = ]       0    [Unmapped]
  +0.1% +6.33Ki  +0.0%      +4    TOTAL
use_rust/rp2040_split (peripheral) — 30.5 KiB → 30.5 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  27896	     60	   3284	  31240	   7a08	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  27896	     60	   3284	  31240	   7a08	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.8%      +1  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .debug_str
  [ = ]       0  [ = ]       0    TOTAL
use_rust/stm32f1 — 64.2 KiB → 64.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  58048	     28	   7656	  65732	  100c4	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  58044	     28	   7656	  65728	  100c0	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +63  [ = ]       0    .debug_str
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
 -10.3%      -6  [ = ]       0    [Unmapped]
  +0.0%     +76  +0.0%      +4    TOTAL
use_rust/stm32h7 — 134.7 KiB → 134.7 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 120676	    336	  16936	 137948	  21adc	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 120672	    336	  16936	 137944	  21ad8	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +165  [ = ]       0    .debug_line
  +0.0%      +9  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .text
  +0.0%      +3  [ = ]       0    .debug_loc
  -7.8%      -5  [ = ]       0    [Unmapped]
  -0.0%      -9  [ = ]       0    .strtab
  -0.0%     -63  [ = ]       0    .debug_str
  +0.0%    +104  +0.0%      +4    TOTAL

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