From 8255b13aa0758d9e7764cfb4fa9b1b4d19700f68 Mon Sep 17 00:00:00 2001 From: Viktor Kronvall Date: Thu, 23 Nov 2023 23:16:41 +0900 Subject: [PATCH] docs: add htmlOpenTool to manual This commit extracts the htmlOpenTool from `nmd` into a module in the home-manager docs directory. This is done to provide feature parity with the documentation generated using the docbook .xml files. --- docs/default.nix | 4 +++- docs/html-open-tool.nix | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 docs/html-open-tool.nix diff --git a/docs/default.nix b/docs/default.nix index 20974c2fd..de7fb4b67 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -128,6 +128,8 @@ let }; inherit revision home-manager-render-docs; }; + html = home-manager-manual; + htmlOpenTool = pkgs.callPackage ./html-open-tool.nix { } { inherit html; }; in { inherit nmdSrc; @@ -150,7 +152,7 @@ in { manPages = home-configuration-manual; - manual = { html = home-manager-manual; }; + manual = { inherit html htmlOpenTool; }; # Unstable, mainly for CI. jsonModuleMaintainers = pkgs.writeText "hm-module-maintainers.json" (let diff --git a/docs/html-open-tool.nix b/docs/html-open-tool.nix new file mode 100644 index 000000000..081616dd9 --- /dev/null +++ b/docs/html-open-tool.nix @@ -0,0 +1,36 @@ +{ writeShellScriptBin, makeDesktopItem, symlinkJoin }: +{ html, pathName ? "home-manager", projectName ? pathName +, name ? "${pathName}-help" }: +let + helpScript = writeShellScriptBin name '' + set -euo pipefail + + if [[ ! -v BROWSER || -z $BROWSER ]]; then + for candidate in xdg-open open w3m; do + BROWSER="$(type -P $candidate || true)" + if [[ -x $BROWSER ]]; then + break; + fi + done + fi + + if [[ ! -v BROWSER || -z $BROWSER ]]; then + echo "$0: unable to start a web browser; please set \$BROWSER" + exit 1 + else + exec "$BROWSER" "${html}/share/docs/${pathName}/index.html" + fi + ''; + + desktopItem = makeDesktopItem { + name = "${pathName}-manual"; + desktopName = "${projectName} Manual"; + genericName = "View ${projectName} documentation in a web browser"; + icon = "nix-snowflake"; + exec = "${helpScript}/bin/${name}"; + categories = [ "System" ]; + }; +in symlinkJoin { + inherit name; + paths = [ helpScript desktopItem ]; +}