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