···56 replaceStrings seq stringLength sub substring tail;
57 inherit (trivial) id const concat or and boolToString mergeAttrs
58 flip mapNullable inNixShell min max importJSON warn info
59- nixpkgsVersion mod;
6061 inherit (fixedPoints) fix fix' extends composeExtensions
62 makeExtensible makeExtensibleWithCustomName;
···71 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
72 concatMap flatten remove findSingle findFirst any all count
73 optional optionals toList range partition zipListsWith zipLists
74- reverseList listDfs toposort sort take drop sublist last init
75- crossLists unique intersectLists subtractLists
76 mutuallyExclusive;
77 inherit (strings) concatStrings concatMapStrings concatImapStrings
78 intersperse concatStringsSep concatMapStringsSep
···56 replaceStrings seq stringLength sub substring tail;
57 inherit (trivial) id const concat or and boolToString mergeAttrs
58 flip mapNullable inNixShell min max importJSON warn info
59+ nixpkgsVersion mod compare splitByAndCompare;
6061 inherit (fixedPoints) fix fix' extends composeExtensions
62 makeExtensible makeExtensibleWithCustomName;
···71 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
72 concatMap flatten remove findSingle findFirst any all count
73 optional optionals toList range partition zipListsWith zipLists
74+ reverseList listDfs toposort sort compareLists take drop sublist
75+ last init crossLists unique intersectLists subtractLists
76 mutuallyExclusive;
77 inherit (strings) concatStrings concatMapStrings concatImapStrings
78 intersperse concatStringsSep concatMapStringsSep
+24
lib/lists.nix
···385 if len < 2 then list
386 else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
387000000000000000000000000388 /* Return the first (at most) N elements of a list.
389390 Example:
···385 if len < 2 then list
386 else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
387388+ /* Compare two lists element-by-element.
389+390+ Example:
391+ compareLists compare [] []
392+ => 0
393+ compareLists compare [] [ "a" ]
394+ => -1
395+ compareLists compare [ "a" ] []
396+ => 1
397+ compareLists compare [ "a" "b" ] [ "a" "c" ]
398+ => 1
399+ */
400+ compareLists = cmp: a: b:
401+ if a == []
402+ then if b == []
403+ then 0
404+ else -1
405+ else if b == []
406+ then 1
407+ else let rel = cmp (head a) (head b); in
408+ if rel == 0
409+ then compareLists cmp (tail a) (tail b)
410+ else rel;
411+412 /* Return the first (at most) N elements of a list.
413414 Example:
+5-4
lib/options.nix
···14 , defaultText ? null # Textual representation of the default, for in the manual.
15 , example ? null # Example value used in the manual.
16 , description ? null # String describing the option.
017 , type ? null # Option type, providing type-checking and value merging.
18 , apply ? null # Function that converts the option value to something else.
19 , internal ? null # Whether the option is for NixOS developers only.
···76 getValues = map (x: x.value);
77 getFiles = map (x: x.file);
7879-80 # Generate documentation template from the list of option declaration like
81 # the set generated with filterOptionSets.
82 optionAttrSetToDocList = optionAttrSetToDocList' [];
···93 readOnly = opt.readOnly or false;
94 type = opt.type.description or null;
95 }
96- // (if opt ? example then { example = scrubOptionValue opt.example; } else {})
97- // (if opt ? default then { default = scrubOptionValue opt.default; } else {})
98- // (if opt ? defaultText then { default = opt.defaultText; } else {});
099100 subOptions =
101 let ss = opt.type.getSubOptions opt.loc;
···14 , defaultText ? null # Textual representation of the default, for in the manual.
15 , example ? null # Example value used in the manual.
16 , description ? null # String describing the option.
17+ , relatedPackages ? null # Related packages used in the manual.
18 , type ? null # Option type, providing type-checking and value merging.
19 , apply ? null # Function that converts the option value to something else.
20 , internal ? null # Whether the option is for NixOS developers only.
···77 getValues = map (x: x.value);
78 getFiles = map (x: x.file);
79080 # Generate documentation template from the list of option declaration like
81 # the set generated with filterOptionSets.
82 optionAttrSetToDocList = optionAttrSetToDocList' [];
···93 readOnly = opt.readOnly or false;
94 type = opt.type.description or null;
95 }
96+ // optionalAttrs (opt ? example) { example = scrubOptionValue opt.example; }
97+ // optionalAttrs (opt ? default) { default = scrubOptionValue opt.default; }
98+ // optionalAttrs (opt ? defaultText) { default = opt.defaultText; }
99+ // optionalAttrs (opt ? relatedPackages && opt.relatedPackages != null) { inherit (opt) relatedPackages; };
100101 subOptions =
102 let ss = opt.type.getSubOptions opt.loc;
+25
lib/trivial.nix
···81 */
82 mod = base: int: base - (int * (builtins.div base int));
83000000000000000000000000084 /* Reads a JSON file. */
85 importJSON = path:
86 builtins.fromJSON (builtins.readFile path);
···81 */
82 mod = base: int: base - (int * (builtins.div base int));
8384+ /* C-style comparisons
85+86+ a < b => -1
87+ a == b => 0
88+ a > b => 1
89+ */
90+ compare = a: b:
91+ if a < b
92+ then -1
93+ else if a > b
94+ then 1
95+ else 0;
96+97+ /* Split type into two subtypes by predicate `p`, assume
98+99+ forall x y . x < y if p x == true && p y == false
100+101+ compare elements of the same subtype with `yes` and `no`
102+ comparisons respectively.
103+ */
104+ splitByAndCompare = p: yes: no: a: b:
105+ if p a
106+ then if p b then yes a b else -1
107+ else if p b then 1 else no a b;
108+109 /* Reads a JSON file. */
110 importJSON = path:
111 builtins.fromJSON (builtins.readFile path);
+31-3
nixos/doc/manual/default.nix
···15 else if builtins.isFunction x then "<function>"
16 else x;
1718- # Clean up declaration sites to not refer to the NixOS source tree.
00000000000019 optionsList' = lib.flip map optionsList (opt: opt // {
020 declarations = map stripAnyPrefixes opt.declarations;
21 }
22 // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
23 // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
24- // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; });
02526 # We need to strip references to /nix/store/* from options,
27 # including any `extraSources` if some modules came from elsewhere,
···32 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
33 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
340000000000000035 # Convert the list of options into an XML file.
36- optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
3738 optionsDocBook = runCommand "options-db.xml" {} ''
39 optionsXML=${optionsXML}
···15 else if builtins.isFunction x then "<function>"
16 else x;
1718+ # Generate DocBook documentation for a list of packages
19+ genRelatedPackages = packages:
20+ let
21+ unpack = p: if lib.isString p then { name = p; } else p;
22+ describe = { name, package ? pkgs.${name}, comment ? "" }:
23+ "<listitem>"
24+ + "<para><option>pkgs.${name}</option> (${package.name}): ${package.meta.description or "???"}.</para>"
25+ + lib.optionalString (comment != "") "\n<para>${comment}</para>"
26+ # Lots of `longDescription's break DocBook, so we just wrap them into <programlisting>
27+ + lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>"
28+ + "</listitem>";
29+ in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>";
30+31 optionsList' = lib.flip map optionsList (opt: opt // {
32+ # Clean up declaration sites to not refer to the NixOS source tree.
33 declarations = map stripAnyPrefixes opt.declarations;
34 }
35 // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
36 // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
37+ // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }
38+ // lib.optionalAttrs (opt ? relatedPackages) { relatedPackages = genRelatedPackages opt.relatedPackages; });
3940 # We need to strip references to /nix/store/* from options,
41 # including any `extraSources` if some modules came from elsewhere,
···46 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
47 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
4849+ # Custom "less" that pushes up all the things ending in ".enable*"
50+ # and ".package"
51+ optionListLess = a: b:
52+ let
53+ splt = lib.splitString ".";
54+ ise = lib.hasPrefix "enable";
55+ isp = lib.hasPrefix "package";
56+ cmp = lib.splitByAndCompare ise lib.compare
57+ (lib.splitByAndCompare isp lib.compare lib.compare);
58+ in lib.compareLists cmp (splt a) (splt b) < 0;
59+60+ # Customly sort option list for the man page.
61+ optionsList'' = lib.sort (a: b: optionListLess a.name b.name) optionsList';
62+63 # Convert the list of options into an XML file.
64+ optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'');
6566 optionsDocBook = runCommand "options-db.xml" {} ''
67 optionsXML=${optionsXML}