From da5bda4c82cc730cf4d3efd7dce08f17d3068098 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 25 Sep 2024 13:38:10 +0200 Subject: [PATCH] Docs: autogenerate inventory & buildClan model --- docs/nix/default.nix | 2 - docs/nix/flake-module.nix | 4 + docs/nix/render_options/__init__.py | 125 ++++++++++++++++++++++++++-- docs/nix/shell.nix | 4 +- 4 files changed, 125 insertions(+), 10 deletions(-) diff --git a/docs/nix/default.nix b/docs/nix/default.nix index 914024538..01dae322f 100644 --- a/docs/nix/default.nix +++ b/docs/nix/default.nix @@ -2,7 +2,6 @@ pkgs, module-docs, clan-cli-docs, - inventory-api-docs, asciinema-player-js, asciinema-player-css, roboto, @@ -33,7 +32,6 @@ pkgs.stdenv.mkDerivation { mkdir -p ./site/reference/cli cp -af ${module-docs}/* ./site/reference/ cp -af ${clan-cli-docs}/* ./site/reference/cli/ - cp -af ${inventory-api-docs} ./site/reference/nix-api/inventory.md mkdir -p ./site/static/asciinema-player ln -snf ${asciinema-player-js} ./site/static/asciinema-player/asciinema-player.min.js diff --git a/docs/nix/flake-module.nix b/docs/nix/flake-module.nix index 89aef7e69..29acc7f4c 100644 --- a/docs/nix/flake-module.nix +++ b/docs/nix/flake-module.nix @@ -8,6 +8,7 @@ ... }: let + buildClanOptions = self'.legacyPackages.clan-internals-docs; # Simply evaluated options (JSON) # { clanCore = «derivation JSON»; clanModules = { ${name} = «derivation JSON» }; } jsonDocs = import ./get-module-docs.nix { @@ -67,6 +68,9 @@ # A file that contains the links to all clanModule docs export CLAN_MODULES=${clanModulesFileInfo} + # buildClan options + export BUILD_CLAN_PATH=${buildClanOptions}/share/doc/nixos/options.json + mkdir $out # The python script will place mkDocs files in the output directory diff --git a/docs/nix/render_options/__init__.py b/docs/nix/render_options/__init__.py index b186a5451..aacf8f3ef 100644 --- a/docs/nix/render_options/__init__.py +++ b/docs/nix/render_options/__init__.py @@ -35,6 +35,7 @@ from clan_cli.errors import ClanError CLAN_CORE_PATH = Path(os.environ["CLAN_CORE_PATH"]) CLAN_CORE_DOCS = Path(os.environ["CLAN_CORE_DOCS"]) CLAN_MODULES = os.environ.get("CLAN_MODULES") +BUILD_CLAN_PATH = os.environ.get("BUILD_CLAN_PATH") OUT = os.environ.get("out") @@ -74,11 +75,15 @@ def join_lines_with_indentation(lines: list[str], indent: int = 4) -> str: return "\n".join(indent_str + line for line in lines) -def render_option(name: str, option: dict[str, Any], level: int = 3) -> str: +def render_option( + name: str, option: dict[str, Any], level: int = 3, short_head: str | None = None +) -> str: read_only = option.get("readOnly") res = f""" -{"#" * level} {sanitize(name)} +{"#" * level} {sanitize(name) if short_head is None else sanitize(short_head)} + +{f"**Attribute: `{name}`**" if short_head is not None else ""} {"**Readonly**" if read_only else ""} @@ -116,7 +121,6 @@ def render_option(name: str, option: dict[str, Any], level: int = 3) -> str: decls = option.get("declarations", []) if decls: source_path, name = replace_store_path(decls[0]) - print(source_path, name) res += f""" :simple-git: [{name}]({source_path}) """ @@ -211,7 +215,7 @@ For more information, see the [inventory guide](../../manual/inventory.md). clan_modules_descr = """Clan modules are [NixOS modules](https://wiki.nixos.org/wiki/NixOS_modules) which have been enhanced with additional features provided by Clan, with certain option types restricted to enable configuration through a graphical interface. -!!! note "🔹 = [inventory](../../manual/inventory.md) supported +!!! note "🔹" Modules with this indicator support the [inventory](../../manual/inventory.md) feature. """ @@ -331,6 +335,117 @@ def build_option_card(module_name: str, frontmatter: Frontmatter) -> str: return f"{to_md_li(module_name, frontmatter)}\n\n" -if __name__ == "__main__": +def produce_build_clan_docs() -> None: + if not BUILD_CLAN_PATH: + msg = f"Environment variables are not set correctly: BUILD_CLAN_PATH={BUILD_CLAN_PATH}. Expected a path to the optionsJSON" + raise ClanError(msg) + + if not OUT: + msg = f"Environment variables are not set correctly: $out={OUT}" + raise ClanError(msg) + + output = """# BuildClan + +This provides an overview of the available arguments of the `buildClan` function. + +!!! Note "Flake-parts" + Each attribute is also available via `clan.