Nix
Static Analysis
Static Analysis
Nix uses clang-tidy for static analysis of C++ code. This helps catch bugs, enforce coding standards, and maintain code quality.
Running clang-tidy locally
To run clang-tidy on the entire codebase in the development shell:
$ nix develop .#native-clangStdenv
$ configurePhase
$ meson compile -C build clang-tidy
This will analyze all C++ source files and report any warnings.
To automatically apply fixes for certain warnings:
$ meson compile -C build clang-tidy-fix
Warning
Review the changes before committing, as automatic fixes may not always be correct.
CI integration
clang-tidy runs automatically on every pull request via GitHub Actions.
The CI job builds .#hydraJobs.clangTidy.x86_64-linux which:
- Builds all components with debug mode (for faster compilation)
- Runs clang-tidy on each component
- Fails if any warnings are found (warnings are treated as errors)
Configuration
The clang-tidy configuration is in .clang-tidy at the repository root (symlinked from nix-meson-build-support/common/clang-tidy/.clang-tidy).
Suppressing warnings
If a warning is a false positive, you can suppress it in several ways:
Inline suppression (preferred for specific cases):
// NOLINTBEGIN(bugprone-some-check) ... code ... // NOLINTEND(bugprone-some-check)Or for a single line:
int x = something(); // NOLINT(bugprone-some-check)Configuration file (for project-wide suppression): Add the check to the disabled list in
.clang-tidy:Checks: - -bugprone-some-check # Reason for disablingCheck options (for configuring check behavior):
CheckOptions: bugprone-reserved-identifier.AllowedIdentifiers: '__some_identifier'
Adding new checks
To enable additional checks:
- Edit
nix-meson-build-support/common/clang-tidy/.clang-tidy - Add the check to the
Checkslist - Run clang-tidy locally to see the impact
- Fix any new warnings or disable specific sub-checks if needed
Custom clang-tidy plugin
The Nix project includes infrastructure for custom clang-tidy checks in src/clang-tidy-plugin/.
These checks can enforce Nix-specific coding patterns that aren't covered by standard clang-tidy checks.
To add a new custom check:
- Add the check implementation in
src/clang-tidy-plugin/ - Register it in
nix-clang-tidy-checks.cc - Enable it in
.clang-tidywith thenix-prefix