nix-community.nixvim/docs/user-configs/default.nix
Matt Sturgeon a658e81d71
docs/config-examples: generate dynamically from a toml list
This should help to maintain uniformity and hopefully make contributions
easier.

Kept regression tests local to the derivation, however these are also
added to the flake checks.
2024-12-15 17:44:56 +00:00

56 lines
1.3 KiB
Nix

{
callPackages,
stdenvNoCC,
yq,
name ? "user-configs",
}:
stdenvNoCC.mkDerivation (finalAttrs: {
enableParallelBuilding = true;
phases = [ "buildPhase" ];
inherit name;
src = ./list.toml;
nativeBuildInputs = [
yq # provides tomlq
];
# Function definitions for use in the jq query
jqFunctions = ''
def normalizeSpaces: . | gsub("\\s+"; " ") | ltrimstr(" ") | rtrimstr(" ");
'';
# The jq query passed to tomlq
query = ''
.config
| sort_by(
(.owner | ascii_downcase),
(.title // .repo | ascii_downcase)
)
| .[]
| .title = (.title // .repo | normalizeSpaces)
| .owner_url = "https://github.com/\(.owner)"
| .url = (.url // "\(.owner_url)/\(.repo)")
| .description = (.description // "" | normalizeSpaces)
'';
# The markdown table heading
heading = ''
| Owner | Config | Comment |
|-------|--------|---------|
'';
# A jq query "template" for the markdown table row
template = ''
"| [\(.owner)](\(.owner_url)) | [\(.title)](\(.url)) | \(.description) |"
'';
buildPhase = ''
echo -n "$heading" > "$out"
tomlq "$jqFunctions $query | $template" --raw-output "$src" >> "$out"
'';
passthru = {
tests = callPackages ./tests.nix { drv = finalAttrs.finalPackage; };
};
})