nix/doctor: check flake registry

We try to access to the Flake registry, if we are failing, it's hosed.
Otherwise, let's record some facts we can reuse later.

Towards #230.

Change-Id: I80dd8272d5c27f7f7ff01052e3487a0496ee29fc
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2026-07-03 20:02:35 +02:00
committed by rootile
parent abeefa0e4f
commit b62b37296c
+27
View File
@@ -3,6 +3,7 @@
#include "lix/libcmd/command.hh"
#include "lix/libexpr/eval-settings.hh"
#include "lix/libfetchers/registry.hh"
#include "lix/libutil/logging.hh"
#include "lix/libstore/serve-protocol.hh"
#include "lix/libmain/shared.hh"
@@ -20,6 +21,11 @@ namespace nix {
namespace {
struct FlakeRegistryEntryFacts
{
fetchers::Registry::Entry entry;
};
std::string formatProtocol(unsigned int proto)
{
if (proto) {
@@ -49,6 +55,7 @@ void checkInfo(const std::string & msg) {
struct CmdDoctor : StoreCommand
{
bool success = true;
std::map<std::string, FlakeRegistryEntryFacts> flakeRegistryFacts;
/**
* This command is stable before the others
@@ -83,6 +90,10 @@ struct CmdDoctor : StoreCommand
Path profile = getEnv("NIX_PROFILE").value_or(getDefaultProfile());
checkValidCurrentProfileGeneration(profile);
}
{
printInfo("Collecting information about the Flake registry");
success &= checkFlakeRegistry(store);
}
if (!success)
throw Exit(2);
@@ -156,6 +167,22 @@ struct CmdDoctor : StoreCommand
return true;
}
bool checkFlakeRegistry(ref<Store> store)
{
try {
auto registries = aio().blockOn(fetchers::getRegistries(store));
for (auto & registry : registries) {
for (auto & entry : registry->entries) {
flakeRegistryFacts[entry.from.toURL().to_string()] = {.entry = entry};
}
}
return true;
} catch (...) {
return checkFail("Failed to obtain the Flake registry");
}
}
bool checkNixInPath()
{
PathSet dirs;