Skip to content

Commit

Permalink
nix doctor: add warning for multiple versions
Browse files Browse the repository at this point in the history
It's pretty easy to unintentionally install a second version of nix
into the user profile when using a daemon install.  In this case it
looks like nix was upgraded while the nix-daemon is probably still
unning an older version.
  • Loading branch information
LnL7 committed Sep 2, 2018
1 parent 246acf9 commit 0f18dc5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/nix/doctor.cc
Expand Up @@ -33,9 +33,26 @@ struct CmdDoctor : StoreCommand
std::cout << "Store uri: " << store->getUri() << std::endl;
std::cout << std::endl;

checkNixInPath();
checkStoreProtocol(store->getProtocol());
}

void checkNixInPath() {
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)
std::cout << " " << dir << std::endl;
std::cout << std::endl;
}
}

void checkStoreProtocol(unsigned int storeProto) {
auto clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto)
? SERVE_PROTOCOL_VERSION
Expand Down

1 comment on commit 0f18dc5

@nixos-discourse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/fail-multiple-versions-of-nix-found-in-path/19890/16

Please sign in to comment.