diff --git a/docs/default.nix b/docs/default.nix index e7371a6..4df87f9 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -12,6 +12,8 @@ in { renderDocs = { enable = true; + name = "cardano-nix-docs"; + mkdocsYamlFile = ./mkdocs.yml; sidebarOptions = [ { anchor = "cardano"; diff --git a/docs/render.nix b/docs/render.nix index b3ecf28..ff2682b 100644 --- a/docs/render.nix +++ b/docs/render.nix @@ -2,11 +2,12 @@ config, inputs, lib, + self, ... }: let cfg = config.renderDocs; - inherit (lib) mkOption mkEnableOption mkIf; + inherit (lib) mkOption mkEnableOption mkIf mkMerge; inherit (lib.types) bool str listOf deferredModule submodule path; sidebarType = submodule { @@ -50,11 +51,31 @@ in { options.renderDocs = { enable = mkEnableOption "Document rendering"; + name = mkOption { + type = str; + description = '' + Title of the documentation + ''; + }; packageName = mkOption { type = str; default = "docs"; description = '' - Name of package with generated documentation (in flake outputs) + Name of package containing the documentation + ''; + }; + mkdocsYamlFile = mkOption { + type = path; + default = "${self}/docs/mkdocs.yml"; + description = '' + Path to the mkdocs.yml file + ''; + }; + devshells = mkOption { + type = listOf str; + default = ["default"]; + description = '' + Names of the devshells to add `docs-serve` and `docs-build` commands to ''; }; @@ -75,7 +96,7 @@ in { type = bool; default = false; description = '' - render invisible options as well + Render invisible options as well ''; }; }; @@ -203,70 +224,78 @@ in { pkgs.runCommand "mkdocs.yaml" { nativeBuildInputs = [pkgs.yq-go]; } '' - yq '. *+ load("${indexYAML}")' ${./mkdocs.yml} -o yaml >$out + yq '. *+ load("${indexYAML}")' ${cfg.mkdocsYamlFile} -o yaml >$out ''; - in { - packages.${cfg.packageName} = stdenv.mkDerivation { - src = ../.; # FIXME: use config.flake-root.package here - name = "cardano-nix-docs"; - - nativeBuildInputs = [my-mkdocs]; + in + mkMerge ([ + { + packages.${cfg.packageName} = stdenv.mkDerivation { + src = ../.; # FIXME: use config.flake-root.package here + # src = builtins.trace config.flake-root.package config.flake-root.package; + inherit (cfg) name; - buildPhase = '' - ln -s ${options-doc} ${docsPath} - # mkdocs expect mkdocs one level upper than `docs/`, but we want to keep it in `docs/` - cp ${mergedMkdocsYaml} mkdocs.yml - mkdocs build -f mkdocs.yml -d site - ''; + nativeBuildInputs = [my-mkdocs]; - installPhase = '' - mv site $out - rm $out/default.nix # Clean unwanted side-effect of mkdocs - ''; + buildPhase = '' + ln -s ${options-doc} ${docsPath} + # mkdocs expect mkdocs one level upper than `docs/`, but we want to keep it in `docs/` + cp ${mergedMkdocsYaml} mkdocs.yml + mkdocs build -f mkdocs.yml -d site + ''; - passthru.serve = pkgs.writeShellScriptBin "serve" '' - set -euo pipefail + installPhase = '' + mv site $out + rm $out/default.nix # Clean unwanted side-effect of mkdocs + ''; - # link in options reference - rm -f ${docsPath} - ln -s ${options-doc} ${docsPath} - rm -f mkdocs.yml - ln -s ${mergedMkdocsYaml} mkdocs.yml + passthru.serve = pkgs.writeShellScriptBin "serve" '' + set -euo pipefail - BASEDIR="$(${lib.getExe config.flake-root.package})" - cd $BASEDIR + # link in options reference + rm -f ${docsPath} + ln -s ${options-doc} ${docsPath} + rm -f mkdocs.yml + ln -s ${mergedMkdocsYaml} mkdocs.yml - cat <