2019-08-08 10:59:25 +00:00
|
|
|
/* Generate JSON, XML and DocBook documentation for given NixOS options.
|
|
|
|
|
|
|
|
Minimal example:
|
|
|
|
|
|
|
|
{ pkgs, }:
|
|
|
|
|
|
|
|
let
|
|
|
|
eval = import (pkgs.path + "/nixos/lib/eval-config.nix") {
|
|
|
|
baseModules = [
|
|
|
|
../module.nix
|
|
|
|
];
|
|
|
|
modules = [];
|
|
|
|
};
|
|
|
|
in pkgs.nixosOptionsDoc {
|
|
|
|
options = eval.options;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
{ pkgs
|
|
|
|
, lib
|
|
|
|
, options
|
2022-12-18 00:31:14 +00:00
|
|
|
, transformOptions ? lib.id # function for additional transformations of the options
|
2022-05-01 19:50:51 +00:00
|
|
|
, documentType ? "appendix" # TODO deprecate "appendix" in favor of "none"
|
|
|
|
# and/or rename function to moduleOptionDoc for clean slate
|
2022-06-27 15:27:24 +00:00
|
|
|
|
|
|
|
# If you include more than one option list into a document, you need to
|
|
|
|
# provide different ids.
|
|
|
|
, variablelistId ? "configuration-variable-list"
|
2022-11-03 14:56:27 +00:00
|
|
|
# String to prefix to the option XML/HTML id attributes.
|
2022-09-29 10:34:06 +00:00
|
|
|
, optionIdPrefix ? "opt-"
|
2019-08-08 10:59:25 +00:00
|
|
|
, revision ? "" # Specify revision for the options
|
2021-11-18 22:00:03 +00:00
|
|
|
# a set of options the docs we are generating will be merged into, as if by recursiveUpdate.
|
|
|
|
# used to split the options doc build into a static part (nixos/modules) and a dynamic part
|
|
|
|
# (non-nixos modules imported via configuration.nix, other module sources).
|
2019-08-08 10:59:25 +00:00
|
|
|
, baseOptionsJSON ? null
|
2021-12-18 18:37:41 +00:00
|
|
|
# instead of printing warnings for eg options with missing descriptions (which may be lost
|
|
|
|
# by nix build unless -L is given), emit errors instead and fail the build
|
|
|
|
, warningsAreErrors ? true
|
2022-09-01 17:23:59 +00:00
|
|
|
# allow docbook option docs if `true`. only markdown documentation is allowed when set to
|
|
|
|
# `false`, and a different renderer may be used with different bugs and performance
|
|
|
|
# characteristics but (hopefully) indistinguishable output.
|
2023-06-11 17:29:32 +00:00
|
|
|
# deprecated since 23.11.
|
|
|
|
# TODO remove in a while.
|
|
|
|
, allowDocBook ? false
|
2022-11-11 05:15:46 +00:00
|
|
|
# whether lib.mdDoc is required for descriptions to be read as markdown.
|
2023-06-11 18:07:13 +00:00
|
|
|
# deprecated since 23.11.
|
|
|
|
# TODO remove in a while.
|
|
|
|
, markdownByDefault ? true
|
2019-08-08 10:59:25 +00:00
|
|
|
}:
|
|
|
|
|
2023-06-11 18:07:13 +00:00
|
|
|
assert markdownByDefault && ! allowDocBook;
|
2023-06-11 17:29:32 +00:00
|
|
|
|
2019-08-08 10:59:25 +00:00
|
|
|
let
|
2022-05-25 10:49:26 +00:00
|
|
|
rawOpts = lib.optionAttrSetToDocList options;
|
|
|
|
transformedOpts = map transformOptions rawOpts;
|
|
|
|
filteredOpts = lib.filter (opt: opt.visible && !opt.internal) transformedOpts;
|
|
|
|
optionsList = lib.flip map filteredOpts
|
|
|
|
(opt: opt
|
2020-08-03 14:32:15 +00:00
|
|
|
// lib.optionalAttrs (opt ? relatedPackages && opt.relatedPackages != []) { relatedPackages = genRelatedPackages opt.relatedPackages opt.name; }
|
2019-08-08 10:59:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
# Generate DocBook documentation for a list of packages. This is
|
|
|
|
# what `relatedPackages` option of `mkOption` from
|
|
|
|
# ../../../lib/options.nix influences.
|
|
|
|
#
|
|
|
|
# Each element of `relatedPackages` can be either
|
2021-12-18 18:21:21 +00:00
|
|
|
# - a string: that will be interpreted as an attribute name from `pkgs` and turned into a link
|
|
|
|
# to search.nixos.org,
|
|
|
|
# - a list: that will be interpreted as an attribute path from `pkgs` and turned into a link
|
|
|
|
# to search.nixos.org,
|
|
|
|
# - an attrset: that can specify `name`, `path`, `comment`
|
2019-08-08 10:59:25 +00:00
|
|
|
# (either of `name`, `path` is required, the rest are optional).
|
2021-12-18 18:21:21 +00:00
|
|
|
#
|
|
|
|
# NOTE: No checks against `pkgs` are made to ensure that the referenced package actually exists.
|
|
|
|
# Such checks are not compatible with option docs caching.
|
2020-08-03 14:32:15 +00:00
|
|
|
genRelatedPackages = packages: optName:
|
2019-08-08 10:59:25 +00:00
|
|
|
let
|
|
|
|
unpack = p: if lib.isString p then { name = p; }
|
|
|
|
else if lib.isList p then { path = p; }
|
|
|
|
else p;
|
|
|
|
describe = args:
|
|
|
|
let
|
|
|
|
title = args.title or null;
|
|
|
|
name = args.name or (lib.concatStringsSep "." args.path);
|
2021-12-18 18:21:21 +00:00
|
|
|
in ''
|
2023-02-01 05:45:22 +00:00
|
|
|
- [${lib.optionalString (title != null) "${title} aka "}`pkgs.${name}`](
|
2023-01-18 23:39:17 +00:00
|
|
|
https://search.nixos.org/packages?show=${name}&sort=relevance&query=${name}
|
|
|
|
)${
|
|
|
|
lib.optionalString (args ? comment) "\n\n ${args.comment}"
|
|
|
|
}
|
2021-12-18 18:21:21 +00:00
|
|
|
'';
|
2023-01-18 23:39:17 +00:00
|
|
|
in lib.concatMapStrings (p: describe (unpack p)) packages;
|
2019-08-08 10:59:25 +00:00
|
|
|
|
2019-08-10 12:24:11 +00:00
|
|
|
optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList);
|
|
|
|
|
2021-11-18 19:21:53 +00:00
|
|
|
in rec {
|
2019-08-10 12:24:11 +00:00
|
|
|
inherit optionsNix;
|
|
|
|
|
2023-02-05 04:58:14 +00:00
|
|
|
optionsAsciiDoc = pkgs.runCommand "options.adoc" {
|
|
|
|
nativeBuildInputs = [ pkgs.nixos-render-docs ];
|
|
|
|
} ''
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options asciidoc \
|
|
|
|
--manpage-urls ${pkgs.path + "/doc/manpage-urls.json"} \
|
|
|
|
--revision ${lib.escapeShellArg revision} \
|
2022-12-05 16:05:06 +00:00
|
|
|
${optionsJSON}/share/doc/nixos/options.json \
|
2023-02-05 04:58:14 +00:00
|
|
|
$out
|
2021-11-18 19:21:53 +00:00
|
|
|
'';
|
2019-08-10 18:07:05 +00:00
|
|
|
|
2023-02-04 22:16:30 +00:00
|
|
|
optionsCommonMark = pkgs.runCommand "options.md" {
|
|
|
|
nativeBuildInputs = [ pkgs.nixos-render-docs ];
|
|
|
|
} ''
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options commonmark \
|
|
|
|
--manpage-urls ${pkgs.path + "/doc/manpage-urls.json"} \
|
|
|
|
--revision ${lib.escapeShellArg revision} \
|
2022-12-05 16:05:06 +00:00
|
|
|
${optionsJSON}/share/doc/nixos/options.json \
|
2023-02-04 22:16:30 +00:00
|
|
|
$out
|
2021-11-18 19:21:53 +00:00
|
|
|
'';
|
2021-04-13 01:08:12 +00:00
|
|
|
|
2019-08-08 10:59:25 +00:00
|
|
|
optionsJSON = pkgs.runCommand "options.json"
|
|
|
|
{ meta.description = "List of NixOS options in JSON format";
|
2022-10-07 16:26:22 +00:00
|
|
|
nativeBuildInputs = [
|
2022-08-05 15:13:47 +00:00
|
|
|
pkgs.brotli
|
2023-09-12 15:07:58 +00:00
|
|
|
pkgs.python3
|
2022-08-05 15:13:47 +00:00
|
|
|
];
|
2019-08-10 12:24:11 +00:00
|
|
|
options = builtins.toFile "options.json"
|
|
|
|
(builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix));
|
2022-09-01 17:23:59 +00:00
|
|
|
# merge with an empty set if baseOptionsJSON is null to run markdown
|
|
|
|
# processing on the input options
|
|
|
|
baseJSON =
|
|
|
|
if baseOptionsJSON == null
|
|
|
|
then builtins.toFile "base.json" "{}"
|
|
|
|
else baseOptionsJSON;
|
2019-08-08 10:59:25 +00:00
|
|
|
}
|
|
|
|
''
|
|
|
|
# Export list of options in different format.
|
|
|
|
dst=$out/share/doc/nixos
|
|
|
|
mkdir -p $dst
|
|
|
|
|
2023-01-15 13:56:46 +00:00
|
|
|
TOUCH_IF_DB=$dst/.used-docbook \
|
2022-09-01 17:23:59 +00:00
|
|
|
python ${./mergeJSON.py} \
|
|
|
|
${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
|
|
|
|
$baseJSON $options \
|
|
|
|
> $dst/options.json
|
2019-08-08 10:59:25 +00:00
|
|
|
|
2023-06-13 12:05:40 +00:00
|
|
|
if grep /nixpkgs/nixos/modules $dst/options.json; then
|
|
|
|
echo "The manual appears to depend on the location of Nixpkgs, which is bad"
|
|
|
|
echo "since this prevents sharing via the NixOS channel. This is typically"
|
|
|
|
echo "caused by an option default that refers to a relative path (see above"
|
|
|
|
echo "for hints about the offending path)."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-03-24 15:38:36 +00:00
|
|
|
brotli -9 < $dst/options.json > $dst/options.json.br
|
|
|
|
|
2019-08-08 10:59:25 +00:00
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products
|
2020-03-24 15:38:36 +00:00
|
|
|
echo "file json-br $dst/options.json.br" >> $out/nix-support/hydra-build-products
|
2021-11-18 22:00:03 +00:00
|
|
|
'';
|
|
|
|
|
2023-06-13 10:21:38 +00:00
|
|
|
optionsDocBook = lib.warn "optionsDocBook is deprecated since 23.11 and will be removed in 24.05"
|
|
|
|
(pkgs.runCommand "options-docbook.xml" {
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.nixos-render-docs
|
|
|
|
];
|
|
|
|
} ''
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options docbook \
|
|
|
|
--manpage-urls ${pkgs.path + "/doc/manpage-urls.json"} \
|
|
|
|
--revision ${lib.escapeShellArg revision} \
|
|
|
|
--document-type ${lib.escapeShellArg documentType} \
|
|
|
|
--varlist-id ${lib.escapeShellArg variablelistId} \
|
|
|
|
--id-prefix ${lib.escapeShellArg optionIdPrefix} \
|
|
|
|
${optionsJSON}/share/doc/nixos/options.json \
|
|
|
|
"$out"
|
|
|
|
'');
|
2019-08-08 10:59:25 +00:00
|
|
|
}
|