60 lines
1.3 KiB
Nix
60 lines
1.3 KiB
Nix
{
|
|
gnused,
|
|
lib,
|
|
nixosOptionsDoc,
|
|
runCommand,
|
|
self,
|
|
}:
|
|
|
|
let
|
|
webUrl = "https://git.defelo.de/Defelo/kvm.nix/src/branch/develop";
|
|
|
|
eval = lib.evalModules {
|
|
modules = [
|
|
{
|
|
config._module.check = false;
|
|
options._module.args = lib.mkOption { internal = true; };
|
|
}
|
|
self.nixosModules.default
|
|
];
|
|
};
|
|
|
|
removeTrailingNewlineInLiteralExpression =
|
|
let
|
|
updateAttr =
|
|
attr: opt:
|
|
if opt.${attr}._type or null == "literalExpression" then
|
|
opt // { ${attr} = lib.literalExpression (lib.removeSuffix "\n" opt.${attr}.text); }
|
|
else
|
|
opt;
|
|
in
|
|
lib.flip lib.pipe [
|
|
(updateAttr "default")
|
|
(updateAttr "example")
|
|
];
|
|
|
|
fixDeclarations =
|
|
opt:
|
|
if opt ? declarations then
|
|
opt
|
|
// {
|
|
declarations = map (
|
|
d: if builtins.readFileType d == "directory" then d + "/default.nix" else d
|
|
) opt.declarations;
|
|
}
|
|
else
|
|
opt;
|
|
|
|
docs =
|
|
(nixosOptionsDoc {
|
|
inherit (eval) options;
|
|
transformOptions = lib.flip lib.pipe [
|
|
removeTrailingNewlineInLiteralExpression
|
|
fixDeclarations
|
|
];
|
|
}).optionsCommonMark;
|
|
in
|
|
|
|
runCommand "docs" { } ''
|
|
${lib.getExe gnused} -E 's|\[${self}/(.*)\]\(.*\)|[\1](${webUrl}/\1)|' ${docs} > $out
|
|
''
|