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.
This commit is contained in:
Viktor Kronvall 2023-11-23 23:16:41 +09:00
parent 728423e6f4
commit 0dcb767676
2 changed files with 39 additions and 1 deletions

View file

@ -128,6 +128,8 @@ let
}; };
inherit revision home-manager-render-docs; inherit revision home-manager-render-docs;
}; };
html = home-manager-manual;
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix { } { inherit html; };
in { in {
inherit nmdSrc; inherit nmdSrc;
@ -150,7 +152,7 @@ in {
manPages = home-configuration-manual; manPages = home-configuration-manual;
manual = { html = home-manager-manual; }; manual = { inherit html htmlOpenTool; };
# Unstable, mainly for CI. # Unstable, mainly for CI.
jsonModuleMaintainers = pkgs.writeText "hm-module-maintainers.json" (let jsonModuleMaintainers = pkgs.writeText "hm-module-maintainers.json" (let

36
docs/html-open-tool.nix Normal file
View file

@ -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 ];
}