Skip to content

Commit

Permalink
doctor: print [INFO] for checkTrustedUser()
Browse files Browse the repository at this point in the history
Adds a new function checkInfo which prints with no consequence to
the exit code, we then use it to print whether the Nix client is a
trusted-user on the store
  • Loading branch information
MatthewCroughan committed Dec 30, 2022
1 parent 0f799fd commit 0d28385
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
* New command: `nix store check-trusted`, which checks if you are a
trusted-user, returning 1 or 0. This is useful for scripting interactions with
remote Nix stores.

* `nix doctor` now prints `[INFO]` instead of just `[PASS]` or `[FAIL]` and will
use the `nix store check-trusted` function to print whether you are a
trusted-user or not.
14 changes: 14 additions & 0 deletions src/nix/doctor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ bool checkFail(const std::string & msg) {
return false;
}

void checkInfo(const std::string & msg) {
notice(ANSI_BLUE "[INFO] " ANSI_NORMAL + msg);
}

}

struct CmdDoctor : StoreCommand
Expand All @@ -55,6 +59,7 @@ struct CmdDoctor : StoreCommand
success &= checkProfileRoots(store);
}
success &= checkStoreProtocol(store->getProtocol());
checkTrustedUser(store);

if (!success)
throw Exit(2);
Expand Down Expand Up @@ -130,6 +135,15 @@ struct CmdDoctor : StoreCommand

return checkPass("Client protocol matches store protocol.");
}

void checkTrustedUser(ref<Store> store)
{
bool trusted = store->isTrustedUser();
if (trusted)
checkInfo("You are a trusted-user on store uri: " + store->getUri());
if (!trusted)
checkInfo("You are not a trusted-user on store uri: " + store->getUri());
}
};

static auto rCmdDoctor = registerCommand<CmdDoctor>("doctor");

0 comments on commit 0d28385

Please sign in to comment.