From c2dbf7acf14a4fcf7496db04be08d69f98a6c86e Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 23 Oct 2024 18:16:03 +0100 Subject: [PATCH] docs/mdbook: clean up derivation --- docs/mdbook/default.nix | 56 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/docs/mdbook/default.nix b/docs/mdbook/default.nix index b5521296..bf6ab987 100644 --- a/docs/mdbook/default.nix +++ b/docs/mdbook/default.nix @@ -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; + }; +})