1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

nix flake show: Support meta attribute for apps

Metadata information for flake apps will be useful while exploring a
flake using `nix flake show`
This commit is contained in:
shivaraj-bh 2024-08-14 14:57:34 +05:30
parent 2ed075ffc0
commit a5f6ee8550
2 changed files with 12 additions and 3 deletions

View file

@ -1251,8 +1251,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
} }
j.emplace("type", "derivation"); j.emplace("type", "derivation");
j.emplace("name", name); j.emplace("name", name);
if (description) j.emplace("description", description ? *description : "");
j.emplace("description", *description);
} else { } else {
logger->cout("%s: %s '%s'", logger->cout("%s: %s '%s'",
headerPrefix, headerPrefix,
@ -1340,12 +1339,19 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
(attrPath.size() == 3 && attrPathS[0] == "apps")) (attrPath.size() == 3 && attrPathS[0] == "apps"))
{ {
auto aType = visitor.maybeGetAttr("type"); auto aType = visitor.maybeGetAttr("type");
std::optional<std::string> description;
if (auto aMeta = visitor.maybeGetAttr(state->sMeta)) {
if (auto aDescription = aMeta->maybeGetAttr(state->sDescription))
description = aDescription->getString();
}
if (!aType || aType->getString() != "app") if (!aType || aType->getString() != "app")
state->error<EvalError>("not an app definition").debugThrow(); state->error<EvalError>("not an app definition").debugThrow();
if (json) { if (json) {
j.emplace("type", "app"); j.emplace("type", "app");
if (description)
j.emplace("description", *description);
} else { } else {
logger->cout("%s: app", headerPrefix); logger->cout("%s: app: " ANSI_BOLD "%s" ANSI_NORMAL, headerPrefix, description ? *description : "no description");
} }
} }

View file

@ -80,6 +80,7 @@ An app is specified by a flake output attribute named
apps.x86_64-linux.blender_2_79 = { apps.x86_64-linux.blender_2_79 = {
type = "app"; type = "app";
program = "${self.packages.x86_64-linux.blender_2_79}/bin/blender"; program = "${self.packages.x86_64-linux.blender_2_79}/bin/blender";
meta.description = "Run Blender, a free and open-source 3D creation suite.";
}; };
``` ```
@ -90,4 +91,6 @@ The only supported attributes are:
* `program` (required): The full path of the executable to run. It * `program` (required): The full path of the executable to run. It
must reside in the Nix store. must reside in the Nix store.
* `meta.description` (optional): A description of the app.
)"" )""