docs/mdbook: clean up derivation

This commit is contained in:
Matt Sturgeon 2024-10-23 18:16:03 +01:00
parent 28bdec9cf7
commit c2dbf7acf1
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -205,7 +205,7 @@ let
};
mdbook = {
nixvimOptions = mapModulesToString (
nixvimOptionsSummary = mapModulesToString (
name: opts:
let
isBranch = name == "index" || (opts.hasComponents && opts.index.options != { });
@ -277,36 +277,21 @@ let
in
removeUnwanted configuration.options
);
prepareMD = ''
# Copy inputs into the build directory
cp -r --no-preserve=all $inputs/* ./
cp ${../../CONTRIBUTING.md} ./CONTRIBUTING.md
cp -r ${../user-guide} ./user-guide
cp -r ${../modules} ./modules
# Copy the generated MD docs into the build directory
# Using pkgs.writeShellScript helps to avoid the "bash: argument list too long" error
bash -e ${pkgs.writeShellScript "copy_docs" docs.commands}
# Prepare SUMMARY.md for mdBook
# Using pkgs.writeText helps to avoid the same error as above
substituteInPlace ./SUMMARY.md \
--replace-fail "@NIXVIM_OPTIONS@" "$(cat ${pkgs.writeText "nixvim-options-summary.md" mdbook.nixvimOptions})"
substituteInPlace ./modules/wrapper-options.md \
--replace-fail "@WRAPPER_OPTIONS@" "$(cat ${mdbook.wrapperOptionDocs})"
'';
in
pkgs.stdenv.mkDerivation {
pkgs.stdenv.mkDerivation (finalAttrs: {
name = "nixvim-docs";
# Use structured attrs to avoid "bash: argument list too long" errors
__structuredAttrs = true;
phases = [ "buildPhase" ];
buildInputs = [
pkgs.mdbook
pkgs.mdbook-alerts
];
inputs = lib.sourceFilesBySuffices ./. [
".md"
".toml"
@ -316,10 +301,33 @@ pkgs.stdenv.mkDerivation {
buildPhase = ''
dest=$out/share/doc/nixvim
mkdir -p $dest
${prepareMD}
# Copy inputs into the build directory
cp -r --no-preserve=all $inputs/* ./
cp ${../../CONTRIBUTING.md} ./CONTRIBUTING.md
cp -r ${../user-guide} ./user-guide
cp -r ${../modules} ./modules
# Copy the generated MD docs into the build directory
bash -e ${finalAttrs.passthru.copy-docs}
# Patch SUMMARY.md - which defiens mdBook's table of contents
substituteInPlace ./SUMMARY.md \
--replace-fail "@NIXVIM_OPTIONS@" "$nixvimOptionsSummary"
substituteInPlace ./modules/wrapper-options.md \
--replace-fail "@WRAPPER_OPTIONS@" "$(cat ${finalAttrs.passthru.wrapperOptionDocs})"
mdbook build
cp -r ./book/* $dest
mkdir -p $dest/search
cp -r ${search}/* $dest/search
'';
}
inherit (mdbook) nixvimOptionsSummary;
passthru = {
inherit (mdbook) wrapperOptionDocs;
copy-docs = pkgs.writeShellScript "copy-docs" docs.commands;
};
})