nix config check: improve error when no nix-env

It is possible that the `nix` executable is installed but not `nix-env`
(this may be unusual but for example in Fedora we have a separate
`nix-legacy` subpackage, which includes the `nix-env` symlink).

The current error message:
```
$ nix config check --verbose
Running checks against store uri: local
[FAIL] Multiple versions of nix found in PATH:

```
when there is no nix-env in PATH is confusing.

This change makes the error message precise for the missing nix-env case.
This commit is contained in:
Jens Petersen
2026-01-22 12:31:46 +08:00
parent 07a3171fb9
commit 9fa69276c4

View File

@@ -95,7 +95,9 @@ struct CmdConfigCheck : StoreCommand
dirs.insert(std::filesystem::canonical(candidate).parent_path());
}
if (dirs.size() != 1) {
if (dirs.empty()) {
return checkFail("No nix-env found in PATH.");
} else if (dirs.size() > 1) {
std::ostringstream ss;
ss << "Multiple versions of nix found in PATH:\n";
for (auto & dir : dirs)