From 7bc3d9b9a9ba1f84a5b6b631143276be767234a4 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 14 Oct 2025 22:53:13 -0400 Subject: [PATCH 1/4] First attempt at uwyu for libflake --- packaging/dev-shell.nix | 1 + src/libflake/config.cc | 27 +++++++++- src/libflake/flake-primops.cc | 26 +++++++++ src/libflake/flake.cc | 52 ++++++++++++++++-- src/libflake/flakeref.cc | 20 ++++++- .../include/nix/flake/flake-primops.hh | 6 +++ src/libflake/include/nix/flake/flakeref.hh | 14 +++++ src/libflake/include/nix/flake/settings.hh | 7 ++- src/libflake/include/nix/flake/url-name.hh | 4 ++ src/libflake/lockfile.cc | 54 +++++++++++++++---- src/libflake/settings.cc | 4 ++ src/libflake/url-name.cc | 6 ++- 12 files changed, 201 insertions(+), 20 deletions(-) diff --git a/packaging/dev-shell.nix b/packaging/dev-shell.nix index 37e92e363..7eec45bfb 100644 --- a/packaging/dev-shell.nix +++ b/packaging/dev-shell.nix @@ -124,6 +124,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs ( (pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript) pkgs.buildPackages.nixfmt-rfc-style pkgs.buildPackages.shellcheck + pkgs.buildPackages.include-what-you-use pkgs.buildPackages.gdb ] ++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) ( diff --git a/src/libflake/config.cc b/src/libflake/config.cc index c9071f601..08e6ff038 100644 --- a/src/libflake/config.cc +++ b/src/libflake/config.cc @@ -1,9 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "nix/util/users.hh" #include "nix/util/config-global.hh" #include "nix/flake/settings.hh" #include "nix/flake/flake.hh" - -#include +#include "nix/util/ansicolor.hh" +#include "nix/util/configuration.hh" +#include "nix/util/file-system.hh" +#include "nix/util/fmt.hh" +#include "nix/util/logging.hh" +#include "nix/util/strings.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" namespace nix::flake { diff --git a/src/libflake/flake-primops.cc b/src/libflake/flake-primops.cc index 7c5ce01b2..eeff9a966 100644 --- a/src/libflake/flake-primops.cc +++ b/src/libflake/flake-primops.cc @@ -1,8 +1,34 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "nix/flake/flake-primops.hh" #include "nix/expr/eval.hh" #include "nix/flake/flake.hh" #include "nix/flake/flakeref.hh" #include "nix/flake/settings.hh" +#include "nix/expr/attr-set.hh" +#include "nix/expr/eval-error.hh" +#include "nix/expr/eval-inline.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/expr/value.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/configuration.hh" +#include "nix/util/error.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/pos-idx.hh" +#include "nix/util/pos-table.hh" +#include "nix/util/source-path.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" namespace nix::flake::primops { diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index 147bff820..ae93f2f39 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -1,3 +1,26 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "nix/util/terminal.hh" #include "nix/util/ref.hh" #include "nix/util/environment-variables.hh" @@ -6,7 +29,6 @@ #include "nix/expr/eval-cache.hh" #include "nix/expr/eval-settings.hh" #include "nix/flake/lockfile.hh" -#include "nix/expr/primops.hh" #include "nix/expr/eval-inline.hh" #include "nix/store/store-api.hh" #include "nix/fetchers/fetchers.hh" @@ -14,14 +36,36 @@ #include "nix/fetchers/fetch-settings.hh" #include "nix/flake/settings.hh" #include "nix/expr/value-to-json.hh" -#include "nix/store/local-fs-store.hh" #include "nix/fetchers/fetch-to-store.hh" #include "nix/util/memory-source-accessor.hh" #include "nix/fetchers/input-cache.hh" - -#include +#include "nix/expr/attr-set.hh" +#include "nix/expr/eval-error.hh" +#include "nix/expr/nixexpr.hh" +#include "nix/expr/symbol-table.hh" +#include "nix/expr/value.hh" +#include "nix/expr/value/context.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/fetchers/registry.hh" +#include "nix/flake/flakeref.hh" +#include "nix/store/path.hh" +#include "nix/util/canon-path.hh" +#include "nix/util/configuration.hh" +#include "nix/util/error.hh" +#include "nix/util/experimental-features.hh" +#include "nix/util/file-system.hh" +#include "nix/util/fmt.hh" +#include "nix/util/hash.hh" +#include "nix/util/logging.hh" +#include "nix/util/pos-idx.hh" +#include "nix/util/pos-table.hh" +#include "nix/util/position.hh" +#include "nix/util/source-path.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" namespace nix { +struct SourceAccessor; using namespace flake; diff --git a/src/libflake/flakeref.cc b/src/libflake/flakeref.cc index 38979783d..a3448c88d 100644 --- a/src/libflake/flakeref.cc +++ b/src/libflake/flakeref.cc @@ -1,10 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "nix/flake/flakeref.hh" -#include "nix/store/store-api.hh" #include "nix/util/url.hh" #include "nix/util/url-parts.hh" #include "nix/fetchers/fetchers.hh" +#include "nix/util/error.hh" +#include "nix/util/file-system.hh" +#include "nix/util/fmt.hh" +#include "nix/util/logging.hh" +#include "nix/util/strings.hh" +#include "nix/util/util.hh" namespace nix { +namespace fetchers { +struct Settings; +} // namespace fetchers #if 0 // 'dir' path elements cannot start with a '.'. We also reject diff --git a/src/libflake/include/nix/flake/flake-primops.hh b/src/libflake/include/nix/flake/flake-primops.hh index 35a7128f4..57a5e3422 100644 --- a/src/libflake/include/nix/flake/flake-primops.hh +++ b/src/libflake/include/nix/flake/flake-primops.hh @@ -3,6 +3,12 @@ #include "nix/expr/eval.hh" #include "nix/flake/settings.hh" +namespace nix { +namespace flake { +struct Settings; +} // namespace flake +} // namespace nix + namespace nix::flake::primops { /** diff --git a/src/libflake/include/nix/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh index c8c536bce..7a26382a7 100644 --- a/src/libflake/include/nix/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -1,16 +1,30 @@ #pragma once ///@file +#include #include +#include +#include +#include +#include +#include +#include +#include #include "nix/util/types.hh" #include "nix/fetchers/fetchers.hh" #include "nix/store/outputs-spec.hh" #include "nix/fetchers/registry.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/util/ref.hh" +#include "nix/util/source-accessor.hh" namespace nix { class Store; +namespace fetchers { +struct Settings; +} // namespace fetchers typedef std::string FlakeId; diff --git a/src/libflake/include/nix/flake/settings.hh b/src/libflake/include/nix/flake/settings.hh index 618ed4d38..7e5d18746 100644 --- a/src/libflake/include/nix/flake/settings.hh +++ b/src/libflake/include/nix/flake/settings.hh @@ -1,9 +1,12 @@ #pragma once ///@file -#include "nix/util/configuration.hh" - #include +#include +#include + +#include "nix/util/configuration.hh" +#include "nix/util/experimental-features.hh" namespace nix { // Forward declarations diff --git a/src/libflake/include/nix/flake/url-name.hh b/src/libflake/include/nix/flake/url-name.hh index b95d2dff6..0c79b74aa 100644 --- a/src/libflake/include/nix/flake/url-name.hh +++ b/src/libflake/include/nix/flake/url-name.hh @@ -1,9 +1,13 @@ +#include +#include + #include "nix/util/url.hh" #include "nix/util/url-parts.hh" #include "nix/util/util.hh" #include "nix/util/split.hh" namespace nix { +struct ParsedURL; /** * Try to extract a reasonably unique and meaningful, human-readable diff --git a/src/libflake/lockfile.cc b/src/libflake/lockfile.cc index f381a57e6..421f872cc 100644 --- a/src/libflake/lockfile.cc +++ b/src/libflake/lockfile.cc @@ -1,15 +1,51 @@ -#include "nix/fetchers/fetch-settings.hh" -#include "nix/flake/settings.hh" -#include "nix/flake/lockfile.hh" -#include "nix/store/store-api.hh" -#include "nix/util/strings.hh" - +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include - -#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nix/fetchers/fetch-settings.hh" +#include "nix/flake/lockfile.hh" +#include "nix/util/strings.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/flake/flakeref.hh" +#include "nix/store/path.hh" +#include "nix/util/ansicolor.hh" +#include "nix/util/configuration.hh" +#include "nix/util/error.hh" +#include "nix/util/fmt.hh" +#include "nix/util/hash.hh" +#include "nix/util/logging.hh" +#include "nix/util/ref.hh" +#include "nix/util/types.hh" +#include "nix/util/util.hh" + +namespace nix { +class Store; +} // namespace nix namespace nix::flake { diff --git a/src/libflake/settings.cc b/src/libflake/settings.cc index e77bded30..52fa1b49d 100644 --- a/src/libflake/settings.cc +++ b/src/libflake/settings.cc @@ -1,5 +1,9 @@ +#include + #include "nix/flake/settings.hh" #include "nix/flake/flake-primops.hh" +#include "nix/expr/eval-settings.hh" +#include "nix/expr/eval.hh" namespace nix::flake { diff --git a/src/libflake/url-name.cc b/src/libflake/url-name.cc index 3bba3692e..a63b107c3 100644 --- a/src/libflake/url-name.cc +++ b/src/libflake/url-name.cc @@ -1,6 +1,8 @@ -#include "nix/flake/url-name.hh" #include -#include + +#include "nix/flake/url-name.hh" +#include "nix/util/strings.hh" +#include "nix/util/url.hh" namespace nix { From 902faf4fe5d0d0b8947f0001c66c4d67e5282e08 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 14 Oct 2025 23:20:35 -0400 Subject: [PATCH 2/4] More fixes for iwyu --- src/libflake/config.cc | 4 +--- src/libflake/flake.cc | 6 ++---- src/libflake/flakeref.cc | 15 +++++++++++++-- src/libflake/lockfile.cc | 2 -- src/libflake/url-name.cc | 2 ++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/libflake/config.cc b/src/libflake/config.cc index 08e6ff038..c248ed0a6 100644 --- a/src/libflake/config.cc +++ b/src/libflake/config.cc @@ -1,19 +1,17 @@ #include #include #include -#include -#include #include #include #include #include #include #include -#include #include #include #include #include +#include #include "nix/util/users.hh" #include "nix/util/config-global.hh" diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index ae93f2f39..8e7e2be26 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include #include @@ -12,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +17,7 @@ #include #include #include +#include #include "nix/util/terminal.hh" #include "nix/util/ref.hh" @@ -909,7 +907,7 @@ static ref makeInternalFS() internalFS->setPathDisplay("«flakes-internal»", ""); internalFS->addFile( CanonPath("call-flake.nix"), -#include "call-flake.nix.gen.hh" +#include "call-flake.nix.gen.hh" // IWYU pragma: keep ); return internalFS; } diff --git a/src/libflake/flakeref.cc b/src/libflake/flakeref.cc index a3448c88d..b4a5c106e 100644 --- a/src/libflake/flakeref.cc +++ b/src/libflake/flakeref.cc @@ -1,12 +1,15 @@ #include #include #include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include #include "nix/flake/flakeref.hh" #include "nix/util/url.hh" @@ -18,8 +21,16 @@ #include "nix/util/logging.hh" #include "nix/util/strings.hh" #include "nix/util/util.hh" +#include "nix/fetchers/attrs.hh" +#include "nix/fetchers/registry.hh" +#include "nix/store/outputs-spec.hh" +#include "nix/util/ref.hh" +#include "nix/util/types.hh" namespace nix { +class Store; +struct SourceAccessor; + namespace fetchers { struct Settings; } // namespace fetchers diff --git a/src/libflake/lockfile.cc b/src/libflake/lockfile.cc index 421f872cc..fbf17a383 100644 --- a/src/libflake/lockfile.cc +++ b/src/libflake/lockfile.cc @@ -1,8 +1,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/libflake/url-name.cc b/src/libflake/url-name.cc index a63b107c3..f4b5c6a7f 100644 --- a/src/libflake/url-name.cc +++ b/src/libflake/url-name.cc @@ -1,4 +1,6 @@ #include +#include +#include #include "nix/flake/url-name.hh" #include "nix/util/strings.hh" From e8b126fa909e9745cbc0f4cdcc99a2a5d05258d4 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 14 Oct 2025 23:43:33 -0400 Subject: [PATCH 3/4] Remove unecessary includes --- src/libflake-tests/flakeref.cc | 7 +++++++ src/libflake-tests/nix_api_flake.cc | 12 +++++++----- src/libflake-tests/url-name.cc | 4 +++- src/libflake/include/nix/flake/flake-primops.hh | 1 - src/libflake/include/nix/flake/flakeref.hh | 9 --------- src/libflake/include/nix/flake/settings.hh | 2 -- src/libflake/include/nix/flake/url-name.hh | 5 ----- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/libflake-tests/flakeref.cc b/src/libflake-tests/flakeref.cc index e2cb91bb8..34d281c52 100644 --- a/src/libflake-tests/flakeref.cc +++ b/src/libflake-tests/flakeref.cc @@ -1,8 +1,15 @@ #include +#include +#include +#include #include "nix/fetchers/fetch-settings.hh" #include "nix/flake/flakeref.hh" #include "nix/fetchers/attrs.hh" +#include "nix/fetchers/fetchers.hh" +#include "nix/util/configuration.hh" +#include "nix/util/error.hh" +#include "nix/util/experimental-features.hh" namespace nix { diff --git a/src/libflake-tests/nix_api_flake.cc b/src/libflake-tests/nix_api_flake.cc index f7e0cb719..da7f01401 100644 --- a/src/libflake-tests/nix_api_flake.cc +++ b/src/libflake-tests/nix_api_flake.cc @@ -1,15 +1,17 @@ +#include +#include +#include + #include "nix/util/file-system.hh" #include "nix_api_store.h" #include "nix_api_util.h" #include "nix_api_expr.h" #include "nix_api_value.h" #include "nix_api_flake.h" - -#include "nix/expr/tests/nix_api_expr.hh" #include "nix/util/tests/string_callback.hh" - -#include -#include +#include "nix/store/tests/nix_api_store.hh" +#include "nix/util/tests/nix_api_util.hh" +#include "nix_api_fetchers.h" namespace nixC { diff --git a/src/libflake-tests/url-name.cc b/src/libflake-tests/url-name.cc index 81ba516c8..64cbe5c9d 100644 --- a/src/libflake-tests/url-name.cc +++ b/src/libflake-tests/url-name.cc @@ -1,6 +1,8 @@ -#include "nix/flake/url-name.hh" #include +#include "nix/flake/url-name.hh" +#include "nix/util/url.hh" + namespace nix { /* ----------- tests for url-name.hh --------------------------------------------------*/ diff --git a/src/libflake/include/nix/flake/flake-primops.hh b/src/libflake/include/nix/flake/flake-primops.hh index 57a5e3422..a2a3d1612 100644 --- a/src/libflake/include/nix/flake/flake-primops.hh +++ b/src/libflake/include/nix/flake/flake-primops.hh @@ -1,7 +1,6 @@ #pragma once #include "nix/expr/eval.hh" -#include "nix/flake/settings.hh" namespace nix { namespace flake { diff --git a/src/libflake/include/nix/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh index 7a26382a7..65a2dfed5 100644 --- a/src/libflake/include/nix/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -1,23 +1,14 @@ #pragma once ///@file -#include #include -#include #include -#include #include #include #include -#include -#include "nix/util/types.hh" -#include "nix/fetchers/fetchers.hh" #include "nix/store/outputs-spec.hh" #include "nix/fetchers/registry.hh" -#include "nix/fetchers/attrs.hh" -#include "nix/util/ref.hh" -#include "nix/util/source-accessor.hh" namespace nix { diff --git a/src/libflake/include/nix/flake/settings.hh b/src/libflake/include/nix/flake/settings.hh index 7e5d18746..7187a3294 100644 --- a/src/libflake/include/nix/flake/settings.hh +++ b/src/libflake/include/nix/flake/settings.hh @@ -2,11 +2,9 @@ ///@file #include -#include #include #include "nix/util/configuration.hh" -#include "nix/util/experimental-features.hh" namespace nix { // Forward declarations diff --git a/src/libflake/include/nix/flake/url-name.hh b/src/libflake/include/nix/flake/url-name.hh index 0c79b74aa..d313db33b 100644 --- a/src/libflake/include/nix/flake/url-name.hh +++ b/src/libflake/include/nix/flake/url-name.hh @@ -1,11 +1,6 @@ #include #include -#include "nix/util/url.hh" -#include "nix/util/url-parts.hh" -#include "nix/util/util.hh" -#include "nix/util/split.hh" - namespace nix { struct ParsedURL; From 01a8499d2f7baede36827cc6138468329757551f Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 14 Oct 2025 23:51:40 -0400 Subject: [PATCH 4/4] Format cpp files --- src/libflake/flakeref.cc | 2 +- src/libflake/include/nix/flake/flake-primops.hh | 4 ++-- src/libflake/include/nix/flake/flakeref.hh | 3 ++- src/libflake/lockfile.cc | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libflake/flakeref.cc b/src/libflake/flakeref.cc index b4a5c106e..a26f269c3 100644 --- a/src/libflake/flakeref.cc +++ b/src/libflake/flakeref.cc @@ -33,7 +33,7 @@ struct SourceAccessor; namespace fetchers { struct Settings; -} // namespace fetchers +} // namespace fetchers #if 0 // 'dir' path elements cannot start with a '.'. We also reject diff --git a/src/libflake/include/nix/flake/flake-primops.hh b/src/libflake/include/nix/flake/flake-primops.hh index a2a3d1612..b333e33d7 100644 --- a/src/libflake/include/nix/flake/flake-primops.hh +++ b/src/libflake/include/nix/flake/flake-primops.hh @@ -5,8 +5,8 @@ namespace nix { namespace flake { struct Settings; -} // namespace flake -} // namespace nix +} // namespace flake +} // namespace nix namespace nix::flake::primops { diff --git a/src/libflake/include/nix/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh index 65a2dfed5..1af8c5afd 100644 --- a/src/libflake/include/nix/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -13,9 +13,10 @@ namespace nix { class Store; + namespace fetchers { struct Settings; -} // namespace fetchers +} // namespace fetchers typedef std::string FlakeId; diff --git a/src/libflake/lockfile.cc b/src/libflake/lockfile.cc index fbf17a383..d3dac19c5 100644 --- a/src/libflake/lockfile.cc +++ b/src/libflake/lockfile.cc @@ -43,7 +43,7 @@ namespace nix { class Store; -} // namespace nix +} // namespace nix namespace nix::flake {