Shared documentation-site machinery based on ndg
- Nix 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
The flake wrapper applied the entrypoint once per `(attr, system)` pair. `import` memoizes the *file* value, not the *application*, so none of those applications shared any of the entrypoint's internal work -- each re-ran the whole `let`, including the `pkgs ? import sources.nixpkgs { ... }` default argument, i.e. a whole fresh nixpkgs.
Binding one instantiation per system in the `let` and reading every keyed output out of it collapses that.
Measured on `fediversity-ci`, `nix flake show --no-eval-cache`, warm store, second of two runs:
| | wall | user+sys | maxrss | nrThunks | gc.totalBytes |
|---|---|---|---|---|---|
| before | 2.08 s | 1.35 s | 198 MB | 607,339 | 149.4 MB |
| after | 1.06 s | 0.67 s | 93 MB | 178,316 | 42.5 MB |
Output is unchanged: `nix flake show --json --all-systems --no-eval-cache | jq -S .` is byte-identical before and after, and every `drvPath` is unmoved bar the `treefmt` check's, which hashes the project source and so moves with any edit to `flake.nix` itself.
This is the same defect that cost the fediversity monorepo far more (its entrypoints carry a whole deployment surface, not just a nixpkgs); the wrapper was copied from https://codeberg.org/kiara/poc-override-nix-deps, which is being fixed at the source too.
Reviewed-on: #3
|
||
| .forgejo/workflows | ||
| npins | ||
| .envrc | ||
| .gitignore | ||
| check-describe.nix | ||
| default.nix | ||
| docs.nix | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE | ||
| README.md | ||
| shell.nix | ||
| treefmt.nix | ||
nix-docs-lib
Shared ndg-based documentation machinery for
rendering per-component option/prose sites, plus the describeCheck helper used
to read each check's meta.description when building a flake-attributes page.
Extracted from the fediversity
monorepo so its core/api/panel doc sites and the standalone
nix-module-form
widget can share one definition, each consuming it via an npins pin.
Usage
lib.docs is a function of { basePath ? null, repoPath ? "", ... } (pkgs,
sources and lib default internally). Each consumer passes its own repo root
(basePath) and Forgejo source URL (repoPath) so transformOptions rewrites
option declarations into links on the consumer's own instance:
inherit
((import "${sources.nix-docs-lib}" { }).lib.docs {
basePath = ./..;
repoPath = "https://git.fediversity.eu/fediversity/fediversity/src/branch/main";
})
mkSite
optionsCommonMark
optionPage
flakeAttributesPage
;
describeCheck lives in check-describe.nix (also re-exported from
default.nix):
inherit ((import "${sources.nix-docs-lib}" { }).lib) describeCheck;
Development
nix flake show
nix build .#checks.x86_64-linux.treefmt
nix build .#checks.x86_64-linux.smoke