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 <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2026-07-03 20:12:07 +02:00
committed by rootile
parent b62b37296c
commit 12f10fca7e
+41
View File
@@ -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<std::string, SearchPathFacts> searchPathFacts;
std::map<std::string, FlakeRegistryEntryFacts> 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;