Docs/modules: add usage example

This commit is contained in:
Johannes Kirschbauer
2024-11-20 11:35:33 +01:00
parent cb47df5de8
commit 25e2307ecc

View File

@@ -218,7 +218,7 @@ Every clan module has a `frontmatter` section within its readme. It provides mac
""" """
output += """"## Overview output += """## Overview
This provides an overview of the available attributes of the `frontmatter` within the `README.md` of a clan module. This provides an overview of the available attributes of the `frontmatter` within the `README.md` of a clan module.
@@ -283,18 +283,54 @@ def produce_clan_core_docs() -> None:
def render_roles(roles: list[str] | None, module_name: str) -> str: def render_roles(roles: list[str] | None, module_name: str) -> str:
if roles: if roles:
roles_list = "\n".join([f" - `{r}`" for r in roles]) roles_list = "\n".join([f" - `{r}`" for r in roles])
return f""" return (
f"""
### Roles ### Roles
This module can be used via predefined roles This module can be used via predefined roles
{roles_list} {roles_list}
"""
"""
Every role has its own configuration options. Which are each listed below. Every role has its own configuration options. Which are each listed below.
For more information, see the [inventory guide](../../manual/inventory.md). For more information, see the [inventory guide](../../manual/inventory.md).
??? Example
For example the `admin` module adds the following options globally to all machines where it is used.
`clan.admin.allowedkeys`
This means there are two equivalent ways to set the `allowedkeys` option. Either via a nixos module or via the inventory interface.
**But it is recommended to keep together `imports` and `config` to preserve locality of the module configuration.**
=== "Inventory"
```nix
clan-core.lib.buildClan {
inventory.services = {
admin.me = {
roles.default.machines = [ "jon" ];
config.allowedkeys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD..." ];
};
};
};
```
=== "NixOS"
```nix
clan-core.lib.buildClan {
machines = {
jon = {
clan.admin.allowedkeys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD..." ];
imports = [ clanModules.admin ];
};
};
};
```
""" """
)
return "" return ""
@@ -395,7 +431,7 @@ def produce_clan_modules_docs() -> None:
) )
exit(1) exit(1)
no_options = f"**The `{module_name}` `{role}` doesnt offer / require any options to be set.**" no_options = f"**The `{module_name}` `{role}` doesnt offer / require any options to be set.**\n\n"
heading = f"""### Options of `{role}` role heading = f"""### Options of `{role}` role