Dev shell flake clangd can't find gnu/stubs-32.h

I am creating a dev environment for the pico debugprobe project, and somehow my LSP is complaining that it can’t find gnu/stubs-32.h

This is my devShell:

{
  description = "Raspberry Pi Pico development environment";
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:s1syph0s/nixpkgs"; # just a fork with pico-sdk update since it's outdated
  };

  outputs = { self, flake-utils, nixpkgs }:
    flake-utils.lib.eachDefaultSystem (system: 
      let
        pico-sdk-overlay = final: prev: {
          pico-sdk = prev.pico-sdk.override {
            withSubmodules = true;
          };
        };
        pkgs = nixpkgs.legacyPackages.${system}.extend pico-sdk-overlay;
      in {
        devShell = with pkgs; mkShell ({
          packages = [ 
            cmake
            pkgsCross.arm-embedded.stdenv.cc
            pico-sdk
            ninja
            python3
          ];
          PICO_SDK_PATH = "${pico-sdk}/lib/pico-sdk";
        });
      }
    );
}

I thought that the header is included in the arm-embedded.stdenv.cc package, but it’s not found. building the project is not a problem.

The error that i get, because it’s couldn’t find gnu/stubs-32.h:

I tried adding pkgsi868Linux.glibc to the devShell according to this comment, but that creates another error.

Adding pkgsi868Linux.glibc solves the gnu/stubs-32.h error, but leads to another error:

The errors:


This is because the clang-tools package is a wrapper that injects the buildPlatform’s glibc to clangd’s C_INCLUDE_PATH, while the actual libc for pkgsCross.arm-embedded is newlib.

To fix this, I have to 1. remove glibc from clangd’s search path, 2. add newlib to clangd’s search path. The canonical method for 2 is --query-driver. The easiest way I can think of is to make my own wrapper for clangd to mask the one from clang-tools:

(lib.hiPrio (
  pkgsBuildBuild.writeShellScriptBin "clangd" ''
    ${pkgsBuildBuild.llvmPackages.clang-unwrapped}/bin/clangd --query-driver="$(command -v $CC)" "$@"
  ''
))
pkgsBuildBuild.clang-tools # The rest of the package

A recent PR clang-tools: Improve wrapper script, add tests by Patryk27 · Pull Request #354755 · NixOS/nixpkgs · GitHub added a condition check to the wrapper: if user passed --query-driver, don’t inject search paths. I’m still on nixos-25.11, but if you are on nixos-unstable, you should be able to have some sort of project-specific Neovim config to do this:

vim.lsp.config('clangd', {cmd={'clangd', '--query-driver=...'}})