2022-12-11 14:56:09 +00:00
|
|
|
# Generates the documentation for library functions via nixdoc.
|
2018-12-30 00:10:19 +00:00
|
|
|
|
2023-06-24 20:14:37 +00:00
|
|
|
{ pkgs, nixpkgs, libsets }:
|
2018-12-30 00:10:19 +00:00
|
|
|
|
2023-06-24 20:14:37 +00:00
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
2023-03-25 20:38:26 +00:00
|
|
|
locationsJSON = import ./lib-function-locations.nix { inherit pkgs nixpkgs libsets; };
|
2023-06-24 20:14:37 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2018-12-30 00:10:19 +00:00
|
|
|
name = "nixpkgs-lib-docs";
|
2022-12-11 14:56:09 +00:00
|
|
|
src = ../../lib;
|
2018-12-30 00:10:19 +00:00
|
|
|
|
|
|
|
buildInputs = [ nixdoc ];
|
|
|
|
installPhase = ''
|
|
|
|
function docgen {
|
2023-07-08 16:43:36 +00:00
|
|
|
name=$1
|
|
|
|
baseName=$2
|
|
|
|
description=$3
|
|
|
|
# TODO: wrap lib.$name in <literal>, make nixdoc not escape it
|
|
|
|
if [[ -e "../lib/$baseName.nix" ]]; then
|
|
|
|
nixdoc -c "$name" -d "lib.$name: $description" -l ${locationsJSON} -f "$baseName.nix" > "$out/$name.md"
|
2022-12-23 19:57:49 +00:00
|
|
|
else
|
2023-07-08 16:43:36 +00:00
|
|
|
nixdoc -c "$name" -d "lib.$name: $description" -l ${locationsJSON} -f "$baseName/default.nix" > "$out/$name.md"
|
2022-12-23 19:57:49 +00:00
|
|
|
fi
|
2023-07-08 16:43:36 +00:00
|
|
|
echo "$out/$name.md" >> "$out/index.md"
|
2018-12-30 00:10:19 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 14:56:09 +00:00
|
|
|
mkdir -p "$out"
|
|
|
|
|
2023-03-25 20:38:26 +00:00
|
|
|
cat > "$out/index.md" << 'EOF'
|
2024-01-15 20:07:52 +00:00
|
|
|
```{=include=} sections auto-id-prefix=auto-generated
|
2022-12-11 14:56:09 +00:00
|
|
|
EOF
|
|
|
|
|
2023-07-08 16:43:36 +00:00
|
|
|
${lib.concatMapStrings ({ name, baseName ? name, description }: ''
|
|
|
|
docgen ${name} ${baseName} ${lib.escapeShellArg description}
|
2022-12-12 11:21:59 +00:00
|
|
|
'') libsets}
|
2018-12-30 00:10:19 +00:00
|
|
|
|
2023-03-25 20:38:26 +00:00
|
|
|
echo '```' >> "$out/index.md"
|
2018-12-30 00:10:19 +00:00
|
|
|
'';
|
|
|
|
}
|