From cfa1fca76e74e6d213a2cd69a4615d372e19274a Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 16 Sep 2024 23:46:19 +0200 Subject: [PATCH] Inventory: docs fixup --- docs/nix/render_options/__init__.py | 12 +++--------- docs/site/guides/inventory.md | 13 ------------- pkgs/clan-cli/clan_cli/api/modules.py | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/docs/nix/render_options/__init__.py b/docs/nix/render_options/__init__.py index a5717a0dc..272990d0d 100644 --- a/docs/nix/render_options/__init__.py +++ b/docs/nix/render_options/__init__.py @@ -212,6 +212,9 @@ For more information, see the [inventory guide](../../guides/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](../../guides/inventory.md) supported + Modules with this indicator support the [inventory](../../guides/inventory.md) feature. + """ @@ -246,15 +249,6 @@ def produce_clan_modules_docs() -> None: with Path(CLAN_MODULES).open() as f: links: dict[str, str] = json.load(f) - # with open(CLAN_MODULES_READMES) as readme: - # readme_map: dict[str, str] = json.load(readme) - - # with open(CLAN_MODULES_META) as f: - # meta_map: dict[str, Any] = json.load(f) - # print(meta_map) - - # {'borgbackup': '/nix/store/hi17dwgy7963ddd4ijh81fv0c9sbh8sw-options.json', ... } - modules_index = "# Modules Overview\n\n" modules_index += clan_modules_descr modules_index += "## Overview\n\n" diff --git a/docs/site/guides/inventory.md b/docs/site/guides/inventory.md index 2ff2130a8..3d4a2b219 100644 --- a/docs/site/guides/inventory.md +++ b/docs/site/guides/inventory.md @@ -12,19 +12,6 @@ This guide will walk you through setting up a backup service, where the inventor Stabilizing the API is a priority. -## Categories - -
- -
- Light Coral -
- -
- Baby Blue -
-
- ## Prerequisites - [x] [Add machines](./add-machines.md) to your clan. diff --git a/pkgs/clan-cli/clan_cli/api/modules.py b/pkgs/clan-cli/clan_cli/api/modules.py index 6fc9cac93..9eaa56cc7 100644 --- a/pkgs/clan-cli/clan_cli/api/modules.py +++ b/pkgs/clan-cli/clan_cli/api/modules.py @@ -106,10 +106,23 @@ def extract_frontmatter(readme_content: str, err_scope: str) -> tuple[Frontmatte ) +def has_inventory_feature(module_path: Path) -> bool: + readme_file = module_path / "README.md" + if not readme_file.exists(): + return False + with readme_file.open() as f: + readme = f.read() + frontmatter, _ = extract_frontmatter(readme, f"{module_path}") + return "inventory" in frontmatter.features + + def get_roles(module_path: Path) -> None | list[str]: + if not has_inventory_feature(module_path): + return None + roles_dir = module_path / "roles" if not roles_dir.exists() or not roles_dir.is_dir(): - return None + return ["default"] return [ role.stem # filename without .nix extension