about summary refs log tree commit diff
path: root/src/nix/doctor.cc
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2018-09-01T23·01+0200
committerDaiderd Jordan <daiderd@gmail.com>2018-09-02T10·56+0200
commit0f18dc54797a1850bc1b91673790ad73e8f4b82f (patch)
tree9dbc8d5bb1decbcfc28d888cd0a49ecf2d310bf4 /src/nix/doctor.cc
parent246acf93f2b61b2915e2140d761b19c2e836a96e (diff)
nix doctor: add warning for multiple versions
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.
Diffstat (limited to 'src/nix/doctor.cc')
-rw-r--r--src/nix/doctor.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nix/doctor.cc b/src/nix/doctor.cc
index a31df595da88..6265e9cfef20 100644
--- a/src/nix/doctor.cc
+++ b/src/nix/doctor.cc
@@ -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