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