summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-07-28 16:33:10 +0200
committerpennae <github@quasiparticle.net>2022-07-28 23:20:02 +0200
commit52b0ad17e3727fe0c3ca028787128ede5fb86352 (patch)
tree07b107e52586b7293d615865133c04906caf9fa5 /nixos
parent18be724a5840145866f058dbf3b4c83a85d7b05d (diff)
downloadnixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar.gz
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar.bz2
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar.lz
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar.xz
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.tar.zst
nixpkgs-52b0ad17e3727fe0c3ca028787128ede5fb86352.zip
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.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/make-options-doc/default.nix31
1 files changed, 21 insertions, 10 deletions
diff --git a/nixos/lib/make-options-doc/default.nix b/nixos/lib/make-options-doc/default.nix
index 6649fc41d41..e039bc4a9b7 100644
--- a/nixos/lib/make-options-doc/default.nix
+++ b/nixos/lib/make-options-doc/default.nix
@@ -99,6 +99,14 @@ let
 
   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 {
   inherit optionsNix;
 
@@ -116,17 +124,20 @@ in rec {
 
   optionsJSON = pkgs.runCommand "options.json"
     { meta.description = "List of NixOS options in JSON format";
-      buildInputs = [
-        pkgs.brotli
-        (let
-          self = (pkgs.python3Minimal.override {
-            inherit self;
-            includeSiteCustomize = true;
-           });
-         in self.withPackages (p: [ p.mistune_2_0 ]))
-      ];
+      buildInputs = [ pkgs.brotli pythonMD ];
       options = builtins.toFile "options.json"
         (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.
@@ -143,7 +154,7 @@ in rec {
           else ''
             python ${./mergeJSON.py} \
               ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
-              ${baseOptionsJSON} $options \
+              $baseJSON $options \
               > $dst/options.json
           ''
       }