bonfire/packages/bonfire-docs/nixosModulesDoc.nix
L-Nafaryus a4d8f5232e
Some checks failed
nix / check (push) Failing after 1m15s
flake: huge rework
flake: fix name conventions
flake: configurations -> lib.preconfiguredModules
flake.packages: rework platform dependency with convient module and
evaluator `lib.collectPackages`
packages.bonfire-docs: convient evaluators `nixosModulesDoc` and
`packagesDoc`
new: packages.postgresql: container image
new: packages.redis: container image
remove: packages.lego: needed dns provider was added to lego and nixpkgs
packages.netgen: broken
2024-07-18 15:49:05 +05:00

65 lines
1.8 KiB
Nix

{
lib,
pkgs,
modules,
excludedModules ? ["default"],
root ? null,
declarations ? {},
projectName ? "",
modulesPrefix ? "",
version ? "unknown",
}: let
moduleNames = lib.filter (key: builtins.all (restricted: key != restricted) excludedModules) (lib.attrNames modules);
moduleValues = map (key: modules.${key}) moduleNames;
genDeclaration = storeDeclaration: declarations:
map (declaration: let
subpath = lib.removePrefix (toString root + "/") (toString storeDeclaration);
project =
if projectName != ""
then "${projectName}/"
else "";
in {
name = "<${declaration.name}:${project}${subpath}>";
url = "${declaration.url}/${subpath}";
})
declarations;
formatDeclaration = storeDeclaration:
if lib.hasPrefix (toString modulesPrefix) (toString storeDeclaration)
then genDeclaration storeDeclaration declarations
# skip external declarations
else lib.singleton storeDeclaration;
transformOptions = option:
option
// {
declarations = lib.unique (
lib.flatten (map (declaration: formatDeclaration declaration) option.declarations)
++ option.declarations
);
};
genDocumentation = module:
pkgs.nixosOptionsDoc {
options = builtins.removeAttrs (lib.evalModules {modules = [module];}).options [
"_module"
"system"
];
transformOptions = transformOptions;
documentType = "none";
revision = version;
};
in {
documentation =
lib.zipListsWith (name: moduleDocumentation: {
name = name;
commonMarkdown = moduleDocumentation.optionsCommonMark;
})
moduleNames
(map (module: genDocumentation module) moduleValues);
summary = map (name: " - [${name}](nixosModules/${name}.md)") moduleNames;
}