Files
clan-core/docs/nix/get-module-docs.nix
Jörg Thalheim 0e97efbbef refactor: move docs transformOptions to clanLib to reduce rebuilds
- Add clanLib.docs.stripStorePathsFromDeclarations to deduplicate code
- Update all documentation generation to use the shared function
- This strips store paths from option declarations to prevent options.json
  from rebuilding when only store paths change but content remains the same
- Reduces unnecessary documentation rebuilds when making unrelated changes
2025-07-09 16:59:58 +02:00

92 lines
2.2 KiB
Nix

{
modulesRolesOptions,
nixosOptionsDoc,
clanModules,
evalClanModules,
lib,
pkgs,
clan-core,
}:
let
inherit (clan-core.clanLib.docs) stripStorePathsFromDeclarations;
transformOptions = stripStorePathsFromDeclarations;
in
{
# clanModules docs
clanModulesViaNix = lib.mapAttrs (
name: module:
if builtins.pathExists (module + "/default.nix") then
(nixosOptionsDoc {
options =
((evalClanModules {
modules = [ module ];
inherit pkgs clan-core;
}).options
).clan.${name} or { };
warningsAreErrors = true;
inherit transformOptions;
}).optionsJSON
else
{ }
) clanModules;
clanModulesViaRoles = lib.mapAttrs (
_moduleName: rolesOptions:
lib.mapAttrs (
_roleName: options:
(nixosOptionsDoc {
inherit options;
warningsAreErrors = true;
inherit transformOptions;
}).optionsJSON
) rolesOptions
) modulesRolesOptions;
# Test with:
# nix build .\#legacyPackages.x86_64-linux.clanModulesViaService
clanModulesViaService = lib.mapAttrs (
_moduleName: moduleValue:
let
evaluatedService = clan-core.clanLib.evalService {
modules = [ moduleValue ];
prefix = [ ];
};
in
{
roles = lib.mapAttrs (
_roleName: role:
(nixosOptionsDoc {
transformOptions =
opt:
let
# Apply store path stripping first
transformed = transformOptions opt;
in
if lib.strings.hasPrefix "_" transformed.name then
transformed // { visible = false; }
else
transformed;
options = (lib.evalModules { modules = [ role.interface ]; }).options;
warningsAreErrors = true;
}).optionsJSON
) evaluatedService.config.roles;
manifest = evaluatedService.config.manifest;
}
) clan-core.clan.modules;
clanCore =
(nixosOptionsDoc {
options =
((evalClanModules {
modules = [ ];
inherit pkgs clan-core;
}).options
).clan.core or { };
warningsAreErrors = true;
inherit transformOptions;
}).optionsJSON;
}