plugins/neorg: switch to mkNeovimPlugin

This commit is contained in:
Gaetan Lepage 2024-12-13 00:45:38 +01:00 committed by nix-infra-bot
parent c0550513b3
commit 2b5a4a3896
3 changed files with 296 additions and 197 deletions

View file

@ -1,173 +1,222 @@
{ {
lib, lib,
helpers,
config, config,
pkgs, pkgs,
... ...
}: }:
let let
cfg = config.plugins.neorg; inherit (lib.nixvim)
defaultNullOpts
mkNullOrStr
mkNullOrOption
mkNullOrOption'
;
inherit (lib) types;
in in
with lib; lib.nixvim.neovim-plugin.mkNeovimPlugin {
{ name = "neorg";
options.plugins.neorg = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "neorg";
package = lib.mkPackageOption pkgs "neorg" { maintainers = [ lib.maintainers.GaetanLepage ];
default = [
"vimPlugins" # TODO introduced 2024-12-12: remove after 25.05
"neorg" deprecateExtraOptions = true;
]; optionsRenamedToSettings = [
"lazyLoading"
[
"logger"
"plugin"
]
[
"logger"
"useConsole"
]
[
"logger"
"highlights"
]
[
"logger"
"useFile"
]
[
"logger"
"level"
]
[
"logger"
"floatPrecision"
]
];
imports = [
./deprecations.nix
];
extraOptions = {
telescopeIntegration = {
enable = lib.mkEnableOption "`neorg-telescope` plugin for telescope integration.";
package = lib.mkPackageOption pkgs "neorg-telescope" {
default = [
"vimPlugins"
"neorg-telescope"
];
};
};
};
settingsOptions = {
hook = mkNullOrOption types.rawLua ''
A user-defined function that is invoked whenever Neorg starts up. May be used to e.g. set custom keybindings.
```lua
fun(manual: boolean, arguments?: string)
```
'';
lazy_loading = defaultNullOpts.mkBool false ''
Whether to defer loading the Neorg core until after the user has entered a `.norg` file.
'';
load = defaultNullOpts.mkAttrsOf' {
description = ''
A list of modules to load, alongside their configurations.
'';
example = {
"core.defaults".__empty = null;
"core.concealer".config = {
icon_preset = "varied";
};
"core.dirman".config = {
workspaces = {
work = "~/notes/work";
home = "~/notes/home";
};
};
};
pluginDefault = { };
type = types.anything;
}; };
neorgTelescopePackage = lib.mkPackageOption pkgs [ logger = {
"vimPlugins" plugin = defaultNullOpts.mkStr "neorg" ''
"neorg-telescope" Name of the plugin.
] { nullable = true; }; Prepended to log messages.
'';
lazyLoading = helpers.defaultNullOpts.mkBool false ''''; use_console = defaultNullOpts.mkBool true ''
Whether to print the output to Neovim while running.
'';
logger = highlights = defaultNullOpts.mkBool true ''
let Whether highlighting should be used in console (using `:echohl`).
modes = { '';
trace = {
hl = "Comment"; use_file = defaultNullOpts.mkBool true ''
level = "trace"; Whether to write output to a file.
}; '';
debug = {
hl = "Comment"; level = defaultNullOpts.mkStr "warn" ''
level = "debug"; Any messages above this level will be logged.
}; '';
info = {
hl = "None"; modes = defaultNullOpts.mkListOf' {
level = "info"; description = ''
}; Level configuration.
warn = {
hl = "WarningMsg";
level = "warn";
};
error = {
hl = "ErrorMsg";
level = "error";
};
fatal = {
hl = "ErrorMsg";
level = 5;
};
};
in
{
plugin = helpers.defaultNullOpts.mkStr "neorg" ''
Name of the plugin. Prepended to log messages
''; '';
type = types.submodule {
useConsole = helpers.defaultNullOpts.mkBool true '' freeformType = with types; attrsOf anything;
Should print the output to neovim while running options = {
''; name = mkNullOrStr ''
Name for this log level.
highlights = helpers.defaultNullOpts.mkBool true ''
Should highlighting be used in console (using echohl)
'';
useFile = helpers.defaultNullOpts.mkBool true ''
Should write to a file
'';
level = helpers.defaultNullOpts.mkEnum (attrNames modes) "warn" ''
Any messages above this level will be logged
'';
modes = mapAttrs (
mode: defaults:
helpers.mkCompositeOption "Settings for mode ${mode}." {
hl = helpers.defaultNullOpts.mkStr defaults.hl ''
Highlight for mode ${mode}.
''; '';
level = helpers.defaultNullOpts.mkLogLevel defaults.level '' hl = mkNullOrStr ''
Level for mode ${mode}. highlight group.
''; '';
}
) modes;
floatPrecision = helpers.defaultNullOpts.mkNullable types.float 1.0e-2 '' level = mkNullOrOption' {
Can limit the number of decimals displayed for floats type = with types; maybeRaw (either ints.unsigned str);
''; description = ''
}; Log level value.
'';
modules = mkOption { example.__raw = "vim.log.levels.TRACE";
type = with types; attrsOf attrs;
description = "Modules configuration.";
default = { };
example = {
"core.defaults" = {
__empty = null;
};
"core.dirman" = {
config = {
workspaces = {
work = "~/notes/work";
home = "~/notes/home";
}; };
}; };
}; };
pluginDefault = [
{
name = "trace";
hl = "Comment";
level.__raw = "vim.log.levels.TRACE";
}
{
name = "debug";
hl = "Comment";
level.__raw = "vim.log.levels.DEBUG";
}
{
name = "info";
hl = "None";
level.__raw = "vim.log.levels.INFO";
}
{
name = "warn";
hl = "WarningMsg";
level.__raw = "vim.log.levels.WARN";
}
{
name = "error";
hl = "ErrorMsg";
level.__raw = "vim.log.levels.ERROR";
}
{
name = "fatal";
hl = "ErrorMsg";
level = 5;
}
];
};
float_precision = defaultNullOpts.mkNullable types.float 0.01 ''
Can limit the number of decimals displayed for floats.
'';
};
};
settingsExample = {
load = {
"core.defaults".__empty = null;
"core.concealer".config = {
icon_preset = "varied";
};
"core.dirman".config = {
workspaces = {
work = "~/notes/work";
home = "~/notes/home";
};
}; };
}; };
}; };
config = extraConfig = cfg: {
let
setupOptions =
with cfg;
{
lazy_loading = lazyLoading;
logger = with logger; { extraPlugins = lib.mkIf cfg.telescopeIntegration.enable [ cfg.telescopeIntegration.package ];
inherit plugin;
use_console = useConsole;
inherit highlights;
use_file = useFile;
inherit level;
modes = filter (v: v != null) ( warnings =
mapAttrsToList ( let
mode: modeConfig: modules = cfg.settings.load or { };
helpers.ifNonNull' modeConfig { telescopeModuleEnabled = (modules."core.integrations.telescope" or null) != null;
name = mode; in
inherit (modeConfig) hl level; (lib.optional (telescopeModuleEnabled && (!cfg.telescopeIntegration.enable)) ''
} You have enabled the telescope neorg module (`core.integrations.telescope`) but have not enabled `plugins.neorg.telescopeIntegration.enable`.
) modes The latter will install the `neorg-telescope` plugin necessary for this integration to work.
); '')
float_precision = floatPrecision; ++ (lib.optional (cfg.telescopeIntegration.enable && (!config.plugins.telescope.enable)) ''
}; Telescope support for neorg is enabled but the telescope plugin is not.
'')
load = modules; ++ (lib.optional ((modules ? "core.defaults") && (!config.plugins.treesitter.enable)) ''
} Neorg's `core.defaults` module is enabled but `plugins.treesitter` is not.
// cfg.extraOptions; Treesitter is required when using the `core.defaults`.
'');
telescopeSupport = hasAttr "core.integrations.telescope" cfg.modules; };
in
mkIf cfg.enable {
warnings =
(optional (telescopeSupport && (!config.plugins.telescope.enable)) ''
Telescope support for neorg (`core.integrations.telescope`) is enabled but the
telescope plugin is not.
'')
++ (optional (telescopeSupport && (cfg.neorgTelescopePackage == null)) ''
Telescope support for neorg (`core.integrations.telescope`) is enabled but the
`neorgTelescopePackage` package is not set.
'')
++ (optional ((hasAttr "core.defaults" cfg.modules) && (!config.plugins.treesitter.enable)) ''
Neorg's `core.defaults` module is enabled but `plugins.treesitter` is not.
Treesitter is required when using the `core.defaults`.
'');
extraPlugins = [
cfg.package
] ++ (optional (telescopeSupport && cfg.neorgTelescopePackage != null) cfg.neorgTelescopePackage);
extraConfigLua = ''
require('neorg').setup(${helpers.toLuaObject setupOptions})
'';
};
} }

View file

@ -0,0 +1,32 @@
{ lib, ... }:
let
basePluginPath = [
"plugins"
"neorg"
];
in
{
imports = [
(lib.mkRenamedOptionModule (basePluginPath ++ [ "modules" ]) (
basePluginPath
++ [
"settings"
"load"
]
))
(lib.mkRemovedOptionModule (
basePluginPath
++ [
"logger"
"modes"
]
) "Please use `settings.logger.modes` but you now need to provide a list of submodules.")
(lib.mkRenamedOptionModule (basePluginPath ++ [ "neorgTelescopePackage" ]) (
basePluginPath
++ [
"telescopeIntegration"
"package"
]
))
];
}

View file

@ -5,56 +5,83 @@
plugins.neorg.enable = true; plugins.neorg.enable = true;
}; };
example = { defaults = {
plugins = { plugins = {
# Treesitter is required when using the "core.defaults" module. # Treesitter is required when using the "core.defaults" module.
treesitter.enable = true; treesitter.enable = true;
neorg = { neorg = {
enable = true; enable = true;
lazyLoading = false; settings = {
logger = { hook = null;
plugin = "neorg"; lazy_loading = false;
useConsole = true; load = { };
highlights = true; logger = {
useFile = true; plugin = "neorg";
level = "warn"; use_console = true;
modes = { highlights = true;
trace = { use_file = true;
hl = "Comment"; level = "warn";
level = "trace"; modes = [
}; {
debug = { name = "trace";
hl = "Comment"; hl = "Comment";
level = "debug"; level.__raw = "vim.log.levels.TRACE";
}; }
info = { {
hl = "None"; name = "debug";
level = "info"; hl = "Comment";
}; level.__raw = "vim.log.levels.DEBUG";
warn = { }
hl = "WarningMsg"; {
level = "warn"; name = "info";
}; hl = "None";
error = { level.__raw = "vim.log.levels.INFO";
hl = "ErrorMsg"; }
level = "error"; {
}; name = "warn";
fatal = { hl = "WarningMsg";
hl = "ErrorMsg"; level.__raw = "vim.log.levels.WARN";
level = 5; }
}; {
}; name = "error";
floatPrecision = 1.0e-2; hl = "ErrorMsg";
}; level.__raw = "vim.log.levels.ERROR";
}
{
name = "fatal";
hl = "ErrorMsg";
level = 5;
}
];
modules = { float_precision = 0.01;
"core.defaults" = {
__empty = null;
}; };
"core.dirman" = { };
config = { };
};
};
example = {
plugins = {
# Treesitter is required when using the "core.defaults" module.
treesitter.enable = true;
neorg = {
enable = true;
settings = {
lazy_loading = true;
load = {
"core.defaults".__empty = null;
"core.concealer".config = {
icon_preset = "varied";
};
"core.dirman".config = {
workspaces = { workspaces = {
work = "~/notes/work"; work = "~/notes/work";
home = "~/notes/home"; home = "~/notes/home";
@ -74,20 +101,11 @@
neorg = { neorg = {
enable = true; enable = true;
modules."core.integrations.telescope".__empty = null; settings.load."core.integrations.telescope".__empty = null;
telescopeIntegration.enable = true;
}; };
web-devicons.enable = true; web-devicons.enable = true;
}; };
}; };
no-packages = {
# Treesitter is required when using the "core.defaults" module.
plugins.treesitter.enable = true;
plugins.neorg = {
enable = true;
neorgTelescopePackage = null;
};
};
} }