refactor: expose nixosOptionsDoc args, add multiple output formats
This commit is contained in:
parent
4d711e5002
commit
480737fc84
1 changed files with 50 additions and 15 deletions
65
flake.nix
65
flake.nix
|
@ -6,8 +6,10 @@
|
|||
|
||||
# cheerfully lifted from nixos + hjem-rum doc gen
|
||||
outputs =
|
||||
inputs: with inputs; {
|
||||
lib.pak-chooie =
|
||||
inputs:
|
||||
with inputs;
|
||||
let
|
||||
rawEval =
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
|
@ -16,6 +18,7 @@
|
|||
newPath ? "https://my.site/unf/docs",
|
||||
specialArgs ? { },
|
||||
modules ? [ ],
|
||||
userOpts ? { },
|
||||
}:
|
||||
let
|
||||
basePath = self.outPath;
|
||||
|
@ -53,9 +56,12 @@
|
|||
internal = true;
|
||||
};
|
||||
}
|
||||
] ++ modules;
|
||||
]
|
||||
++ modules;
|
||||
};
|
||||
optionsDoc = pkgs.nixosOptionsDoc {
|
||||
in
|
||||
pkgs.nixosOptionsDoc (
|
||||
{
|
||||
inherit (eval) options;
|
||||
|
||||
transformOptions =
|
||||
|
@ -69,9 +75,12 @@
|
|||
in
|
||||
map (
|
||||
decl:
|
||||
if hasPrefix (toString devDir) (toString decl) then
|
||||
let
|
||||
decl' = toString decl;
|
||||
in
|
||||
if hasPrefix devDir decl' then
|
||||
let
|
||||
subpath = removePrefix "/" (removePrefix (toString devDir) (toString decl));
|
||||
subpath = removePrefix "/" (removePrefix devDir decl');
|
||||
in
|
||||
{
|
||||
url = "${newPath}/${subpath}";
|
||||
|
@ -81,15 +90,41 @@
|
|||
decl
|
||||
) opt.declarations;
|
||||
};
|
||||
};
|
||||
}
|
||||
// userOpts
|
||||
);
|
||||
|
||||
in
|
||||
{
|
||||
lib =
|
||||
let
|
||||
inherit (builtins) removeAttrs toJSON toXML;
|
||||
raw = { pkgs, ... }@args: pkgs.callPackage rawEval (removeAttrs args [ "pkgs" ]);
|
||||
withTransform =
|
||||
fmt: transform:
|
||||
{ pkgs, ... }@args:
|
||||
pkgs.writeText "options.${fmt}" (transform (raw args).optionsNix);
|
||||
in
|
||||
pkgs.runCommandLocal "${projectName}-docs"
|
||||
{ nativeBuildInputs = [ ndg.packages.${pkgs.system}.ndg ]; }
|
||||
''
|
||||
ndg --verbose html --jobs $NIX_BUILD_CORES --title "${projectName}" \
|
||||
--module-options "${optionsDoc.optionsJSON}/share/doc/nixos/options.json" \
|
||||
--generate-search true \
|
||||
--output-dir "$out"
|
||||
'';
|
||||
{
|
||||
md = args: (raw args).optionsCommonMark;
|
||||
nix = args: (raw args).optionsNix;
|
||||
json = withTransform "json" toJSON;
|
||||
xml = withTransform "xml" toXML;
|
||||
yaml = { pkgs, ... }@args: (pkgs.formats.yaml { }).generate "options.yaml" (raw args).optionsNix;
|
||||
toml = { pkgs, ... }@args: (pkgs.formats.toml { }).generate "options.toml" (raw args).optionsNix;
|
||||
html =
|
||||
{ pkgs, projectName, ... }@args:
|
||||
let
|
||||
json = self.lib.json args;
|
||||
in
|
||||
pkgs.runCommandLocal "${projectName}-docs"
|
||||
{ nativeBuildInputs = [ ndg.packages.${pkgs.system}.ndg ]; }
|
||||
''
|
||||
ndg --verbose html --jobs $NIX_BUILD_CORES --title "${projectName}" \
|
||||
--module-options "${json}" \
|
||||
--generate-search true \
|
||||
--output-dir "$out"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue