Add AST-extracted metadata from .nix module files to a srctree filesystem tree using nix-meta.
Embed metadata (descriptions, author info, version numbers) in your Nix modules without affecting the evaluated configuration. metatree-nix strips _meta before evaluation.
nix-metaparses.nixfiles at the AST level and extracts the top-level_metaattribute set.nix-metaremoves_metafrom each AST and renders the modified AST to temporary files.srctreeevaluates the stripped files.- metatree-nix merges the evaluated content and the extracted metadata into the final tree.
Note
Because stripping happens before evaluation, modules never see _meta. Strict modules then evaluate without type errors or warnings.
Add metatree-nix to your flake.nix inputs:
{
inputs.metatree.url = "github:z1-0/metatree-nix";
outputs = { metatree, ... }: {
lib = metatree.lib;
};
}Add a top-level _meta attribute set to your module files:
# src/services/web.nix
{
_meta = {
description = "Web server service module";
author = "team-infra";
version = 1;
};
port = 8080;
host = "0.0.0.0";
workers = 4;
}let
pkgs = import nixpkgs { system = "x86_64-linux"; };
metatree = metatree.lib.load pkgs ./src;
in
metatreeloadreturns the enriched tree structure directly.loadHaumeareturns{ tree, attrs }for haumea-style access.
{
name = "web";
path = "/abs/path/to/src/services/web.nix";
type = "file";
content = {
port = 8080;
host = "0.0.0.0";
workers = 4;
};
meta = {
description = "Web server service module";
author = "team-infra";
version = 1;
};
}Tip
Use loadHaumea when you need both tree and attrs. Use load for direct tree access.
load :: pkgs -> src -> tree
Load a directory with srctree, extract _meta from Nix files, strip it, evaluate, and return the enriched tree.
pkgs: package set for running the parser/renderer utilities.src: source directory to load.
loadHaumea :: pkgs -> args -> { tree, attrs }
Load with a haumea-style return, giving you the tree and clean attrs.
pkgs: package set for running the parser/renderer utilities.args: arguments forwarded tosrctree.lib.loadHaumea.
withMeta :: pkgs -> tree -> tree
Enrich an already loaded srctree tree with AST-extracted _meta attributes.
pkgs: package set for running the parser/renderer utilities.tree: srctree tree structure to enrich.