2018-08-29 22:59:29 +00:00
|
|
|
#include "command.hh"
|
2018-08-30 23:01:59 +00:00
|
|
|
#include "serve-protocol.hh"
|
2018-08-29 22:59:29 +00:00
|
|
|
#include "shared.hh"
|
|
|
|
#include "store-api.hh"
|
2018-08-30 21:42:28 +00:00
|
|
|
#include "worker-protocol.hh"
|
2018-08-29 22:59:29 +00:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
2018-08-30 21:42:28 +00:00
|
|
|
std::string formatProtocol(unsigned int proto)
|
|
|
|
{
|
|
|
|
if (proto) {
|
|
|
|
auto major = GET_PROTOCOL_MAJOR(proto) >> 8;
|
|
|
|
auto minor = GET_PROTOCOL_MINOR(proto);
|
|
|
|
return (format("%1%.%2%") % major % minor).str();
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:59:29 +00:00
|
|
|
struct CmdDoctor : StoreCommand
|
|
|
|
{
|
2018-10-29 12:09:22 +00:00
|
|
|
bool success = true;
|
|
|
|
|
2018-08-29 22:59:29 +00:00
|
|
|
std::string description() override
|
|
|
|
{
|
|
|
|
return "check your system for potential problems";
|
|
|
|
}
|
|
|
|
|
|
|
|
void run(ref<Store> store) override
|
|
|
|
{
|
|
|
|
std::cout << "Store uri: " << store->getUri() << std::endl;
|
2018-08-30 21:42:28 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
2018-09-02 11:14:39 +00:00
|
|
|
auto type = getStoreType();
|
|
|
|
|
|
|
|
if (type < tOther) {
|
2018-10-29 12:09:22 +00:00
|
|
|
success &= checkNixInPath();
|
|
|
|
success &= checkProfileRoots(store);
|
2018-09-02 11:14:39 +00:00
|
|
|
}
|
2018-10-29 12:09:22 +00:00
|
|
|
success &= checkStoreProtocol(store->getProtocol());
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
throw Exit(2);
|
2018-08-30 21:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 12:09:22 +00:00
|
|
|
bool checkNixInPath()
|
2018-09-26 20:59:41 +00:00
|
|
|
{
|
2018-09-01 23:01:23 +00:00
|
|
|
PathSet dirs;
|
|
|
|
|
|
|
|
for (auto & dir : tokenizeString<Strings>(getEnv("PATH"), ":"))
|
|
|
|
if (pathExists(dir + "/nix-env"))
|
|
|
|
dirs.insert(dirOf(canonPath(dir + "/nix-env", true)));
|
|
|
|
|
|
|
|
if (dirs.size() != 1) {
|
|
|
|
std::cout << "Warning: multiple versions of nix found in PATH." << std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
for (auto & dir : dirs)
|
2018-09-02 10:52:04 +00:00
|
|
|
std::cout << " " << dir << std::endl;
|
|
|
|
std::cout << std::endl;
|
2018-10-29 12:09:22 +00:00
|
|
|
return false;
|
2018-09-02 10:52:04 +00:00
|
|
|
}
|
2018-10-29 12:09:22 +00:00
|
|
|
|
|
|
|
return true;
|
2018-09-02 10:52:04 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 12:09:22 +00:00
|
|
|
bool checkProfileRoots(ref<Store> store)
|
2018-09-26 20:59:41 +00:00
|
|
|
{
|
2018-09-02 10:52:04 +00:00
|
|
|
PathSet dirs;
|
|
|
|
|
2018-09-26 20:59:41 +00:00
|
|
|
for (auto & dir : tokenizeString<Strings>(getEnv("PATH"), ":")) {
|
|
|
|
Path profileDir = dirOf(dir);
|
2018-09-02 10:52:04 +00:00
|
|
|
try {
|
2018-09-26 20:59:41 +00:00
|
|
|
Path userEnv = canonPath(profileDir, true);
|
2018-09-02 10:52:04 +00:00
|
|
|
|
2018-09-26 20:59:41 +00:00
|
|
|
if (store->isStorePath(userEnv) && hasSuffix(userEnv, "user-environment")) {
|
|
|
|
while (profileDir.find("/profiles/") == std::string::npos && isLink(profileDir))
|
|
|
|
profileDir = absPath(readLink(profileDir), dirOf(profileDir));
|
|
|
|
|
|
|
|
if (profileDir.find("/profiles/") == std::string::npos)
|
|
|
|
dirs.insert(dir);
|
2018-09-02 10:52:04 +00:00
|
|
|
}
|
|
|
|
} catch (SysError &) {}
|
2018-09-26 20:59:41 +00:00
|
|
|
}
|
2018-09-02 10:52:04 +00:00
|
|
|
|
|
|
|
if (!dirs.empty()) {
|
2018-09-26 20:59:41 +00:00
|
|
|
std::cout << "Warning: found profiles outside of " << settings.nixStateDir << "/profiles." << std::endl;
|
|
|
|
std::cout << "The generation this profile points to might not have a gcroot and could be" << std::endl;
|
|
|
|
std::cout << "garbage collected, resulting in broken symlinks." << std::endl;
|
2018-09-02 10:52:04 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
for (auto & dir : dirs)
|
2018-09-01 23:01:23 +00:00
|
|
|
std::cout << " " << dir << std::endl;
|
|
|
|
std::cout << std::endl;
|
2018-10-29 12:09:22 +00:00
|
|
|
return false;
|
2018-09-01 23:01:23 +00:00
|
|
|
}
|
2018-10-29 12:09:22 +00:00
|
|
|
|
|
|
|
return true;
|
2018-09-01 23:01:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 12:09:22 +00:00
|
|
|
bool checkStoreProtocol(unsigned int storeProto)
|
2018-09-26 20:59:41 +00:00
|
|
|
{
|
2018-10-27 11:07:26 +00:00
|
|
|
unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto)
|
2018-08-30 23:01:59 +00:00
|
|
|
? SERVE_PROTOCOL_VERSION
|
|
|
|
: PROTOCOL_VERSION;
|
|
|
|
|
|
|
|
if (clientProto != storeProto) {
|
2018-08-30 21:42:28 +00:00
|
|
|
std::cout << "Warning: protocol version of this client does not match the store." << std::endl;
|
|
|
|
std::cout << "While this is not necessarily a problem it's recommended to keep the client in" << std::endl;
|
|
|
|
std::cout << "sync with the daemon." << std::endl;
|
|
|
|
std::cout << std::endl;
|
2018-08-30 23:01:59 +00:00
|
|
|
std::cout << "Client protocol: " << formatProtocol(clientProto) << std::endl;
|
|
|
|
std::cout << "Store protocol: " << formatProtocol(storeProto) << std::endl;
|
2018-08-30 21:42:28 +00:00
|
|
|
std::cout << std::endl;
|
2018-10-29 12:09:22 +00:00
|
|
|
return false;
|
2018-08-30 21:42:28 +00:00
|
|
|
}
|
2018-10-29 12:09:22 +00:00
|
|
|
|
|
|
|
return true;
|
2018-08-29 22:59:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-18 14:01:35 +00:00
|
|
|
static auto r1 = registerCommand<CmdDoctor>("doctore");
|