···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 functionArgs setFunctionArgs isFunction;
5959+ nixpkgsVersion mod compare splitByAndCompare
6060+ functionArgs setFunctionArgs isFunction;
60616162 inherit (fixedPoints) fix fix' extends composeExtensions
6263 makeExtensible makeExtensibleWithCustomName;
···7172 inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
7273 concatMap flatten remove findSingle findFirst any all count
7374 optional optionals toList range partition zipListsWith zipLists
7474- reverseList listDfs toposort sort take drop sublist last init
7575- crossLists unique intersectLists subtractLists
7575+ reverseList listDfs toposort sort compareLists take drop sublist
7676+ last init crossLists unique intersectLists subtractLists
7677 mutuallyExclusive;
7778 inherit (strings) concatStrings concatMapStrings concatImapStrings
7879 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 (see `genRelatedPackages` in ../nixos/doc/manual/default.nix).
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;
+36
lib/trivial.nix
···8181 */
8282 mod = base: int: base - (int * (builtins.div base int));
83838484+ /* C-style comparisons
8585+8686+ a < b, compare a b => -1
8787+ a == b, compare a b => 0
8888+ a > b, compare 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`, take all elements
9898+ of the first subtype to be less than all the elements of the
9999+ second subtype, compare elements of a single subtype with `yes`
100100+ and `no` respectively.
101101+102102+ Example:
103103+104104+ let cmp = splitByAndCompare (hasPrefix "foo") compare compare; in
105105+106106+ cmp "a" "z" => -1
107107+ cmp "fooa" "fooz" => -1
108108+109109+ cmp "f" "a" => 1
110110+ cmp "fooa" "a" => -1
111111+ # while
112112+ compare "fooa" "a" => 1
113113+114114+ */
115115+ splitByAndCompare = p: yes: no: a: b:
116116+ if p a
117117+ then if p b then yes a b else -1
118118+ else if p b then 1 else no a b;
119119+84120 /* Reads a JSON file. */
85121 importJSON = path:
86122 builtins.fromJSON (builtins.readFile path);
+50-6
nixos/doc/manual/default.nix
···66 lib = pkgs.lib;
7788 # Remove invisible and internal options.
99- optionsList = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
99+ optionsListVisible = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
10101111 # Replace functions by the string <function>
1212 substFunction = x:
···1515 else if lib.isFunction x then "<function>"
1616 else x;
17171818- # Clean up declaration sites to not refer to the NixOS source tree.
1919- optionsList' = lib.flip map optionsList (opt: opt // {
1818+ # Generate DocBook documentation for a list of packages. This is
1919+ # what `relatedPackages` option of `mkOption` from
2020+ # ../../../lib/options.nix influences.
2121+ #
2222+ # Each element of `relatedPackages` can be either
2323+ # - a string: that will be interpreted as an attribute name from `pkgs`,
2424+ # - a list: that will be interpreted as an attribute path from `pkgs`,
2525+ # - an attrset: that can specify `name`, `path`, `package`, `comment`
2626+ # (either of `name`, `path` is required, the rest are optional).
2727+ genRelatedPackages = packages:
2828+ let
2929+ unpack = p: if lib.isString p then { name = p; }
3030+ else if lib.isList p then { path = p; }
3131+ else p;
3232+ describe = args:
3333+ let
3434+ name = args.name or (lib.concatStringsSep "." args.path);
3535+ path = args.path or [ args.name ];
3636+ package = args.package or (lib.attrByPath path (throw "Invalid package attribute path `${toString path}'") pkgs);
3737+ in "<listitem>"
3838+ + "<para><literal>pkgs.${name} (${package.meta.name})</literal>"
3939+ + lib.optionalString (!package.meta.evaluates) " <emphasis>[UNAVAILABLE]</emphasis>"
4040+ + ": ${package.meta.description or "???"}.</para>"
4141+ + lib.optionalString (args ? comment) "\n<para>${args.comment}</para>"
4242+ # Lots of `longDescription's break DocBook, so we just wrap them into <programlisting>
4343+ + lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>"
4444+ + "</listitem>";
4545+ in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>";
4646+4747+ optionsListDesc = lib.flip map optionsListVisible (opt: opt // {
4848+ # Clean up declaration sites to not refer to the NixOS source tree.
2049 declarations = map stripAnyPrefixes opt.declarations;
2150 }
2251 // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
2352 // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
2424- // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; });
5353+ // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }
5454+ // lib.optionalAttrs (opt ? relatedPackages) { relatedPackages = genRelatedPackages opt.relatedPackages; });
25552656 # We need to strip references to /nix/store/* from options,
2757 # including any `extraSources` if some modules came from elsewhere,
···3262 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
3363 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip;
34646565+ # Custom "less" that pushes up all the things ending in ".enable*"
6666+ # and ".package"
6767+ optionListLess = a: b:
6868+ let
6969+ splt = lib.splitString ".";
7070+ ise = lib.hasPrefix "enable";
7171+ isp = lib.hasPrefix "package";
7272+ cmp = lib.splitByAndCompare ise lib.compare
7373+ (lib.splitByAndCompare isp lib.compare lib.compare);
7474+ in lib.compareLists cmp (splt a) (splt b) < 0;
7575+7676+ # Customly sort option list for the man page.
7777+ optionsList = lib.sort (a: b: optionListLess a.name b.name) optionsListDesc;
7878+3579 # Convert the list of options into an XML file.
3636- optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
8080+ optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList);
37813882 optionsDocBook = runCommand "options-db.xml" {} ''
3983 optionsXML=${optionsXML}
···191235 mkdir -p $dst
192236193237 cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
194194- (builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList'))))
238238+ (builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList))))
195239 } $dst/options.json
196240197241 mkdir -p $out/nix-support
···1616 To grant access to a user, it must be part of adbusers group:
1717 <code>users.extraUsers.alice.extraGroups = ["adbusers"];</code>
1818 '';
1919+ relatedPackages = [ ["androidenv" "platformTools"] ];
1920 };
2021 };
2122 };