diff --git a/docs/default.nix b/docs/default.nix index 20974c2f..de7fb4b6 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 00000000..081616dd --- /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 ]; +}