From 67bac7fe6d0f7e8d6b6f1190a0f6380374d56535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Mon, 3 Jul 2023 20:29:32 +0200 Subject: [PATCH] Bundle `link-manpages.nix` (#669) It's being removed from nixpkgs as part of the dedocbookification process. Eventually we'll want to use nixos-render-docs to render options. --- flake-info/default.nix | 2 +- flake-info/src/data/link-manpages.nix | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 flake-info/src/data/link-manpages.nix diff --git a/flake-info/default.nix b/flake-info/default.nix index bd239bf..c93e010 100644 --- a/flake-info/default.nix +++ b/flake-info/default.nix @@ -24,7 +24,7 @@ pkgs.rustPlatform.buildRustPackage rec { ROOTDIR = builtins.placeholder "out"; NIXPKGS_PANDOC_FILTERS_PATH = pkgs.path + "/doc/build-aux/pandoc-filters"; - LINK_MANPAGES_PANDOC_FILTER = import (pkgs.path + "/doc/build-aux/pandoc-filters/link-manpages.nix") { inherit pkgs; }; + LINK_MANPAGES_PANDOC_FILTER = import src/data/link-manpages.nix { inherit pkgs; }; checkFlags = [ "--skip elastic::tests" diff --git a/flake-info/src/data/link-manpages.nix b/flake-info/src/data/link-manpages.nix new file mode 100644 index 0000000..9856a00 --- /dev/null +++ b/flake-info/src/data/link-manpages.nix @@ -0,0 +1,28 @@ +{ pkgs }: +let + inherit (pkgs) lib; + manpageURLs = lib.importJSON (pkgs.path + "/doc/manpage-urls.json"); +in pkgs.writeText "link-manpages.lua" '' + --[[ + Adds links to known man pages that aren't already in a link. + ]] + + local manpage_urls = { + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (man: url: + " [${builtins.toJSON man}] = ${builtins.toJSON url},") manpageURLs)} + } + + traverse = 'topdown' + + -- Returning false as the second value aborts processing of child elements. + function Link(elem) + return elem, false + end + + function Code(elem) + local is_man_role = elem.classes:includes('interpreted-text') and elem.attributes['role'] == 'manpage' + if is_man_role and manpage_urls[elem.text] ~= nil then + return pandoc.Link(elem, manpage_urls[elem.text]), false + end + end +''