nixos/documentation: deprecate docbook option docs

following the plan in https://github.com/NixOS/nixpkgs/pull/189318#discussion_r961764451

also adds an activation script to print the warning during activation
instead of during build, otherwise folks using the new CLI that hides
build logs by default might never see the warning.

pennae df09c21f 45a5c01a

Changed files
+66 -17
nixos
doc
manual
from_md
release-notes
release-notes
lib
make-options-doc
testing
modules
+1 -1
nixos/doc/manual/default.nix
···
in rec {
inherit generatedSources;
-
inherit (optionsDoc) optionsJSON optionsNix optionsDocBook;
# Generate the NixOS manual.
manualHTML = runCommand "nixos-manual-html"
···
in rec {
inherit generatedSources;
+
inherit (optionsDoc) optionsJSON optionsNix optionsDocBook optionsUsedDocbook;
# Generate the NixOS manual.
manualHTML = runCommand "nixos-manual-html"
+16
nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
···
</listitem>
<listitem>
<para>
The <literal>dnsmasq</literal> service now takes configuration
via the <literal>services.dnsmasq.settings</literal> attribute
set. The option
···
</listitem>
<listitem>
<para>
+
DocBook option documentation, which has been deprecated since
+
22.11, will now cause a warning when documentation is built.
+
Out-of-tree modules should migrate to using CommonMark
+
documentation as outlined in
+
<xref linkend="sec-option-declarations" /> to silence this
+
warning.
+
</para>
+
<para>
+
DocBook option documentation support will be removed in the
+
next release and CommonMark will become the default. DocBook
+
option documentation that has not been migrated until then
+
will no longer render properly or cause errors.
+
</para>
+
</listitem>
+
<listitem>
+
<para>
The <literal>dnsmasq</literal> service now takes configuration
via the <literal>services.dnsmasq.settings</literal> attribute
set. The option
+4
nixos/doc/manual/release-notes/rl-2305.section.md
···
- `services.mastodon` gained a tootctl wrapped named `mastodon-tootctl` similar to `nextcloud-occ` which can be executed from any user and switches to the configured mastodon user with sudo and sources the environment variables.
- The `dnsmasq` service now takes configuration via the
`services.dnsmasq.settings` attribute set. The option
`services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches
···
- `services.mastodon` gained a tootctl wrapped named `mastodon-tootctl` similar to `nextcloud-occ` which can be executed from any user and switches to the configured mastodon user with sudo and sources the environment variables.
+
- DocBook option documentation, which has been deprecated since 22.11, will now cause a warning when documentation is built. Out-of-tree modules should migrate to using CommonMark documentation as outlined in [](#sec-option-declarations) to silence this warning.
+
+
DocBook option documentation support will be removed in the next release and CommonMark will become the default. DocBook option documentation that has not been migrated until then will no longer render properly or cause errors.
+
- The `dnsmasq` service now takes configuration via the
`services.dnsmasq.settings` attribute set. The option
`services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches
+10 -1
nixos/lib/make-options-doc/default.nix
···
dst=$out/share/doc/nixos
mkdir -p $dst
python ${./mergeJSON.py} \
${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
-
${lib.optionalString (! allowDocBook) "--error-on-docbook"} \
${lib.optionalString markdownByDefault "--markdown-by-default"} \
$baseJSON $options \
> $dst/options.json
···
echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products
echo "file json-br $dst/options.json.br" >> $out/nix-support/hydra-build-products
'';
# Convert options.json into an XML file.
# The actual generation of the xml file is done in nix purely for the convenience
···
dst=$out/share/doc/nixos
mkdir -p $dst
+
TOUCH_IF_DB=$dst/.used-docbook \
python ${./mergeJSON.py} \
${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
+
${if allowDocBook then "--warn-on-docbook" else "--error-on-docbook"} \
${lib.optionalString markdownByDefault "--markdown-by-default"} \
$baseJSON $options \
> $dst/options.json
···
echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products
echo "file json-br $dst/options.json.br" >> $out/nix-support/hydra-build-products
'';
+
+
optionsUsedDocbook = pkgs.runCommand "options-used-docbook" {} ''
+
if [ -e ${optionsJSON}/share/doc/nixos/.used-docbook ]; then
+
echo 1
+
else
+
echo 0
+
fi >"$out"
+
'';
# Convert options.json into an XML file.
# The actual generation of the xml file is done in nix purely for the convenience
+26 -14
nixos/lib/make-options-doc/mergeJSON.py
···
return options
warningsAreErrors = False
errorOnDocbook = False
markdownByDefault = False
optOffset = 0
···
if arg == "--warnings-are-errors":
optOffset += 1
warningsAreErrors = True
-
if arg == "--error-on-docbook":
optOffset += 1
errorOnDocbook = True
if arg == "--markdown-by-default":
···
# check that every option has a description
hasWarnings = False
hasErrors = False
-
hasDocBookErrors = False
for (k, v) in options.items():
-
if errorOnDocbook:
if isinstance(v.value.get('description', {}), str):
-
hasErrors = True
-
hasDocBookErrors = True
print(
-
f"\x1b[1;31merror: option {v.name} description uses DocBook\x1b[0m",
file=sys.stderr)
elif is_docbook(v.value, 'defaultText'):
-
hasErrors = True
-
hasDocBookErrors = True
print(
-
f"\x1b[1;31merror: option {v.name} default uses DocBook\x1b[0m",
file=sys.stderr)
elif is_docbook(v.value, 'example'):
-
hasErrors = True
-
hasDocBookErrors = True
print(
-
f"\x1b[1;31merror: option {v.name} example uses DocBook\x1b[0m",
file=sys.stderr)
if v.value.get('description', None) is None:
···
f"\x1b[1;31m{severity}: option {v.name} has no type. Please specify a valid type, see " +
"https://nixos.org/manual/nixos/stable/index.html#sec-option-types\x1b[0m", file=sys.stderr)
-
if hasDocBookErrors:
print("Explanation: The documentation contains descriptions, examples, or defaults written in DocBook. " +
"NixOS is in the process of migrating from DocBook to Markdown, and " +
-
"DocBook is disallowed for in-tree modules. To change your contribution to "+
"use Markdown, apply mdDoc and literalMD and use the *MD variants of option creation " +
"functions where they are available. For example:\n" +
"\n" +
···
" example.package = mkPackageOptionMD pkgs \"your-package\" {};\n" +
" imports = [ (mkAliasOptionModuleMD [ \"example\" \"args\" ] [ \"example\" \"settings\" ]) ];",
file = sys.stderr)
if hasErrors:
sys.exit(1)
···
return options
warningsAreErrors = False
+
warnOnDocbook = False
errorOnDocbook = False
markdownByDefault = False
optOffset = 0
···
if arg == "--warnings-are-errors":
optOffset += 1
warningsAreErrors = True
+
if arg == "--warn-on-docbook":
+
optOffset += 1
+
warnOnDocbook = True
+
elif arg == "--error-on-docbook":
optOffset += 1
errorOnDocbook = True
if arg == "--markdown-by-default":
···
# check that every option has a description
hasWarnings = False
hasErrors = False
+
hasDocBook = False
for (k, v) in options.items():
+
if warnOnDocbook or errorOnDocbook:
+
kind = "error" if errorOnDocbook else "warning"
if isinstance(v.value.get('description', {}), str):
+
hasErrors |= errorOnDocbook
+
hasDocBook = True
print(
+
f"\x1b[1;31m{kind}: option {v.name} description uses DocBook\x1b[0m",
file=sys.stderr)
elif is_docbook(v.value, 'defaultText'):
+
hasErrors |= errorOnDocbook
+
hasDocBook = True
print(
+
f"\x1b[1;31m{kind}: option {v.name} default uses DocBook\x1b[0m",
file=sys.stderr)
elif is_docbook(v.value, 'example'):
+
hasErrors |= errorOnDocbook
+
hasDocBook = True
print(
+
f"\x1b[1;31m{kind}: option {v.name} example uses DocBook\x1b[0m",
file=sys.stderr)
if v.value.get('description', None) is None:
···
f"\x1b[1;31m{severity}: option {v.name} has no type. Please specify a valid type, see " +
"https://nixos.org/manual/nixos/stable/index.html#sec-option-types\x1b[0m", file=sys.stderr)
+
if hasDocBook:
+
(why, what) = (
+
("disallowed for in-tree modules", "contribution") if errorOnDocbook
+
else ("deprecated for option documentation", "module")
+
)
print("Explanation: The documentation contains descriptions, examples, or defaults written in DocBook. " +
"NixOS is in the process of migrating from DocBook to Markdown, and " +
+
f"DocBook is {why}. To change your {what} to "+
"use Markdown, apply mdDoc and literalMD and use the *MD variants of option creation " +
"functions where they are available. For example:\n" +
"\n" +
···
" example.package = mkPackageOptionMD pkgs \"your-package\" {};\n" +
" imports = [ (mkAliasOptionModuleMD [ \"example\" \"args\" ] [ \"example\" \"settings\" ]) ];",
file = sys.stderr)
+
with open(os.getenv('TOUCH_IF_DB'), 'x'):
+
# just make sure it exists
+
pass
if hasErrors:
sys.exit(1)
+1 -1
nixos/lib/testing/testScript.nix
···
options = {
testScript = mkOption {
type = either str (functionTo str);
-
description = ''
A series of python declarations and statements that you write to perform
the test.
'';
···
options = {
testScript = mkOption {
type = either str (functionTo str);
+
description = mdDoc ''
A series of python declarations and statements that you write to perform
the test.
'';
+8
nixos/modules/misc/documentation.nix
···
(mkIf cfg.nixos.enable {
system.build.manual = manual;
environment.systemPackages = []
++ optional cfg.man.enable manual.manpages
++ optionals cfg.doc.enable [ manual.manualHTML nixos-help ];
···
(mkIf cfg.nixos.enable {
system.build.manual = manual;
+
system.activationScripts.check-manual-docbook = ''
+
if [[ $(cat ${manual.optionsUsedDocbook}) = 1 ]]; then
+
echo -e "\e[31;1mwarning\e[0m: This configuration contains option documentation in docbook." \
+
"Support for docbook is deprecated and will be removed after NixOS 23.05." \
+
"See nix-store --read-log ${builtins.unsafeDiscardStringContext manual.optionsJSON.drvPath}"
+
fi
+
'';
+
environment.systemPackages = []
++ optional cfg.man.enable manual.manpages
++ optionals cfg.doc.enable [ manual.manualHTML nixos-help ];