-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
nixos: doc: implement related packages in the manual (again) #33898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee32204
lib: implement `compare`, `splitByAndCompare`, and `compareLists`
oxij a7d75ab
nixos/doc: push all the `enable*' and `package*` options to the top o…
oxij 6608060
nixos, lib: implement relatedPackages option
oxij eb38b86
nixos/tmux: add related package
oxij e526834
nixos/adb: add related package
oxij 06adc17
xen, qemu: passthru the path to qemu-system-i386
oxij 0d1a643
nixos/xen-dom0: add related packages, make it play well with them
oxij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ let | |
| 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: | ||
|
|
@@ -15,13 +15,43 @@ let | |
| else if lib.isFunction x then "<function>" | ||
| else x; | ||
|
|
||
| # Clean up declaration sites to not refer to the NixOS source tree. | ||
| optionsList' = lib.flip map optionsList (opt: opt // { | ||
| # 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 | ||
| # - a string: that will be interpreted as an attribute name from `pkgs`, | ||
| # - a list: that will be interpreted as an attribute path from `pkgs`, | ||
| # - an attrset: that can specify `name`, `path`, `package`, `comment` | ||
| # (either of `name`, `path` is required, the rest are optional). | ||
| genRelatedPackages = packages: | ||
| let | ||
| unpack = p: if lib.isString p then { name = p; } | ||
| else if lib.isList p then { path = p; } | ||
| else p; | ||
| describe = args: | ||
| let | ||
| name = args.name or (lib.concatStringsSep "." args.path); | ||
| path = args.path or [ args.name ]; | ||
| package = args.package or (lib.attrByPath path (throw "Invalid package attribute path `${toString path}'") pkgs); | ||
| in "<listitem>" | ||
| + "<para><literal>pkgs.${name} (${package.meta.name})</literal>" | ||
| + lib.optionalString (!package.meta.evaluates) " <emphasis>[UNAVAILABLE]</emphasis>" | ||
| + ": ${package.meta.description or "???"}.</para>" | ||
| + lib.optionalString (args ? comment) "\n<para>${args.comment}</para>" | ||
| # Lots of `longDescription's break DocBook, so we just wrap them into <programlisting> | ||
| + lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>" | ||
| + "</listitem>"; | ||
| in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>"; | ||
|
|
||
| optionsListDesc = lib.flip map optionsListVisible (opt: opt // { | ||
| # Clean up declaration sites to not refer to the NixOS source tree. | ||
| declarations = map stripAnyPrefixes opt.declarations; | ||
| } | ||
| // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; } | ||
| // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; } | ||
| // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }); | ||
| // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; } | ||
| // lib.optionalAttrs (opt ? relatedPackages) { relatedPackages = genRelatedPackages opt.relatedPackages; }); | ||
|
|
||
| # We need to strip references to /nix/store/* from options, | ||
| # including any `extraSources` if some modules came from elsewhere, | ||
|
|
@@ -32,8 +62,22 @@ let | |
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the cause of the slowdown, the cost of sorting all of the options happens during every evaluation. |
||
|
|
||
| # 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} | ||
|
|
@@ -191,7 +235,7 @@ in rec { | |
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the intentions behind making the inherits explicit here is so we don't need to make all the lib functions available in the top level, but instead say
lib.lists.compareLists. If this seems like a reasonable thing to do, would you like to notinheritthem here? It could be we're just not ready for that yet, seeing as I don't think many functions aren't exposed at the top level here.