2022-12-28 21:21:41 +00:00
|
|
|
# Generates the documentation for library functions via nixdoc.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
{ pkgs, nixpkgs, libsets }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
locationsJSON = import ./lib-function-locations.nix { inherit pkgs nixpkgs libsets; };
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "nixpkgs-lib-docs";
|
2022-12-28 21:21:41 +00:00
|
|
|
src = ../../lib;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs = [ nixdoc ];
|
|
|
|
installPhase = ''
|
|
|
|
function docgen {
|
2023-07-15 17:15:38 +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"
|
2023-01-11 07:51:40 +00:00
|
|
|
else
|
2023-07-15 17:15:38 +00:00
|
|
|
nixdoc -c "$name" -d "lib.$name: $description" -l ${locationsJSON} -f "$baseName/default.nix" > "$out/$name.md"
|
2023-01-11 07:51:40 +00:00
|
|
|
fi
|
2023-07-15 17:15:38 +00:00
|
|
|
echo "$out/$name.md" >> "$out/index.md"
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
mkdir -p "$out"
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
cat > "$out/index.md" << 'EOF'
|
|
|
|
```{=include=} sections
|
2022-12-28 21:21:41 +00:00
|
|
|
EOF
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
${lib.concatMapStrings ({ name, baseName ? name, description }: ''
|
|
|
|
docgen ${name} ${baseName} ${lib.escapeShellArg description}
|
2022-12-28 21:21:41 +00:00
|
|
|
'') libsets}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
echo '```' >> "$out/index.md"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
}
|