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:
committed by
Johannes Kirschbauer
parent
0363dd29d0
commit
0e97efbbef
@@ -29,7 +29,10 @@
|
|||||||
# Frontmatter for clanModules
|
# Frontmatter for clanModules
|
||||||
clanModulesFrontmatter =
|
clanModulesFrontmatter =
|
||||||
let
|
let
|
||||||
docs = pkgs.nixosOptionsDoc { options = self.clanLib.modules.frontmatterOptions; };
|
docs = pkgs.nixosOptionsDoc {
|
||||||
|
options = self.clanLib.modules.frontmatterOptions;
|
||||||
|
transformOptions = self.clanLib.docs.stripStorePathsFromDeclarations;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
docs.optionsJSON;
|
docs.optionsJSON;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
clan-core,
|
clan-core,
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
inherit (clan-core.clanLib.docs) stripStorePathsFromDeclarations;
|
||||||
|
transformOptions = stripStorePathsFromDeclarations;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# clanModules docs
|
# clanModules docs
|
||||||
clanModulesViaNix = lib.mapAttrs (
|
clanModulesViaNix = lib.mapAttrs (
|
||||||
@@ -20,6 +24,7 @@
|
|||||||
}).options
|
}).options
|
||||||
).clan.${name} or { };
|
).clan.${name} or { };
|
||||||
warningsAreErrors = true;
|
warningsAreErrors = true;
|
||||||
|
inherit transformOptions;
|
||||||
}).optionsJSON
|
}).optionsJSON
|
||||||
else
|
else
|
||||||
{ }
|
{ }
|
||||||
@@ -32,6 +37,7 @@
|
|||||||
(nixosOptionsDoc {
|
(nixosOptionsDoc {
|
||||||
inherit options;
|
inherit options;
|
||||||
warningsAreErrors = true;
|
warningsAreErrors = true;
|
||||||
|
inherit transformOptions;
|
||||||
}).optionsJSON
|
}).optionsJSON
|
||||||
) rolesOptions
|
) rolesOptions
|
||||||
) modulesRolesOptions;
|
) modulesRolesOptions;
|
||||||
@@ -52,7 +58,15 @@
|
|||||||
|
|
||||||
(nixosOptionsDoc {
|
(nixosOptionsDoc {
|
||||||
transformOptions =
|
transformOptions =
|
||||||
opt: if lib.strings.hasPrefix "_" opt.name then opt // { visible = false; } else opt;
|
opt:
|
||||||
|
let
|
||||||
|
# Apply store path stripping first
|
||||||
|
transformed = transformOptions opt;
|
||||||
|
in
|
||||||
|
if lib.strings.hasPrefix "_" transformed.name then
|
||||||
|
transformed // { visible = false; }
|
||||||
|
else
|
||||||
|
transformed;
|
||||||
options = (lib.evalModules { modules = [ role.interface ]; }).options;
|
options = (lib.evalModules { modules = [ role.interface ]; }).options;
|
||||||
warningsAreErrors = true;
|
warningsAreErrors = true;
|
||||||
}).optionsJSON
|
}).optionsJSON
|
||||||
@@ -72,5 +86,6 @@
|
|||||||
}).options
|
}).options
|
||||||
).clan.core or { };
|
).clan.core or { };
|
||||||
warningsAreErrors = true;
|
warningsAreErrors = true;
|
||||||
|
inherit transformOptions;
|
||||||
}).optionsJSON;
|
}).optionsJSON;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ lib.fix (
|
|||||||
introspection = import ./introspection { inherit lib; };
|
introspection = import ./introspection { inherit lib; };
|
||||||
jsonschema = import ./jsonschema { inherit lib; };
|
jsonschema = import ./jsonschema { inherit lib; };
|
||||||
facts = import ./facts.nix { inherit lib; };
|
facts = import ./facts.nix { inherit lib; };
|
||||||
|
docs = import ./docs.nix { inherit lib; };
|
||||||
|
|
||||||
# flakes
|
# flakes
|
||||||
flakes = clanLib.callLib ./flakes.nix { };
|
flakes = clanLib.callLib ./flakes.nix { };
|
||||||
|
|||||||
21
lib/docs.nix
Normal file
21
lib/docs.nix
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,9 +9,11 @@ let
|
|||||||
clan-core.modules.clan.default
|
clan-core.modules.clan.default
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
evalDocs = pkgs.nixosOptionsDoc {
|
evalDocs = pkgs.nixosOptionsDoc {
|
||||||
options = eval.options;
|
options = eval.options;
|
||||||
warningsAreErrors = false;
|
warningsAreErrors = false;
|
||||||
|
transformOptions = clan-core.clanLib.docs.stripStorePathsFromDeclarations;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ in
|
|||||||
prefix = [ ];
|
prefix = [ ];
|
||||||
}).options;
|
}).options;
|
||||||
warningsAreErrors = true;
|
warningsAreErrors = true;
|
||||||
|
transformOptions = self.clanLib.docs.stripStorePathsFromDeclarations;
|
||||||
}).optionsJSON;
|
}).optionsJSON;
|
||||||
|
|
||||||
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests
|
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests
|
||||||
|
|||||||
Reference in New Issue
Block a user