1
0
Fork 0
mirror of https://github.com/NotAShelf/neovim-flake.git synced 2024-12-28 04:59:49 +01:00
neovim-flake/docs/default.nix

139 lines
4.2 KiB
Nix
Raw Normal View History

{
pkgs,
2023-10-03 21:08:35 +02:00
lib ? import ../lib/stdlib-extended.nix pkgs.lib,
nmdSrc,
2023-12-09 20:03:58 +01:00
...
}: let
nmd = import nmdSrc {
inherit lib;
# The DocBook output of `nixos-render-docs` doesn't have the change
# `nmd` uses to work around the broken stylesheets in
# `docbook-xsl-ns`, so we restore the patched version here.
pkgs =
pkgs
// {
docbook-xsl-ns =
pkgs.docbook-xsl-ns.override {withManOptDedupPatch = true;};
};
};
# Make sure the used package is scrubbed to avoid actually
# instantiating derivations.
scrubbedPkgsModule = {
imports = [
{
_module.args = {
pkgs = lib.mkForce (nmd.scrubDerivations "pkgs" pkgs);
pkgs_i686 = lib.mkForce {};
};
}
];
};
2023-12-09 20:03:58 +01:00
dontCheckDefinitions = {_module.check = false;};
githubDeclaration = user: repo: subpath: let
urlRef = "main";
in {
url = "https://github.com/${user}/${repo}/blob/${urlRef}/${subpath}";
name = "<${repo}/${subpath}>";
};
2023-12-09 20:21:36 +01:00
nvimPath = toString ./..;
buildOptionsDocs = args @ {
modules,
2023-12-09 20:03:58 +01:00
includeModuleSystemOptions ? true,
...
}: let
2023-12-09 20:03:58 +01:00
inherit ((lib.evalModules {inherit modules;})) options;
in
2023-12-09 20:03:58 +01:00
pkgs.buildPackages.nixosOptionsDoc ({
options =
2023-12-09 20:03:58 +01:00
if includeModuleSystemOptions
then options
2023-12-09 20:03:58 +01:00
else builtins.removeAttrs options ["_module"];
transformOptions = opt:
opt
// {
2023-12-09 20:03:58 +01:00
# Clean up declaration sites to not refer to the Home Manager
# source tree.
declarations = map (decl:
2023-12-09 20:21:36 +01:00
if lib.hasPrefix nvimPath (toString decl)
2023-12-09 20:03:58 +01:00
then
githubDeclaration "notashelf" "neovim-flake"
2023-12-09 20:21:36 +01:00
(lib.removePrefix "/" (lib.removePrefix nvimPath (toString decl)))
2023-12-09 20:03:58 +01:00
else if decl == "lib/modules.nix"
then
# TODO: handle this in a better way (may require upstream
# changes to nixpkgs)
githubDeclaration "NixOS" "nixpkgs" decl
else decl)
opt.declarations;
};
}
2023-12-09 20:03:58 +01:00
// builtins.removeAttrs args ["modules" "includeModuleSystemOptions"]);
nvimModuleDocs = buildOptionsDocs {
modules =
2023-12-09 20:03:58 +01:00
import ../modules/modules.nix {
inherit lib pkgs;
check = false;
}
++ [scrubbedPkgsModule];
variablelistId = "neovim-flake-options";
};
2023-12-09 20:03:58 +01:00
release-config = builtins.fromJSON (builtins.readFile ../release.json);
revision = "release-${release-config.release}";
# Generate the `man home-configuration.nix` package
nvf-configuration-manual =
2023-12-09 20:03:58 +01:00
pkgs.runCommand "neovim-flake-reference-manpage" {
nativeBuildInputs = [pkgs.buildPackages.installShellFiles pkgs.nixos-render-docs];
allowedReferences = ["out"];
} ''
# Generate manpages.
mkdir -p $out/share/man/man5
mkdir -p $out/share/man/man1
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
--revision ${revision} \
${nvimModuleDocs.optionsJSON}/share/doc/nixos/options.json \
2023-12-09 20:21:36 +01:00
$out/share/man/man5/neovim-flake.5
cp ${./neovim-flake.1} $out/share/man/man1/neovim-flake.1
'';
2023-12-09 20:03:58 +01:00
# Generate the HTML manual pages
neovim-flake-manual = pkgs.callPackage ./manual.nix {
inherit revision;
outputPath = "share/doc/neovim-flake";
nmd = nmdSrc;
options = {
neovim-flake = nvimModuleDocs.optionsJSON;
};
};
2023-12-09 20:03:58 +01:00
html = neovim-flake-manual;
htmlOpenTool = pkgs.callPackage ./html-open-tool.nix {} {inherit html;};
in {
2023-12-09 20:03:58 +01:00
inherit nmdSrc;
2023-12-09 20:03:58 +01:00
options = {
# TODO: Use `hmOptionsDocs.optionsJSON` directly once upstream
# `nixosOptionsDoc` is more customizable.
json =
pkgs.runCommand "options.json" {
meta.description = "List of Home Manager options in JSON format";
} ''
mkdir -p $out/{share/doc,nix-support}
2023-12-09 20:21:36 +01:00
cp -a ${nvimModuleDocs.optionsJSON}/share/doc/nixos $out/share/doc/neovim-flake
2023-12-09 20:03:58 +01:00
substitute \
${nvimModuleDocs.optionsJSON}/nix-support/hydra-build-products \
$out/nix-support/hydra-build-products \
--replace \
'${nvimModuleDocs.optionsJSON}/share/doc/nixos' \
2023-12-09 20:21:36 +01:00
"$out/share/doc/neovim-flake"
2023-12-09 20:03:58 +01:00
'';
};
manPages = nvf-configuration-manual;
2023-12-09 20:03:58 +01:00
manual = {inherit html htmlOpenTool;};
}