···5656 replaceStrings seq stringLength sub substring tail;
5757 inherit (trivial) id const concat or and boolToString mergeAttrs
5858 flip mapNullable inNixShell min max importJSON warn info
5959- nixpkgsVersion mod;
5959+ nixpkgsVersion mod compare splitByAndCompare;
60606161 inherit (fixedPoints) fix fix' extends composeExtensions
6262 makeExtensible makeExtensibleWithCustomName;
···7171 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
7272 concatMap flatten remove findSingle findFirst any all count
7373 optional optionals toList range partition zipListsWith zipLists
7474- reverseList listDfs toposort sort take drop sublist last init
7575- crossLists unique intersectLists subtractLists
7474+ reverseList listDfs toposort sort compareLists take drop sublist
7575+ last init crossLists unique intersectLists subtractLists
7676 mutuallyExclusive;
7777 inherit (strings) concatStrings concatMapStrings concatImapStrings
7878 intersperse concatStringsSep concatMapStringsSep
+24
lib/lists.nix
···385385 if len < 2 then list
386386 else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
387387388388+ /* Compare two lists element-by-element.
389389+390390+ Example:
391391+ compareLists compare [] []
392392+ => 0
393393+ compareLists compare [] [ "a" ]
394394+ => -1
395395+ compareLists compare [ "a" ] []
396396+ => 1
397397+ compareLists compare [ "a" "b" ] [ "a" "c" ]
398398+ => 1
399399+ */
400400+ compareLists = cmp: a: b:
401401+ if a == []
402402+ then if b == []
403403+ then 0
404404+ else -1
405405+ else if b == []
406406+ then 1
407407+ else let rel = cmp (head a) (head b); in
408408+ if rel == 0
409409+ then compareLists cmp (tail a) (tail b)
410410+ else rel;
411411+388412 /* Return the first (at most) N elements of a list.
389413390414 Example:
+5-4
lib/options.nix
···1414 , defaultText ? null # Textual representation of the default, for in the manual.
1515 , example ? null # Example value used in the manual.
1616 , description ? null # String describing the option.
1717+ , relatedPackages ? null # Related packages used in the manual.
1718 , type ? null # Option type, providing type-checking and value merging.
1819 , apply ? null # Function that converts the option value to something else.
1920 , internal ? null # Whether the option is for NixOS developers only.
···7677 getValues = map (x: x.value);
7778 getFiles = map (x: x.file);
78797979-8080 # Generate documentation template from the list of option declaration like
8181 # the set generated with filterOptionSets.
8282 optionAttrSetToDocList = optionAttrSetToDocList' [];
···9393 readOnly = opt.readOnly or false;
9494 type = opt.type.description or null;
9595 }
9696- // (if opt ? example then { example = scrubOptionValue opt.example; } else {})
9797- // (if opt ? default then { default = scrubOptionValue opt.default; } else {})
9898- // (if opt ? defaultText then { default = opt.defaultText; } else {});
9696+ // optionalAttrs (opt ? example) { example = scrubOptionValue opt.example; }
9797+ // optionalAttrs (opt ? default) { default = scrubOptionValue opt.default; }
9898+ // optionalAttrs (opt ? defaultText) { default = opt.defaultText; }
9999+ // optionalAttrs (opt ? relatedPackages && opt.relatedPackages != null) { inherit (opt) relatedPackages; };
99100100101 subOptions =
101102 let ss = opt.type.getSubOptions opt.loc;
+25
lib/trivial.nix
···8181 */
8282 mod = base: int: base - (int * (builtins.div base int));
83838484+ /* C-style comparisons
8585+8686+ a < b => -1
8787+ a == b => 0
8888+ a > b => 1
8989+ */
9090+ compare = a: b:
9191+ if a < b
9292+ then -1
9393+ else if a > b
9494+ then 1
9595+ else 0;
9696+9797+ /* Split type into two subtypes by predicate `p`, assume
9898+9999+ forall x y . x < y if p x == true && p y == false
100100+101101+ compare elements of the same subtype with `yes` and `no`
102102+ comparisons respectively.
103103+ */
104104+ splitByAndCompare = p: yes: no: a: b:
105105+ if p a
106106+ then if p b then yes a b else -1
107107+ else if p b then 1 else no a b;
108108+84109 /* Reads a JSON file. */
85110 importJSON = path:
86111 builtins.fromJSON (builtins.readFile path);
+31-3
nixos/doc/manual/default.nix
···1515 else if builtins.isFunction x then "<function>"
1616 else x;
17171818- # Clean up declaration sites to not refer to the NixOS source tree.
1818+ # Generate DocBook documentation for a list of packages
1919+ genRelatedPackages = packages:
2020+ let
2121+ unpack = p: if lib.isString p then { name = p; } else p;
2222+ describe = { name, package ? pkgs.${name}, comment ? "" }:
2323+ "<listitem>"
2424+ + "<para><option>pkgs.${name}</option> (${package.name}): ${package.meta.description or "???"}.</para>"
2525+ + lib.optionalString (comment != "") "\n<para>${comment}</para>"
2626+ # Lots of `longDescription's break DocBook, so we just wrap them into <programlisting>
2727+ + lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>"
2828+ + "</listitem>";
2929+ in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>";
3030+1931 optionsList' = lib.flip map optionsList (opt: opt // {
3232+ # Clean up declaration sites to not refer to the NixOS source tree.
2033 declarations = map stripAnyPrefixes opt.declarations;
2134 }
2235 // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
2336 // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
2424- // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; });
3737+ // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }
3838+ // lib.optionalAttrs (opt ? relatedPackages) { relatedPackages = genRelatedPackages opt.relatedPackages; });
25392640 # We need to strip references to /nix/store/* from options,
2741 # including any `extraSources` if some modules came from elsewhere,
···3246 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
3347 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
34484949+ # Custom "less" that pushes up all the things ending in ".enable*"
5050+ # and ".package"
5151+ optionListLess = a: b:
5252+ let
5353+ splt = lib.splitString ".";
5454+ ise = lib.hasPrefix "enable";
5555+ isp = lib.hasPrefix "package";
5656+ cmp = lib.splitByAndCompare ise lib.compare
5757+ (lib.splitByAndCompare isp lib.compare lib.compare);
5858+ in lib.compareLists cmp (splt a) (splt b) < 0;
5959+6060+ # Customly sort option list for the man page.
6161+ optionsList'' = lib.sort (a: b: optionListLess a.name b.name) optionsList';
6262+3563 # Convert the list of options into an XML file.
3636- optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
6464+ optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'');
37653866 optionsDocBook = runCommand "options-db.xml" {} ''
3967 optionsXML=${optionsXML}