From 247f4425b9f11e5176be084b76f38ca7ca632870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Tue, 15 Sep 2026 01:46:34 +0200 Subject: [PATCH 1/3] llvmPackages.clang-tools: ensure wrapper uses bash The wrapper script relies on features only available with bash, namely arithmetic evaluation as in `while (( $# )); do`. So let's ensure that the shebang is patched to use bash. (bash's POSIX `sh` evaluates this as intended.) A minimal reproducer with a project that generally ought to pass clang-tidy checking may look like so: ```nix { pkgs ? import { }, }: pkgs.fwupd.overrideAttrs ( final: prev: { nativeBuildInputs = prev.nativeBuildInputs ++ [ pkgs.clang-tools ]; preCheck = '' ninja clang-tidy ''; } ) ``` Before, you may see many errors about missing headers and some lines that suspiciously look like bash errors. ``` fwupd> >>> /nix/store/gf6qdh329rc8lbby710r9rzhwqkkgv3h-clang-tools-21.1.8/bin/clang-tidy --use-color -quiet -p /build/source/build /build/source/plugins/uf2/fu-self-test.c fwupd> /nix/store/gf6qdh329rc8lbby710r9rzhwqkkgv3h-clang-tools-21.1.8/bin/clang-tidy: line 5: 129: not found fwupd> /nix/store/gf6qdh329rc8lbby710r9rzhwqkkgv3h-clang-tools-21.1.8/bin/clang-tidy: line 23: 129: not found fwupd> 276 warnings and 1 error generated. fwupd> Error while processing /build/source/plugins/uf2/fu-self-test.c. fwupd> /nix/store/dm7fg33sqnjxkwdpirnnbnx7wyi89m82-glib-2.88.3-dev/include/glib-2.0/glib/gtypes.h:41:10: error: 'time.h' file not found [clang-diagnostic-error] fwupd> 41 | #include fwupd> | ^~~~~~~~ ``` With this change, these clang-tidy errors no longer appear. --- pkgs/development/compilers/llvm/common/clang-tools/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/clang-tools/default.nix b/pkgs/development/compilers/llvm/common/clang-tools/default.nix index 91daa95d07cf..74523db10b80 100644 --- a/pkgs/development/compilers/llvm/common/clang-tools/default.nix +++ b/pkgs/development/compilers/llvm/common/clang-tools/default.nix @@ -3,6 +3,7 @@ stdenv, runCommand, writeText, + bashNonInteractive, clang-unwrapped, clang, libcxxClang, @@ -20,6 +21,8 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; __structuredAttrs = true; + buildInputs = [ bashNonInteractive ]; + installPhase = '' runHook preInstall From c37c7bbcdb0d1bb51bc497f85194f97be2bf859b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Thu, 17 Sep 2026 00:52:48 +0200 Subject: [PATCH 2/3] llvmPackages.clang-tools: use correct shell shebang This wrapper is factually a bash script and should therefore use the correct shebang instead of relying on the leniency of the bash POSIX mode. --- pkgs/development/compilers/llvm/common/clang-tools/wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/common/clang-tools/wrapper b/pkgs/development/compilers/llvm/common/clang-tools/wrapper index 6601d6875f8e..247d858b9488 100755 --- a/pkgs/development/compilers/llvm/common/clang-tools/wrapper +++ b/pkgs/development/compilers/llvm/common/clang-tools/wrapper @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash buildcpath() { local path after From 5bf21ff317f377d7dd3e417e3b583d15852a3a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Thu, 17 Sep 2026 00:55:02 +0200 Subject: [PATCH 3/3] llvmPackages.clang-tools: add test for clang-tidy While the wrapper's bash script was broken, clang-tidy would have failed to check a project with an include such as assert.h because it wouldn't have been able to find that header file. --- .../compilers/llvm/common/clang-tools/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/clang-tools/default.nix b/pkgs/development/compilers/llvm/common/clang-tools/default.nix index 74523db10b80..4fab7f98164d 100644 --- a/pkgs/development/compilers/llvm/common/clang-tools/default.nix +++ b/pkgs/development/compilers/llvm/common/clang-tools/default.nix @@ -66,9 +66,11 @@ stdenv.mkDerivation (finalAttrs: { passthru.tests = let src = writeText "main.cpp" '' + #include #include int main() { + assert(true); std::cout << "Hi!"; } ''; @@ -79,6 +81,10 @@ stdenv.mkDerivation (finalAttrs: { ${finalAttrs.finalPackage}/bin/clangd --check=${src} touch $out ''; + smokeOkClangTidy = runCommand "clang-tidy-test-smoke-ok" { } '' + ${finalAttrs.finalPackage}/bin/clang-tidy ${src} + touch $out + ''; smokeErr = runCommand "clang-tools-test-smoke-err" { } '' (${finalAttrs.finalPackage}/bin/clangd --query-driver='**' --check=${src} 2>&1 || true) \ | grep 'use of undeclared identifier'