Metadata for Nix: embed, query, and strip it on any expression.
nix-meta embeds metadata as an attribute set under a _meta marker in a Nix expression, then traverses the expression to find, update, or remove it.
Built on nix-ast.
Flake input:
{
inputs.nix-meta.url = "github:z1-0/nix-meta";
outputs = { nix-meta, ... }: {
lib = nix-meta.lib;
};
}get :: pkgs -> [AST] -> [a | null]
For each AST, find and evaluate the first _meta binding.
Returns one element per input AST, in the same order. null where an AST has no _meta.
meta.lib.get pkgs [ ast1 ast2 ]
# -> [ metadata-or-null, metadata-or-null ]set :: a -> AST -> AST
Attach metadata to an AST. If metadata already exists, it is replaced.
Returns the AST with metadata embedded.
meta.lib.set { version = "1.0"; author = "me"; } ast
# -> ast with metadata attachedremove :: AST -> AST
Remove the first _meta binding from an AST.
meta.lib.remove ast
# -> ast with first _meta removednix-meta re-exports the full nix-ast API. See its documentation.
Inspect metadata across multiple files:
let
inherit (nix-meta) parse get;
asts = parse pkgs [
./maintainers/alice.nix # { _meta = { email = "alice@email.com"; }; outputs = { ... }; }
./maintainers/bob.nix # { outputs = { ... }; }
./maintainers/charlie.nix # { _meta = { email = "charlie@email.com"; }; outputs = { ... }; }
];
metas = get pkgs asts; # [ { email = "alice@example.com"; } null { email = "charlie@example.com"; } ]
in