docs: improve some parts
This commit is contained in:
34 files changed
+932
-123
No files matched your search
+35
-50
@@ -48,6 +48,11 @@ in
|
||||
pkgs.runCommand "proxy-suite-options-doc-check" { nativeBuildInputs = [ pkgs.diffutils ]; }
|
||||
''
|
||||
diff -ru ${../../docs/options} ${generatedOptionsDoc}
|
||||
# A package default without defaultText renders as a store derivation.
|
||||
if grep -rn '<derivation ' ${generatedOptionsDoc}; then
|
||||
echo "package option without defaultText" >&2
|
||||
exit 1
|
||||
fi
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
@@ -60,30 +65,23 @@ in
|
||||
|
||||
# The usage guides are hand-written; what can go stale in them is checked here. Every
|
||||
# ```nix block that sets services.proxy-suite (in the guides, their examples/ and the
|
||||
# README) must evaluate, with no proxy-suite assertion or warning; a block fenced
|
||||
# ```nix no-check is skipped. A block is either module attributes or, when it starts
|
||||
# with "{", a whole module. Every relative link must reach a file, and its #anchor an
|
||||
# <a id> there.
|
||||
# README) must evaluate, with no proxy-suite assertion or warning, from its copy in
|
||||
# docs/usage/.snippets (nix/usage-snippets.nix), which must match it. Every relative link
|
||||
# must reach a file, and its #anchor an <a id> there.
|
||||
usage-docs =
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
usageDir = ../../docs/usage;
|
||||
markdownIn =
|
||||
dir:
|
||||
map (name: lib.removePrefix "./" "${dir}/${name}") (
|
||||
builtins.filter (lib.hasSuffix ".md") (builtins.attrNames (builtins.readDir (usageDir + "/${dir}")))
|
||||
);
|
||||
guides = markdownIn "." ++ markdownIn "examples";
|
||||
readmeText = builtins.readFile ../../README.md;
|
||||
usageSnippets = import ../usage-snippets.nix { inherit lib; };
|
||||
inherit (usageSnippets) guides snippets;
|
||||
guideText = name: builtins.readFile (usageDir + "/${name}");
|
||||
|
||||
snippets =
|
||||
text:
|
||||
builtins.filter (lib.hasInfix "services.proxy-suite") (
|
||||
map (chunk: builtins.head (lib.splitString "\n```" chunk)) (
|
||||
builtins.tail (lib.splitString "```nix\n" text)
|
||||
)
|
||||
);
|
||||
snippetDir = ../.. + "/${usageSnippets.dir}";
|
||||
committed = lib.optionals (builtins.pathExists snippetDir) (
|
||||
builtins.attrNames (builtins.readDir snippetDir)
|
||||
);
|
||||
outdated = "is out of date, run `nix run .#update-docs`";
|
||||
|
||||
# Every visible option's value, so a wrong type fails too. Packages are skipped:
|
||||
# forcing one evaluates its whole build graph. Removed options throw when read.
|
||||
plain =
|
||||
@@ -102,39 +100,28 @@ in
|
||||
name: opt: if lib.isOption opt then plain cfg.${name} else visibleValues opt cfg.${name}
|
||||
) (lib.filterAttrs (name: opt: name != "_module" && (opt.visible or true) != false) opts);
|
||||
snippetProblems =
|
||||
where: snippet:
|
||||
snippet:
|
||||
let
|
||||
module = import (
|
||||
builtins.toFile "snippet.nix" (
|
||||
if lib.hasPrefix "{" snippet then
|
||||
snippet
|
||||
else
|
||||
''
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
${snippet}
|
||||
}
|
||||
''
|
||||
)
|
||||
);
|
||||
path = snippetDir + "/${snippet.file}";
|
||||
eval = evalProxySuite [
|
||||
module
|
||||
(import path)
|
||||
{ system.stateVersion = "26.05"; }
|
||||
];
|
||||
inherit (eval) config;
|
||||
failed = map (a: a.message) (builtins.filter (a: !a.assertion) config.assertions);
|
||||
own = builtins.filter (lib.hasPrefix "proxy-suite:") (failed ++ config.warnings);
|
||||
in
|
||||
builtins.addErrorContext "while evaluating ${where}" (
|
||||
builtins.deepSeq (visibleValues eval.options.services.proxy-suite config.services.proxy-suite) (
|
||||
map (message: "${where}: ${message}") own
|
||||
)
|
||||
);
|
||||
textProblems =
|
||||
file: text:
|
||||
lib.concatLists (
|
||||
lib.imap1 (index: snippetProblems "${file}, nix block ${toString index}") (snippets text)
|
||||
);
|
||||
if !builtins.elem snippet.file committed || builtins.readFile path != snippet.text then
|
||||
[ "${snippet.where}: ${usageSnippets.dir}/${snippet.file} ${outdated}" ]
|
||||
else
|
||||
builtins.addErrorContext "while evaluating ${snippet.where}" (
|
||||
builtins.deepSeq (visibleValues eval.options.services.proxy-suite config.services.proxy-suite) (
|
||||
map (message: "${snippet.where}: ${message}") own
|
||||
)
|
||||
);
|
||||
leftover = map (file: "${usageSnippets.dir}/${file}: no nix block for it, ${outdated}") (
|
||||
lib.subtractLists (map (snippet: snippet.file) snippets) committed
|
||||
);
|
||||
|
||||
# [text](target) and [text](target#anchor), except absolute URLs.
|
||||
links =
|
||||
@@ -162,11 +149,7 @@ in
|
||||
[ ]
|
||||
) (links (guideText name));
|
||||
|
||||
problems =
|
||||
textProblems "README.md" readmeText
|
||||
++ lib.concatMap (
|
||||
name: textProblems "docs/usage/${name}" (guideText name) ++ linkProblems name
|
||||
) guides;
|
||||
problems = leftover ++ lib.concatMap snippetProblems snippets ++ lib.concatMap linkProblems guides;
|
||||
in
|
||||
pkgs.runCommand "proxy-suite-usage-docs-check" { } (
|
||||
if problems == [ ] then
|
||||
@@ -178,14 +161,16 @@ in
|
||||
''
|
||||
);
|
||||
|
||||
# The tree as `nix fmt` leaves it.
|
||||
# The tree as `nix fmt` leaves it; the generated usage snippets are left as written.
|
||||
nix-format =
|
||||
pkgs.runCommand "proxy-suite-nix-format-check" { nativeBuildInputs = [ pkgs.nixfmt ]; }
|
||||
''
|
||||
cd ${
|
||||
pkgs.lib.fileset.toSource {
|
||||
root = ../..;
|
||||
fileset = pkgs.lib.fileset.fileFilter (file: file.hasExt "nix") ../..;
|
||||
fileset = pkgs.lib.fileset.difference (pkgs.lib.fileset.fileFilter (
|
||||
file: file.hasExt "nix"
|
||||
) ../..) (pkgs.lib.fileset.maybeMissing ../../docs/usage/.snippets);
|
||||
}
|
||||
}
|
||||
find . -name '*.nix' -print0 | xargs -0 nixfmt --check
|
||||
|
||||
+12
-5
@@ -17,8 +17,14 @@ let
|
||||
];
|
||||
};
|
||||
|
||||
pretty = text: {
|
||||
__pretty = _: text;
|
||||
val = null;
|
||||
};
|
||||
|
||||
# Visible options only (renamed aliases are hidden, and so are groups left
|
||||
# with nothing but aliases), packages shown by name.
|
||||
# with nothing but aliases). A defaultText is shown as written, Markdown ones
|
||||
# as a ‹placeholder›; other packages by name.
|
||||
visibleConfig =
|
||||
opts: cfg:
|
||||
lib.filterAttrs (name: value: lib.isOption opts.${name} || value != { }) (
|
||||
@@ -26,11 +32,12 @@ let
|
||||
name: opt:
|
||||
if !lib.isOption opt then
|
||||
visibleConfig opt cfg.${name}
|
||||
else if (opt.defaultText._type or null) == "literalExpression" then
|
||||
pretty opt.defaultText.text
|
||||
else if (opt.defaultText._type or null) == "literalMD" then
|
||||
pretty "‹${lib.replaceStrings [ "`" ] [ "" ] opt.defaultText.text}›"
|
||||
else if lib.isDerivation cfg.${name} then
|
||||
{
|
||||
__pretty = _: "pkgs.${lib.getName cfg.${name}}";
|
||||
val = null;
|
||||
}
|
||||
pretty "pkgs.${lib.getName cfg.${name}}"
|
||||
else
|
||||
cfg.${name}
|
||||
) (lib.filterAttrs (name: opt: name != "_module" && (opt.visible or true) != false) opts)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# The ```nix blocks of the README and the usage guides that set services.proxy-suite, each
|
||||
# as a whole module. update-docs writes them to docs/usage/.snippets, where the usage-docs
|
||||
# check imports them: Nix only parses files, and `nix flake check --no-build` can't write
|
||||
# one to the store. A block fenced ```nix no-check is skipped; one that starts with "{" is
|
||||
# a module already, anything else is its attributes.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
usageDir = ../docs/usage;
|
||||
markdownIn =
|
||||
dir:
|
||||
map (name: lib.removePrefix "./" "${dir}/${name}") (
|
||||
builtins.filter (lib.hasSuffix ".md") (builtins.attrNames (builtins.readDir (usageDir + "/${dir}")))
|
||||
);
|
||||
guides = markdownIn "." ++ markdownIn "examples";
|
||||
|
||||
blocks =
|
||||
text:
|
||||
builtins.filter (lib.hasInfix "services.proxy-suite") (
|
||||
map (chunk: builtins.head (lib.splitString "\n```" chunk)) (
|
||||
builtins.tail (lib.splitString "```nix\n" text)
|
||||
)
|
||||
);
|
||||
module =
|
||||
block:
|
||||
if lib.hasPrefix "{" block then
|
||||
block
|
||||
else
|
||||
''
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
${block}
|
||||
}
|
||||
'';
|
||||
|
||||
docs = [
|
||||
{
|
||||
where = "README.md";
|
||||
stem = "README";
|
||||
text = builtins.readFile ../README.md;
|
||||
}
|
||||
]
|
||||
++ map (name: {
|
||||
where = "docs/usage/${name}";
|
||||
stem = lib.replaceStrings [ "/" ] [ "-" ] (lib.removeSuffix ".md" name);
|
||||
text = builtins.readFile (usageDir + "/${name}");
|
||||
}) guides;
|
||||
in
|
||||
{
|
||||
inherit guides;
|
||||
dir = "docs/usage/.snippets";
|
||||
# [ { file, where, text } ], file relative to dir.
|
||||
snippets = lib.concatMap (
|
||||
doc:
|
||||
lib.imap1 (index: block: {
|
||||
file = "${doc.stem}-${toString index}.nix";
|
||||
where = "${doc.where}, nix block ${toString index}";
|
||||
text = module block;
|
||||
}) (blocks doc.text)
|
||||
) docs;
|
||||
}
|
||||
Reference in new issue
Block a user