From 12f10fca7e1e6e7fda6cad9db9fb9237dbcc4df1 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Mon, 2 Mar 2026 19:42:37 +0100 Subject: [PATCH] nix/doctor: check ambient search paths Some issues are caused by users confused about their ambient search paths, let's analyze the current configuration and make it awfully obvious what is going on. Towards #230. Change-Id: I953ef3feaefc56cee68623c5aaa4d568ba1fd034 Signed-off-by: Raito Bezarius --- lix/nix/doctor.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lix/nix/doctor.cc b/lix/nix/doctor.cc index 119a5c899..b7a36df36 100644 --- a/lix/nix/doctor.cc +++ b/lix/nix/doctor.cc @@ -3,6 +3,7 @@ #include "lix/libcmd/command.hh" #include "lix/libexpr/eval-settings.hh" +#include "lix/libexpr/search-path.hh" #include "lix/libfetchers/registry.hh" #include "lix/libutil/logging.hh" #include "lix/libstore/serve-protocol.hh" @@ -21,11 +22,24 @@ namespace nix { namespace { +enum SearchPathBackingType { + Channel, + FlakeRegistry, + FlakeRef, + FilesystemPath, + Other, +}; + struct FlakeRegistryEntryFacts { fetchers::Registry::Entry entry; }; +struct SearchPathFacts +{ + std::string originReference; +}; + std::string formatProtocol(unsigned int proto) { if (proto) { @@ -55,6 +69,7 @@ void checkInfo(const std::string & msg) { struct CmdDoctor : StoreCommand { bool success = true; + std::map searchPathFacts; std::map flakeRegistryFacts; /** @@ -94,6 +109,10 @@ struct CmdDoctor : StoreCommand printInfo("Collecting information about the Flake registry"); success &= checkFlakeRegistry(store); } + { + printInfo("Collecting information about the ambient Nix search paths"); + success &= checkAmbientNixSearchPaths(); + } if (!success) throw Exit(2); @@ -183,6 +202,28 @@ struct CmdDoctor : StoreCommand } } + bool checkAmbientNixSearchPaths() + { + bool nixPathOverridden = evalSettings.nixPath.overridden; + bool influencedByEnvironment = getEnvNonEmpty("NIX_PATH") == std::nullopt; + + auto nixPathS = concatStringsSep(", ", evalSettings.nixPath.get()); + + if (nixPathOverridden) { + if (influencedByEnvironment) { + checkInfo(fmt( + "Default (influenced by $NIX_PATH) Nix configuration search path: %s", nixPathS + )); + } else { + checkInfo(fmt("Default Nix configuration search path: %s", nixPathS)); + } + } else { + checkInfo(fmt("Overridden Nix configuration search path: %s", nixPathS)); + } + + return true; + } + bool checkNixInPath() { PathSet dirs;