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 Jan 19, 2023
1 parent 8f8c234 commit a13a7c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
* New command: `nix store check-trusted-user`, 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 displays 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 a13a7c3

Please sign in to comment.