doc: store module documentation as a README within the module

This has two benefits:

1. It will be displayed when browsing the module source code on
   GitHub.
2. It prevents the documentation inadvertently disappearing if the
   module directory is renamed.
This commit is contained in:
Daniel Thwaites 2025-02-17 20:08:59 +00:00
parent 7afc6fb46d
commit 472bd50c85
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D

View file

@ -106,7 +106,7 @@ pkgs.stdenvNoCC.mkDerivation {
optionsFile="$2"
outputFile="$3"
echo "## $platformName options" >>"$outputFile"
echo -e "\n## $platformName options" >>"$outputFile"
if [ -s "$optionsFile" ]; then
sed -e "$REDUCE_HEADINGS" -e "$REMOVE_DECLARED_BY" <"$optionsFile" >>"$outputFile"
@ -120,10 +120,16 @@ pkgs.stdenvNoCC.mkDerivation {
homeManagerOptionsFile="$2"
nixosOptionsFile="$3"
readmeFile="${inputs.self}/modules/$moduleName/README.md"
page="options/modules/$moduleName.md"
outputFile="src/$page"
if [ ! -f "$file" ]; then
if [ -f "$outputFile" ]; then
echo "Please move docs/src/options/modules/$moduleName.md to modules/$moduleName/README.md" >&2
exit 1
elif [ -f "$readmeFile" ]; then
cp --no-preserve=mode,ownership "$readmeFile" "$outputFile"
else
echo "# $moduleName" >>"$outputFile"
echo ${lib.escapeShellArg ''
> [!NOTE]