summary refs log tree commit diff
path: root/nixos/lib/eval-cacheable-options.nix
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2021-11-19 00:26:27 +0100
committerpennae <github@quasiparticle.net>2022-01-02 19:46:13 +0100
commitfc614c37c653637e5475a0b0a987489b4d1f351d (patch)
tree7b2470a3a67979ddcc51f18bb0d424f8e95908b1 /nixos/lib/eval-cacheable-options.nix
parent55daffc1c943bddb71dc89a606f8284f6d50f5bd (diff)
downloadnixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar.gz
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar.bz2
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar.lz
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar.xz
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.tar.zst
nixpkgs-fc614c37c653637e5475a0b0a987489b4d1f351d.zip
nixos/documentation: split options doc build
most modules can be evaluated for their documentation in a very
restricted environment that doesn't include all of nixpkgs. this
evaluation can then be cached and reused for subsequent builds, merging
only documentation that has changed into the cached set. since nixos
ships with a large number of modules of which only a few are used in any
given config this can save evaluation a huge percentage of nixos
options available in any given config.

in tests of this caching, despite having to copy most of nixos/, saves
about 80% of the time needed to build the system manual, or about two
second on the machine used for testing. build time for a full system
config shrank from 9.4s to 7.4s, while turning documentation off
entirely shortened the build to 7.1s.
Diffstat (limited to 'nixos/lib/eval-cacheable-options.nix')
-rw-r--r--nixos/lib/eval-cacheable-options.nix53
1 files changed, 53 insertions, 0 deletions
diff --git a/nixos/lib/eval-cacheable-options.nix b/nixos/lib/eval-cacheable-options.nix
new file mode 100644
index 00000000000..c3ba2ce6637
--- /dev/null
+++ b/nixos/lib/eval-cacheable-options.nix
@@ -0,0 +1,53 @@
+{ libPath
+, pkgsLibPath
+, nixosPath
+, modules
+, stateVersion
+, release
+}:
+
+let
+  lib = import libPath;
+  modulesPath = "${nixosPath}/modules";
+  # dummy pkgs set that contains no packages, only `pkgs.lib` from the full set.
+  # not having `pkgs.lib` causes all users of `pkgs.formats` to fail.
+  pkgs = import pkgsLibPath {
+    inherit lib;
+    pkgs = null;
+  };
+  utils = import "${nixosPath}/lib/utils.nix" {
+    inherit config lib;
+    pkgs = null;
+  };
+  # this is used both as a module and as specialArgs.
+  # as a module it sets the _module special values, as specialArgs it makes `config`
+  # unusable. this causes documentation attributes depending on `config` to fail.
+  config = {
+    _module.check = false;
+    _module.args = {};
+    system.stateVersion = stateVersion;
+  };
+  eval = lib.evalModules {
+    modules = (map (m: "${modulesPath}/${m}") modules) ++ [
+      config
+    ];
+    specialArgs = {
+      inherit config pkgs utils;
+    };
+  };
+  docs = import "${nixosPath}/doc/manual" {
+    pkgs = pkgs // {
+      inherit lib;
+      # duplicate of the declaration in all-packages.nix
+      buildPackages.nixosOptionsDoc = attrs:
+        (import "${nixosPath}/lib/make-options-doc")
+          ({ inherit pkgs lib; } // attrs);
+    };
+    config = config.config;
+    options = eval.options;
+    version = release;
+    revision = "release-${release}";
+    prefix = modulesPath;
+  };
+in
+  docs.optionsNix