Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add render.enable and render.output options #1288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 66 additions & 40 deletions render/render-module.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
top@{ config, inputs, lib, flake-parts-lib, ... }:
let
inherit (lib)
mkIf
mkOption
types
concatMap
Expand Down Expand Up @@ -407,9 +408,20 @@ in
{
options = {
render = {
enable = mkOption {
type = types.bool;
description = "Whether to install the rendered docs to `perSystem.packages`.";
default = true;
example = false;
};
inputs = mkOption {
description = "Which modules to render.";
type = types.attrsOf (types.submodule inputModule);
description = ''
Which modules to render.

The rendered docs are installed as `perSystem.packages.generated-docs-<name>`,
unless [`enable`](#opt-perSystem.render.enable) is set to false.
'';
};
officialFlakeInputs = mkOption {
type = types.raw;
Expand All @@ -420,49 +432,63 @@ in
'';
readOnly = true;
};
output = mkOption {
type = types.package;
description = ''
The generated-docs package.

Contains the rendered docs for all of [`inputs`](#opt-perSystem.render.inputs),
along with a `menu.md` summary file.

Installed as `perSystem.packages.generated-docs`,
unless [`enable`](#opt-perSystem.render.enable) is set to false.
'';
readOnly = true;
};
};
};
config = {
packages = lib.mapAttrs' (name: inputCfg: { name = "generated-docs-${name}"; value = inputCfg.rendered; }) cfg.inputs // {
generated-docs =
pkgs.runCommand "generated-docs"
{
passthru = {
inherit config;
inherit eval;
# This won't be in sync with the actual nixosOptionsDoc
# invocations, but it's useful for troubleshooting.
allOptionsPerhaps = (pkgs.nixosOptionsDoc {
options = opts;
}).optionsNix;
};
passAsFile = [ "menu" ];
menu =
lib.concatStringsSep
"\n"
(lib.filter
(x: x != "")
(lib.mapAttrsToList
(name: inputCfg:
lib.optionalString inputCfg.menu.enable
" - [${inputCfg.menu.title}](options/${name}.md)"
)
cfg.inputs
)
);
}
''
mkdir $out
${lib.concatStringsSep "\n"
packages = mkIf cfg.enable (
lib.mapAttrs' (name: inputCfg: { name = "generated-docs-${name}"; value = inputCfg.rendered; }) cfg.inputs
// { generated-docs = cfg.render.output; }
);
render.output = pkgs.runCommand "generated-docs"
{
passthru = {
inherit config;
inherit eval;
# This won't be in sync with the actual nixosOptionsDoc
# invocations, but it's useful for troubleshooting.
allOptionsPerhaps = (pkgs.nixosOptionsDoc {
options = opts;
}).optionsNix;
};
passAsFile = [ "menu" ];
menu =
lib.concatStringsSep
"\n"
(lib.filter
(x: x != "")
(lib.mapAttrsToList
(name: inputCfg: ''
cp ${inputCfg.rendered.file} $out/${name}.html
'')
cfg.inputs)
}
cp $menuPath $out/menu.md
'';
};
(name: inputCfg:
lib.optionalString inputCfg.menu.enable
" - [${inputCfg.menu.title}](options/${name}.md)"
)
cfg.inputs
)
);
}
''
mkdir $out
${lib.concatStringsSep "\n"
(lib.mapAttrsToList
(name: inputCfg: ''
cp ${inputCfg.rendered.file} $out/${name}.html
'')
cfg.inputs)
}
cp $menuPath $out/menu.md
'';
};
});
}