aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-08-24 14:49:30 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-08-24 14:49:30 +0200
commit0f314f3c2594e80322c675b70a61dcfda11bf423 (patch)
treeb978499817409cc431b53f27bf180b97561b273d /src/nix
parenta990f063ff7afc6028ab430170ad23e1285d1a6d (diff)
Generate builtins section of the manual
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/main.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 0c4fd46fd..210327927 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -179,11 +179,29 @@ void mainWrapped(int argc, char * * argv)
NixArgs args;
- if (argc == 2 && std::string(argv[1]) == "dump-args") {
+ if (argc == 2 && std::string(argv[1]) == "__dump-args") {
std::cout << args.toJSON().dump() << "\n";
return;
}
+ if (argc == 2 && std::string(argv[1]) == "__dump-builtins") {
+ EvalState state({}, openStore("ssh://foo.invalid/"));
+ auto res = nlohmann::json::object();
+ auto builtins = state.baseEnv.values[0]->attrs;
+ for (auto & builtin : *builtins) {
+ auto b = nlohmann::json::object();
+ if (builtin.value->type != tPrimOp) continue;
+ auto primOp = builtin.value->primOp;
+ if (!primOp->doc) continue;
+ b["arity"] = primOp->arity;
+ b["args"] = primOp->args;
+ b["doc"] = trim(stripIndentation(primOp->doc));
+ res[(std::string) builtin.name] = std::move(b);
+ }
+ std::cout << res.dump() << "\n";
+ return;
+ }
+
Finally printCompletions([&]()
{
if (completions) {