···
27
-
# Replace functions by the string <function>
29
-
if builtins.isAttrs x then lib.mapAttrs (name: substFunction) x
30
-
else if builtins.isList x then map substFunction x
27
+
# Make a value safe for JSON. Functions are replaced by the string "<function>",
28
+
# derivations are replaced with an attrset
29
+
# { _type = "derivation"; name = <name of that derivation>; }.
30
+
# We need to handle derivations specially because consumers want to know about them,
31
+
# but we can't easily use the type,name subset of keys (since type is often used as
32
+
# a module option and might cause confusion). Use _type,name instead to the same
33
+
# effect, since _type is already used by the module system.
35
+
if lib.isDerivation x then { _type = "derivation"; name = x.name; }
36
+
else if builtins.isAttrs x then lib.mapAttrs (name: substSpecial) x
37
+
else if builtins.isList x then map substSpecial x
else if lib.isFunction x then "<function>"
optionsList = lib.flip map optionsListVisible
(opt: transformOptions opt
36
-
// lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
37
-
// lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
38
-
// lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }
43
+
// lib.optionalAttrs (opt ? example) { example = substSpecial opt.example; }
44
+
// lib.optionalAttrs (opt ? default) { default = substSpecial opt.default; }
45
+
// lib.optionalAttrs (opt ? type) { type = substSpecial opt.type; }
// lib.optionalAttrs (opt ? relatedPackages && opt.relatedPackages != []) { relatedPackages = genRelatedPackages opt.relatedPackages opt.name; }
···
# Remove invisible and internal options.
optionsListVisible = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options);
75
-
# Convert the list of options into an XML file.
76
-
# This file is *not* sorted sorted to save on eval time, since the docbook XML
77
-
# and the manpage depend on it and thus we evaluate this on every system rebuild.
78
-
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList);
optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList);
···
mkdir -p $out/nix-support
echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products
echo "file json-br $dst/options.json.br" >> $out/nix-support/hydra-build-products
117
+
# Convert options.json into an XML file.
118
+
# The actual generation of the xml file is done in nix purely for the convenience
119
+
# of not having to generate the xml some other way
120
+
optionsXML = pkgs.runCommand "options.xml" {} ''
121
+
${pkgs.nix}/bin/nix-instantiate \
123
+
--eval --xml --strict ${./optionsJSONtoXML.nix} \
124
+
--argstr file ${optionsJSON}/share/doc/nixos/options.json \
optionsDocBook = pkgs.runCommand "options-docbook.xml" {} ''