lol

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.

pennae 52b0ad17 18be724a

+21 -10
+21 -10
nixos/lib/make-options-doc/default.nix
··· 99 99 100 100 optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList); 101 101 102 + pythonMD = 103 + let 104 + self = (pkgs.python3Minimal.override { 105 + inherit self; 106 + includeSiteCustomize = true; 107 + }); 108 + in self.withPackages (p: [ p.mistune_2_0 ]); 109 + 102 110 in rec { 103 111 inherit optionsNix; 104 112 ··· 116 124 117 125 optionsJSON = pkgs.runCommand "options.json" 118 126 { meta.description = "List of NixOS options in JSON format"; 119 - buildInputs = [ 120 - pkgs.brotli 121 - (let 122 - self = (pkgs.python3Minimal.override { 123 - inherit self; 124 - includeSiteCustomize = true; 125 - }); 126 - in self.withPackages (p: [ p.mistune_2_0 ])) 127 - ]; 127 + buildInputs = [ pkgs.brotli pythonMD ]; 128 128 options = builtins.toFile "options.json" 129 129 (builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix)); 130 + # convert markdown to docbook in its own derivation to cache the 131 + # conversion results. the conversion is surprisingly expensive. 132 + baseJSON = 133 + if baseOptionsJSON != null 134 + then 135 + pkgs.runCommand "base-json-md-converted" { 136 + buildInputs = [ pythonMD ]; 137 + } '' 138 + python ${./mergeJSON.py} ${baseOptionsJSON} <(echo '{}') > $out 139 + '' 140 + else null; 130 141 } 131 142 '' 132 143 # Export list of options in different format. ··· 143 154 else '' 144 155 python ${./mergeJSON.py} \ 145 156 ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \ 146 - ${baseOptionsJSON} $options \ 157 + $baseJSON $options \ 147 158 > $dst/options.json 148 159 '' 149 160 }