diff options
| author | pennae <82953136+pennae@users.noreply.github.com> | 2023-01-06 02:20:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-06 02:20:32 +0100 |
| commit | 2dea8991d89b9f1e78d874945f78ca15f6954289 (patch) | |
| tree | 8cdadfecc86c881328125df3b8d2f78bcab48f3a | |
| parent | Merge pull request #209239 from NixOS/backport-205541-to-release-22.11 (diff) | |
| parent | lib/modules: hide _module.args docs (diff) | |
| download | nixpkgs-2dea8991d89b9f1e78d874945f78ca15f6954289.tar.gz | |
Merge pull request #209125 from pennae/mddoc-fixes-2211
[22.11] doc: markdown transition fixes
22 files changed, 64 insertions, 29 deletions
diff --git a/lib/default.nix b/lib/default.nix index cc4bedc5869b..05869f2344e9 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -127,14 +127,15 @@ let mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule mkRenamedOptionModule mkRenamedOptionModuleWith mkMergedOptionModule mkChangedOptionModule - mkAliasOptionModule mkDerivedConfig doRename; + mkAliasOptionModule mkDerivedConfig doRename + mkAliasOptionModuleMD; inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption getValues getFiles optionAttrSetToDocList optionAttrSetToDocList' scrubOptionValue literalExpression literalExample literalDocBook showOption showOptionWithDefLocs showFiles - unknownModule mkOption mkPackageOption + unknownModule mkOption mkPackageOption mkPackageOptionMD mdDoc literalMD; inherit (self.types) isType setType defaultTypeMerge defaultFunctor isOptionType mkOptionType; diff --git a/lib/modules.nix b/lib/modules.nix index 23e531de5c3a..cea34b0d8436 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -157,6 +157,11 @@ rec { ${if prefix == [] then null # unset => visible else "internal"} = true; + # TODO: hidden during the markdown transition to not expose downstream + # users of the docs infra to markdown if they're not ready for it. + # we don't make this visible conditionally because it can impact + # performance (https://github.com/NixOS/nixpkgs/pull/208407#issuecomment-1368246192) + visible = false; # TODO: Change the type of this option to a submodule with a # freeformType, so that individual arguments can be documented # separately @@ -1107,6 +1112,15 @@ rec { visible = true; warn = false; use = id; + wrapDescription = lib.id; + }; + + /* Transitional version of mkAliasOptionModule that uses MD docs. */ + mkAliasOptionModuleMD = from: to: doRename { + inherit from to; + visible = true; + warn = false; + use = id; }; /* mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b @@ -1129,7 +1143,7 @@ rec { (opt.highestPrio or defaultPriority) (f opt.value); - doRename = { from, to, visible, warn, use, withPriority ? true }: + doRename = { from, to, visible, warn, use, withPriority ? true, wrapDescription ? lib.mdDoc }: { config, options, ... }: let fromOpt = getAttrFromPath from options; @@ -1140,7 +1154,7 @@ rec { { options = setAttrByPath from (mkOption { inherit visible; - description = lib.mdDoc "Alias of {option}`${showOption to}`."; + description = wrapDescription "Alias of {option}`${showOption to}`."; apply = x: use (toOf config); } // optionalAttrs (toType != null) { type = toType; diff --git a/lib/options.nix b/lib/options.nix index c80256c0e653..af5db8eff2fd 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -136,7 +136,7 @@ rec { let default' = if !isList default then [ default ] else default; in mkOption { type = lib.types.package; - description = lib.mdDoc "The ${name} package to use."; + description = "The ${name} package to use."; default = attrByPath default' (throw "${concatStringsSep "." default'} cannot be found in pkgs") pkgs; defaultText = literalExpression ("pkgs." + concatStringsSep "." default'); @@ -144,6 +144,11 @@ rec { (if isList example then "pkgs." + concatStringsSep "." example else example); }; + /* Like mkPackageOption, but emit an mdDoc description instead of DocBook. */ + mkPackageOptionMD = args: name: extra: + let option = mkPackageOption args name extra; + in option // { description = lib.mdDoc option.description; }; + /* This option accepts anything, but it does not produce any result. This is useful for sharing a module across different module sets diff --git a/nixos/doc/manual/development/option-declarations.section.md b/nixos/doc/manual/development/option-declarations.section.md index 88617ab1920a..6e3d621abf08 100644 --- a/nixos/doc/manual/development/option-declarations.section.md +++ b/nixos/doc/manual/development/option-declarations.section.md @@ -88,7 +88,7 @@ lib.mkOption { } ``` -### `mkPackageOption` {#sec-option-declarations-util-mkPackageOption} +### `mkPackageOption`, `mkPackageOptionMD` {#sec-option-declarations-util-mkPackageOption} Usage: @@ -106,6 +106,8 @@ The second argument is the name of the option, used in the description "The \<na You can omit the default path if the name of the option is also attribute path in nixpkgs. +During the transition to CommonMark documentation `mkPackageOption` creates an option with a DocBook description attribute, once the transition is completed it will create a CommonMark description instead. `mkPackageOptionMD` always creates an option with a CommonMark description attribute and will be removed some time after the transition is completed. + ::: {#ex-options-declarations-util-mkPackageOption .title} Examples: diff --git a/nixos/doc/manual/from_md/development/option-declarations.section.xml b/nixos/doc/manual/from_md/development/option-declarations.section.xml index 0932a51a18cd..5c8358507de2 100644 --- a/nixos/doc/manual/from_md/development/option-declarations.section.xml +++ b/nixos/doc/manual/from_md/development/option-declarations.section.xml @@ -138,7 +138,8 @@ lib.mkOption { } </programlisting> <section xml:id="sec-option-declarations-util-mkPackageOption"> - <title><literal>mkPackageOption</literal></title> + <title><literal>mkPackageOption</literal>, + <literal>mkPackageOptionMD</literal></title> <para> Usage: </para> @@ -172,6 +173,15 @@ mkPackageOption pkgs "name" { default = [ "path" "in&qu You can omit the default path if the name of the option is also attribute path in nixpkgs. </para> + <para> + During the transition to CommonMark documentation + <literal>mkPackageOption</literal> creates an option with a + DocBook description attribute, once the transition is + completed it will create a CommonMark description instead. + <literal>mkPackageOptionMD</literal> always creates an option + with a CommonMark description attribute and will be removed + some time after the transition is completed. + </para> <anchor xml:id="ex-options-declarations-util-mkPackageOption" /> <para> Examples: diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py index 750cd24fc653..7b14af40c313 100644 --- a/nixos/lib/make-options-doc/mergeJSON.py +++ b/nixos/lib/make-options-doc/mergeJSON.py @@ -306,14 +306,17 @@ 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. For example:\n" + + "use Markdown, apply mdDoc and literalMD and use the *MD variants of option creation " + + "functions where they are available. For example:\n" + "\n" + " example.foo = mkOption {\n" + " description = lib.mdDoc ''your description'';\n" + " defaultText = lib.literalMD ''your description of default'';\n" + - " }\n" + + " };\n" + "\n" + - " example.enable = mkEnableOption (lib.mdDoc ''your thing'');", + " example.enable = mkEnableOption (lib.mdDoc ''your thing'');\n" + + " example.package = mkPackageOptionMD pkgs \"your-package\" {};\n" + + " imports = [ (mkAliasOptionModuleMD [ \"example\" \"args\" ] [ \"example\" \"settings\" ]) ];", file = sys.stderr) if hasErrors: diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index 2660b0e6c938..bf95fe539478 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -447,8 +447,8 @@ let in { imports = [ - (mkAliasOptionModule [ "users" "extraUsers" ] [ "users" "users" ]) - (mkAliasOptionModule [ "users" "extraGroups" ] [ "users" "groups" ]) + (mkAliasOptionModuleMD [ "users" "extraUsers" ] [ "users" "users" ]) + (mkAliasOptionModuleMD [ "users" "extraGroups" ] [ "users" "groups" ]) (mkRenamedOptionModule ["security" "initialRootPassword"] ["users" "users" "root" "initialHashedPassword"]) ]; diff --git a/nixos/modules/programs/_1password-gui.nix b/nixos/modules/programs/_1password-gui.nix index 83ef6037fb5a..27c0d34a2eed 100644 --- a/nixos/modules/programs/_1password-gui.nix +++ b/nixos/modules/programs/_1password-gui.nix @@ -27,7 +27,7 @@ in ''; }; - package = mkPackageOption pkgs "1Password GUI" { + package = mkPackageOptionMD pkgs "1Password GUI" { default = [ "_1password-gui" ]; }; }; diff --git a/nixos/modules/programs/_1password.nix b/nixos/modules/programs/_1password.nix index 91246150755d..8537484c7e67 100644 --- a/nixos/modules/programs/_1password.nix +++ b/nixos/modules/programs/_1password.nix @@ -18,7 +18,7 @@ in programs._1password = { enable = mkEnableOption (lib.mdDoc "the 1Password CLI tool"); - package = mkPackageOption pkgs "1Password CLI" { + package = mkPackageOptionMD pkgs "1Password CLI" { default = [ "_1password" ]; }; }; diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index aef42d0f4db1..d88baac7a5d4 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -14,7 +14,7 @@ with lib; # This alias module can't be where _module.check is defined because it would # be added to submodules as well there - (mkAliasOptionModule [ "environment" "checkConfigurationOptions" ] [ "_module" "check" ]) + (mkAliasOptionModuleMD [ "environment" "checkConfigurationOptions" ] [ "_module" "check" ]) # Completely removed modules (mkRemovedOptionModule [ "environment" "blcr" "enable" ] "The BLCR module has been removed") diff --git a/nixos/modules/services/databases/dgraph.nix b/nixos/modules/services/databases/dgraph.nix index 5726851a43f9..887164fa5b94 100644 --- a/nixos/modules/services/databases/dgraph.nix +++ b/nixos/modules/services/databases/dgraph.nix @@ -55,7 +55,7 @@ in services.dgraph = { enable = mkEnableOption (lib.mdDoc "Dgraph native GraphQL database with a graph backend"); - package = lib.mkPackageOption pkgs "dgraph" { }; + package = lib.mkPackageOptionMD pkgs "dgraph" { }; settings = mkOption { type = settingsFormat.type; diff --git a/nixos/modules/services/mail/listmonk.nix b/nixos/modules/services/mail/listmonk.nix index c4ea6747196c..844c561b019f 100644 --- a/nixos/modules/services/mail/listmonk.nix +++ b/nixos/modules/services/mail/listmonk.nix @@ -128,7 +128,7 @@ in { ''; }; }; - package = mkPackageOption pkgs "listmonk" {}; + package = mkPackageOptionMD pkgs "listmonk" {}; settings = mkOption { type = types.submodule { freeformType = tomlFormat.type; }; description = lib.mdDoc '' diff --git a/nixos/modules/services/misc/input-remapper.nix b/nixos/modules/services/misc/input-remapper.nix index 51e1abdc98a0..6353966f5c3f 100644 --- a/nixos/modules/services/misc/input-remapper.nix +++ b/nixos/modules/services/misc/input-remapper.nix @@ -7,7 +7,7 @@ let cfg = config.services.input-remapper; in options = { services.input-remapper = { enable = mkEnableOption (lib.mdDoc "input-remapper, an easy to use tool to change the mapping of your input device buttons."); - package = options.mkPackageOption pkgs "input-remapper" { }; + package = mkPackageOptionMD pkgs "input-remapper" { }; enableUdevRules = mkEnableOption (lib.mdDoc "udev rules added by input-remapper to handle hotplugged devices. Currently disabled by default due to https://github.com/sezanzeb/input-remapper/issues/140"); serviceWantedBy = mkOption { default = [ "graphical.target" ]; diff --git a/nixos/modules/services/misc/polaris.nix b/nixos/modules/services/misc/polaris.nix index 83da486083b4..70f097f02840 100644 --- a/nixos/modules/services/misc/polaris.nix +++ b/nixos/modules/services/misc/polaris.nix @@ -13,7 +13,7 @@ in services.polaris = { enable = mkEnableOption (lib.mdDoc "Polaris Music Server"); - package = mkPackageOption pkgs "polaris" { }; + package = mkPackageOptionMD pkgs "polaris" { }; user = mkOption { type = types.str; diff --git a/nixos/modules/services/networking/openconnect.nix b/nixos/modules/services/networking/openconnect.nix index 469f0a3bc3bb..c4100bd8e992 100644 --- a/nixos/modules/services/networking/openconnect.nix +++ b/nixos/modules/services/networking/openconnect.nix @@ -115,7 +115,7 @@ let }; in { options.networking.openconnect = { - package = mkPackageOption pkgs "openconnect" { }; + package = mkPackageOptionMD pkgs "openconnect" { }; interfaces = mkOption { description = lib.mdDoc "OpenConnect interfaces."; diff --git a/nixos/modules/services/networking/shellhub-agent.nix b/nixos/modules/services/networking/shellhub-agent.nix index ad33c50f9d63..7cce23cb9c4e 100644 --- a/nixos/modules/services/networking/shellhub-agent.nix +++ b/nixos/modules/services/networking/shellhub-agent.nix @@ -14,7 +14,7 @@ in enable = mkEnableOption (lib.mdDoc "ShellHub Agent daemon"); - package = mkPackageOption pkgs "shellhub-agent" { }; + package = mkPackageOptionMD pkgs "shellhub-agent" { }; preferredHostname = mkOption { type = types.str; diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index af8200c7e295..37d7518ab3c4 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -79,8 +79,8 @@ in { imports = [ - (mkAliasOptionModule [ "services" "sshd" "enable" ] [ "services" "openssh" "enable" ]) - (mkAliasOptionModule [ "services" "openssh" "knownHosts" ] [ "programs" "ssh" "knownHosts" ]) + (mkAliasOptionModuleMD [ "services" "sshd" "enable" ] [ "services" "openssh" "enable" ]) + (mkAliasOptionModuleMD [ "services" "openssh" "knownHosts" ] [ "programs" "ssh" "knownHosts" ]) (mkRenamedOptionModule [ "services" "openssh" "challengeResponseAuthentication" ] [ "services" "openssh" "kbdInteractiveAuthentication" ]) ]; diff --git a/nixos/modules/services/networking/vdirsyncer.nix b/nixos/modules/services/networking/vdirsyncer.nix index 6a069943434d..f9b880c763e3 100644 --- a/nixos/modules/services/networking/vdirsyncer.nix +++ b/nixos/modules/services/networking/vdirsyncer.nix @@ -71,7 +71,7 @@ in services.vdirsyncer = { enable = mkEnableOption (mdDoc "vdirsyncer"); - package = mkPackageOption pkgs "vdirsyncer" {}; + package = mkPackageOptionMD pkgs "vdirsyncer" {}; jobs = mkOption { description = mdDoc "vdirsyncer job configurations"; diff --git a/nixos/modules/services/torrent/transmission.nix b/nixos/modules/services/torrent/transmission.nix index 9b53f5de143d..2d487ac3691b 100644 --- a/nixos/modules/services/torrent/transmission.nix +++ b/nixos/modules/services/torrent/transmission.nix @@ -19,8 +19,8 @@ in imports = [ (mkRenamedOptionModule ["services" "transmission" "port"] ["services" "transmission" "settings" "rpc-port"]) - (mkAliasOptionModule ["services" "transmission" "openFirewall"] - ["services" "transmission" "openPeerPorts"]) + (mkAliasOptionModuleMD ["services" "transmission" "openFirewall"] + ["services" "transmission" "openPeerPorts"]) ]; options = { services.transmission = { diff --git a/nixos/modules/services/x11/picom.nix b/nixos/modules/services/x11/picom.nix index 56b55709e47f..5342e132743f 100644 --- a/nixos/modules/services/x11/picom.nix +++ b/nixos/modules/services/x11/picom.nix @@ -41,7 +41,7 @@ let in { imports = [ - (mkAliasOptionModule [ "services" "compton" ] [ "services" "picom" ]) + (mkAliasOptionModuleMD [ "services" "compton" ] [ "services" "picom" ]) (mkRemovedOptionModule [ "services" "picom" "refreshRate" ] '' This option corresponds to `refresh-rate`, which has been unused since picom v6 and was subsequently removed by upstream. diff --git a/nixos/modules/services/x11/window-managers/qtile.nix b/nixos/modules/services/x11/window-managers/qtile.nix index 523642591d94..fc27566d49ee 100644 --- a/nixos/modules/services/x11/window-managers/qtile.nix +++ b/nixos/modules/services/x11/window-managers/qtile.nix @@ -10,7 +10,7 @@ in options.services.xserver.windowManager.qtile = { enable = mkEnableOption (lib.mdDoc "qtile"); - package = mkPackageOption pkgs "qtile" { }; + package = mkPackageOptionMD pkgs "qtile" { }; }; config = mkIf cfg.enable { diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 31702499b0f1..029d57cc7360 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -142,7 +142,7 @@ in { ''; }; - package = (mkPackageOption pkgs "systemd" { + package = (mkPackageOptionMD pkgs "systemd" { default = "systemdStage1"; }) // { visible = false; |
