mirror of
https://git.atagen.co/atagen/unf.git
synced 2026-07-17 06:25:11 +08:00
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
51
flake.nix
51
flake.nix
|
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
# cheerfully lifted from nixos + hjem-rum doc gen
|
# cheerfully lifted from nixos + hjem-rum doc gen
|
||||||
outputs =
|
outputs =
|
||||||
inputs: with inputs; {
|
inputs:
|
||||||
lib.pak-chooie =
|
with inputs;
|
||||||
|
let
|
||||||
|
rawEval =
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
|
|
@ -16,6 +18,7 @@
|
||||||
newPath ? "https://my.site/unf/docs",
|
newPath ? "https://my.site/unf/docs",
|
||||||
specialArgs ? { },
|
specialArgs ? { },
|
||||||
modules ? [ ],
|
modules ? [ ],
|
||||||
|
userOpts ? { },
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
basePath = self.outPath;
|
basePath = self.outPath;
|
||||||
|
|
@ -53,9 +56,12 @@
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
] ++ modules;
|
]
|
||||||
|
++ modules;
|
||||||
};
|
};
|
||||||
optionsDoc = pkgs.nixosOptionsDoc {
|
in
|
||||||
|
pkgs.nixosOptionsDoc (
|
||||||
|
{
|
||||||
inherit (eval) options;
|
inherit (eval) options;
|
||||||
|
|
||||||
transformOptions =
|
transformOptions =
|
||||||
|
|
@ -69,9 +75,12 @@
|
||||||
in
|
in
|
||||||
map (
|
map (
|
||||||
decl:
|
decl:
|
||||||
if hasPrefix (toString devDir) (toString decl) then
|
|
||||||
let
|
let
|
||||||
subpath = removePrefix "/" (removePrefix (toString devDir) (toString decl));
|
decl' = toString decl;
|
||||||
|
in
|
||||||
|
if hasPrefix devDir decl' then
|
||||||
|
let
|
||||||
|
subpath = removePrefix "/" (removePrefix devDir decl');
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
url = "${newPath}/${subpath}";
|
url = "${newPath}/${subpath}";
|
||||||
|
|
@ -81,15 +90,41 @@
|
||||||
decl
|
decl
|
||||||
) opt.declarations;
|
) 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
|
||||||
|
{
|
||||||
|
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
|
in
|
||||||
pkgs.runCommandLocal "${projectName}-docs"
|
pkgs.runCommandLocal "${projectName}-docs"
|
||||||
{ nativeBuildInputs = [ ndg.packages.${pkgs.system}.ndg ]; }
|
{ nativeBuildInputs = [ ndg.packages.${pkgs.system}.ndg ]; }
|
||||||
''
|
''
|
||||||
ndg --verbose html --jobs $NIX_BUILD_CORES --title "${projectName}" \
|
ndg --verbose html --jobs $NIX_BUILD_CORES --title "${projectName}" \
|
||||||
--module-options "${optionsDoc.optionsJSON}/share/doc/nixos/options.json" \
|
--module-options "${json}" \
|
||||||
--generate-search true \
|
--generate-search true \
|
||||||
--output-dir "$out"
|
--output-dir "$out"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue