plugins/vimtex: switch to mkVimPlugin

This commit is contained in:
Gaetan Lepage 2024-02-13 23:16:01 +01:00 committed by Gaétan Lepage
parent 485d21f60d
commit b6138b409f

View file

@ -4,80 +4,94 @@
config, config,
pkgs, pkgs,
... ...
}: let }:
cfg = config.plugins.vimtex; with lib;
in helpers.vim-plugin.mkVimPlugin config {
with lib; { name = "vimtex";
options.plugins.vimtex = { defaultPackage = pkgs.vimPlugins.vimtex;
enable = mkEnableOption "vimtex"; globalPrefix = "vimtex_";
package = helpers.mkPackageOption "vimtex" pkgs.vimPlugins.vimtex; maintainers = [maintainers.GaetanLepage];
extraConfig = mkOption { extraPackages = [pkgs.pstree];
type = types.attrs;
description = ''
The configuration options for vimtex without the 'vimtex_' prefix.
Example: To set 'vimtex_compiler_enabled' to 1, write
extraConfig = {
compiler_enabled = true;
};
'';
default = {};
};
viewMethod = mkOption { # TODO introduced 2024-02-20: remove 2024-04-20
deprecateExtraConfig = true;
optionsRenamedToSettings = [
"viewMethod"
];
imports = let
basePluginPath = ["plugins" "vimtex"];
in [
(
mkRemovedOptionModule
(basePluginPath ++ ["installTexLive"])
"If you don't want `texlive` to be installed, set `plugins.vimtex.texlivePackage` to `null`."
)
(
mkRenamedOptionModule
(basePluginPath ++ ["texLivePackage"])
(basePluginPath ++ ["texlivePackage"])
)
];
settingsOptions = {
view_method = mkOption {
type = types.str; type = types.str;
description = ''
The view method that vimtex will use to display PDF's.
Check https://github.com/lervag/vimtex/blob/03c83443108a6984bf90100f6d00ec270b84a339/doc/vimtex.txt#L3322
for more information.
'';
default = "general"; default = "general";
}; example = "zathura";
installTexLive = mkOption {
type = types.bool;
description = '' description = ''
Whether or not to install TexLive. Set the viewer method.
See https://nixos.wiki/wiki/TexLive. By default, a generic viewer is used through the general view method (e.g. `xdg-open` on Linux).
''; '';
default = false;
}; };
texLivePackage = helpers.mkPackageOption "texLivePackage" pkgs.texlive.combined.scheme-medium;
}; };
config = let settingsExample = {
globals = view_method = "zathura";
{ compiler_method = "latexrun";
enabled = cfg.enable; toc_config = {
callback_progpath = "nvim"; split_pos = "vert topleft";
view_method = cfg.viewMethod; split_width = 40;
}
// cfg.extraConfig;
basePackages =
[pkgs.pstree]
++ (
lib.optional cfg.installTexLive cfg.texLivePackage
);
viewMethodAndPDFViewerPairs = {
general = [pkgs.xdotool];
zathura = [pkgs.xdotool pkgs.zathura];
zathura_simple = [pkgs.zathura];
mupdf = [pkgs.xdotool pkgs.mupdf];
}; };
in };
mkIf cfg.enable {
extraPlugins = [cfg.package];
extraPackages = extraOptions = {
basePackages texlivePackage = mkOption {
++ ( type = with types; nullOr package;
optionals default = pkgs.texlive.combined.scheme-medium;
( example = null;
hasAttr "${cfg.viewMethod}" viewMethodAndPDFViewerPairs description = ''
) The package to install for `textlive.
viewMethodAndPDFViewerPairs."${cfg.viewMethod}" Set to `null` for not installing `texlive` at all.
); '';
globals = mapAttrs' (name: nameValuePair ("vimtex_" + name)) globals;
}; };
};
extraConfig = cfg: {
plugins.vimtex.settings = {
enabled = true;
callback_progpath = "nvim";
};
extraPackages = let
# xdotool does not exist on darwin
xdotool = optional pkgs.stdenv.isLinux pkgs.xdotool;
viewerPackages =
{
general = xdotool;
zathura = xdotool ++ [pkgs.zathura];
zathura_simple = [pkgs.zathura];
mupdf = xdotool ++ [pkgs.mupdf];
}
.${cfg.settings.view_method}
or [];
in
(
optional
(cfg.texlivePackage != null)
cfg.texlivePackage
)
++ viewerPackages;
};
} }