nixos/doc: push all the `enable*' and `package*` options to the top of their option group

Why? Because this way configuration.nix(5) can be read linearly.

Before:

> virtualisation.xen.bootParams
> ...
> virtualisation.xen.enable
> ...
> virtualisation.xen.package
> ...

After:

> virtualisation.xen.enable
> virtualisation.xen.package
> virtualisation.xen.bootParams
> ...

Changed files
+18 -4
nixos
doc
manual
+18 -4
nixos/doc/manual/default.nix
···
lib = pkgs.lib;
# Remove invisible and internal options.
-
optionsList = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
+
optionsListVisible = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
# Replace functions by the string <function>
substFunction = x:
···
else x;
# Clean up declaration sites to not refer to the NixOS source tree.
-
optionsList' = lib.flip map optionsList (opt: opt // {
+
optionsListDesc = lib.flip map optionsListVisible (opt: opt // {
declarations = map stripAnyPrefixes opt.declarations;
}
// lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
···
prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
+
# Custom "less" that pushes up all the things ending in ".enable*"
+
# and ".package"
+
optionListLess = a: b:
+
let
+
splt = lib.splitString ".";
+
ise = lib.hasPrefix "enable";
+
isp = lib.hasPrefix "package";
+
cmp = lib.splitByAndCompare ise lib.compare
+
(lib.splitByAndCompare isp lib.compare lib.compare);
+
in lib.compareLists cmp (splt a) (splt b) < 0;
+
+
# Customly sort option list for the man page.
+
optionsList = lib.sort (a: b: optionListLess a.name b.name) optionsListDesc;
+
# Convert the list of options into an XML file.
-
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
+
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList);
optionsDocBook = runCommand "options-db.xml" {} ''
optionsXML=${optionsXML}
···
mkdir -p $dst
cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
-
(builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList'))))
+
(builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList))))
} $dst/options.json
mkdir -p $out/nix-support