Skip to content
Merged
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
36 changes: 20 additions & 16 deletions docs/mdbook/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,39 @@ let
removeWhitespace = builtins.replaceStrings [ " " ] [ "" ];

getSubOptions =
opts: path:
lib.optionalAttrs (isDeeplyVisible opts) (removeUnwanted (opts.type.getSubOptions path));

isVisible = isVisibleWith true;
isDeeplyVisible = isVisibleWith false;
opt:
let
visible = opt.visible or true;
visible' = if lib.isBool visible then visible else visible != "shallow";
subOpts = opt.type.getSubOptions opt.loc;
in
lib.optionalAttrs visible' (removeUnwanted subOpts);

isVisibleWith =
shallow: opts:
isVisible =
let
test =
opt:
let
internal = opt.internal or false;
visible = opt.visible or true;
visible' = if visible == "shallow" then shallow else visible;
visible' = if lib.isBool visible then visible else visible != "transparent";
in
visible' && !internal;

# FIXME: isVisible is not a perfect check;
# it will false-positive on `visible = "transparent"`
hasVisible = opts: lib.any (v: lib.isAttrs v -> isVisible v) (lib.attrValues opts);
in
opts:
if lib.isOption opts then
test opts
else if opts.isOption then
test opts.index.options
else
let
filterFunc = lib.filterAttrs (_: v: if lib.isAttrs v then isVisibleWith shallow v else true);
hasEmptyIndex = (filterFunc opts.index.options) == { };
hasEmptyComponents = (filterFunc opts.components) == { };
in
!hasEmptyIndex || !hasEmptyComponents;
lib.any hasVisible [
opts.index.options
opts.components
];

wrapOptionDocPage = path: opts: isOpt: rec {
index = {
Expand Down Expand Up @@ -136,15 +140,15 @@ let
wrapOptionDocPage (path ++ [ name ]) (go (path ++ [ name ]) opts) false
else
let
subOpts = getSubOptions opts (path ++ [ name ]);
subOpts = getSubOptions opts;
in
# If this node is an option with sub-options...
# Pass wrapOptionDocPage a set containing it and its sub-options.
# In practice, this creates a dedicated page for the option and its sub-options.
if subOpts != { } then
wrapOptionDocPage (path ++ [ name ]) (
(go (path ++ [ name ]) subOpts)
// {
// lib.optionalAttrs (isVisible opts) {
# This is necessary to include the option itself in the docs.
# For instance, this helps submodules like "autoCmd" to include their base declaration in the docs.
# Though there must be a better, less "hacky" solution than this.
Expand Down