refactor: move docs transformOptions to clanLib to reduce rebuilds

- Add clanLib.docs.stripStorePathsFromDeclarations to deduplicate code
- Update all documentation generation to use the shared function
- This strips store paths from option declarations to prevent options.json
  from rebuilding when only store paths change but content remains the same
- Reduces unnecessary documentation rebuilds when making unrelated changes
This commit is contained in:
Jörg Thalheim
2025-07-07 22:20:40 +02:00
committed by Johannes Kirschbauer
parent 7bc8e091a5
commit 8d4099d13d
6 changed files with 45 additions and 2 deletions

View File

@@ -45,6 +45,7 @@ lib.fix (
introspection = import ./introspection { inherit lib; };
jsonschema = import ./jsonschema { inherit lib; };
facts = import ./facts.nix { inherit lib; };
docs = import ./docs.nix { inherit lib; };
# flakes
flakes = clanLib.callLib ./flakes.nix { };

21
lib/docs.nix Normal file
View File

@@ -0,0 +1,21 @@
{ lib, ... }:
{
# Strip store paths from option declarations to make docs more stable
# This prevents documentation from rebuilding when store paths change
# but the actual content remains the same
stripStorePathsFromDeclarations = opt:
opt // {
declarations = map (decl:
if lib.isString decl && lib.hasPrefix "/nix/store/" decl then
let
parts = lib.splitString "/" decl;
in
if builtins.length parts > 4 then
"/" + lib.concatStringsSep "/" (lib.drop 4 parts)
else
decl
else
decl
) opt.declarations;
};
}

View File

@@ -9,9 +9,11 @@ let
clan-core.modules.clan.default
];
};
evalDocs = pkgs.nixosOptionsDoc {
options = eval.options;
warningsAreErrors = false;
transformOptions = clan-core.clanLib.docs.stripStorePathsFromDeclarations;
};
in
{

View File

@@ -49,6 +49,7 @@ in
prefix = [ ];
}).options;
warningsAreErrors = true;
transformOptions = self.clanLib.docs.stripStorePathsFromDeclarations;
}).optionsJSON;
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests