nixos/docs: cache mergeJSON md conversion on baseOptionsJSON
with ever more options being markdown rather than docbook the conversion time is starting to become a significant factor of doc build time. luckily we can pre-convert all nixos option docs to MD and cache the result of this conversion, then merge the already-converted json file with user option docs. we leave options.json unconverted to keep it as close to the actual nix code as possible.
This commit is contained in:
parent
18be724a58
commit
52b0ad17e3
|
@ -99,6 +99,14 @@ let
|
||||||
|
|
||||||
optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList);
|
optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList);
|
||||||
|
|
||||||
|
pythonMD =
|
||||||
|
let
|
||||||
|
self = (pkgs.python3Minimal.override {
|
||||||
|
inherit self;
|
||||||
|
includeSiteCustomize = true;
|
||||||
|
});
|
||||||
|
in self.withPackages (p: [ p.mistune_2_0 ]);
|
||||||
|
|
||||||
in rec {
|
in rec {
|
||||||
inherit optionsNix;
|
inherit optionsNix;
|
||||||
|
|
||||||
|
@ -116,17 +124,20 @@ in rec {
|
||||||
|
|
||||||
optionsJSON = pkgs.runCommand "options.json"
|
optionsJSON = pkgs.runCommand "options.json"
|
||||||
{ meta.description = "List of NixOS options in JSON format";
|
{ meta.description = "List of NixOS options in JSON format";
|
||||||
buildInputs = [
|
buildInputs = [ pkgs.brotli pythonMD ];
|
||||||
pkgs.brotli
|
|
||||||
(let
|
|
||||||
self = (pkgs.python3Minimal.override {
|
|
||||||
inherit self;
|
|
||||||
includeSiteCustomize = true;
|
|
||||||
});
|
|
||||||
in self.withPackages (p: [ p.mistune_2_0 ]))
|
|
||||||
];
|
|
||||||
options = builtins.toFile "options.json"
|
options = builtins.toFile "options.json"
|
||||||
(builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix));
|
(builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix));
|
||||||
|
# convert markdown to docbook in its own derivation to cache the
|
||||||
|
# conversion results. the conversion is surprisingly expensive.
|
||||||
|
baseJSON =
|
||||||
|
if baseOptionsJSON != null
|
||||||
|
then
|
||||||
|
pkgs.runCommand "base-json-md-converted" {
|
||||||
|
buildInputs = [ pythonMD ];
|
||||||
|
} ''
|
||||||
|
python ${./mergeJSON.py} ${baseOptionsJSON} <(echo '{}') > $out
|
||||||
|
''
|
||||||
|
else null;
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
# Export list of options in different format.
|
# Export list of options in different format.
|
||||||
|
@ -143,7 +154,7 @@ in rec {
|
||||||
else ''
|
else ''
|
||||||
python ${./mergeJSON.py} \
|
python ${./mergeJSON.py} \
|
||||||
${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
|
${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
|
||||||
${baseOptionsJSON} $options \
|
$baseJSON $options \
|
||||||
> $dst/options.json
|
> $dst/options.json
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue