mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 19:46:06 +01:00
plugins/efmls-configs: migrate to mkNeovimPlugin
This commit is contained in:
parent
4a274251bf
commit
fa8240195a
1 changed files with 115 additions and 118 deletions
|
|
@ -1,114 +1,128 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
tools = lib.importJSON ../../../generated/efmls-configs-sources.json;
|
name = "efmls-configs";
|
||||||
inherit (import ./packages.nix lib) packaged;
|
package = "efmls-configs-nvim";
|
||||||
in
|
description = "Premade configurations for efm-langserver.";
|
||||||
{
|
maintainers = [ ];
|
||||||
options.plugins.efmls-configs = {
|
|
||||||
enable = lib.mkEnableOption "efmls-configs, premade configurations for efm-langserver";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "efmls-configs-nvim" {
|
dependencies = [
|
||||||
default = [
|
"efm-langserver"
|
||||||
"vimPlugins"
|
];
|
||||||
"efmls-configs-nvim"
|
imports = [
|
||||||
];
|
# TODO: added 2025-10-23, remove after 26.05
|
||||||
};
|
(lib.nixvim.mkRemovedPackageOptionModule {
|
||||||
|
plugin = "efmls-configs";
|
||||||
|
oldPackageName = "efmLangServer";
|
||||||
|
packageName = "efm-langserver";
|
||||||
|
})
|
||||||
|
|
||||||
externallyManagedPackages = lib.mkOption {
|
# Propagate setup warnings
|
||||||
type = with lib.types; either (enum [ "all" ]) (listOf str);
|
{ inherit (config.plugins.efmls-configs.setup) warnings; }
|
||||||
description = ''
|
];
|
||||||
Linters/Formatters to skip installing with nixvim. Set to `all` to install no packages
|
|
||||||
'';
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
|
|
||||||
toolPackages = lib.pipe packaged [
|
hasSettings = false;
|
||||||
# Produce package a option for each tool
|
callSetup = false;
|
||||||
(lib.attrsets.mapAttrs (
|
|
||||||
name: loc:
|
|
||||||
lib.mkPackageOption pkgs name {
|
|
||||||
nullable = true;
|
|
||||||
default = loc;
|
|
||||||
}
|
|
||||||
))
|
|
||||||
# Filter package defaults that are not compatible with the current platform
|
|
||||||
(lib.attrsets.mapAttrs (
|
|
||||||
_: opt:
|
|
||||||
opt
|
|
||||||
// {
|
|
||||||
default = if lib.meta.availableOn pkgs.stdenv.hostPlatform opt.default then opt.default else null;
|
|
||||||
defaultText = lib.literalMD ''
|
|
||||||
`${opt.defaultText.text}` if available on the current system, otherwise null
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
))
|
|
||||||
];
|
|
||||||
|
|
||||||
/*
|
extraOptions =
|
||||||
Users can set the options as follows:
|
|
||||||
|
|
||||||
{
|
|
||||||
c = {
|
|
||||||
linter = "cppcheck";
|
|
||||||
formatter = ["clang-format" "uncrustify"];
|
|
||||||
};
|
|
||||||
go = {
|
|
||||||
linter = ["djlint" "golangci_lint"];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setup = lib.mkOption {
|
|
||||||
type = lib.types.submodule {
|
|
||||||
freeformType = lib.types.attrsOf lib.types.anything;
|
|
||||||
|
|
||||||
options = lib.mapAttrs (
|
|
||||||
_:
|
|
||||||
lib.mapAttrs (
|
|
||||||
kind:
|
|
||||||
{ lang, possible }:
|
|
||||||
let
|
|
||||||
toolType = lib.types.maybeRaw (lib.types.enum possible);
|
|
||||||
in
|
|
||||||
lib.mkOption {
|
|
||||||
type = lib.types.either toolType (lib.types.listOf toolType);
|
|
||||||
default = [ ];
|
|
||||||
description = "${kind} tools for ${lang}";
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) tools;
|
|
||||||
|
|
||||||
# Added 2025-06-25 in https://github.com/nix-community/nixvim/pull/3503
|
|
||||||
imports =
|
|
||||||
map (name: lib.mkRenamedOptionModule [ name ] [ (lib.toLower name) ]) [
|
|
||||||
"HTML"
|
|
||||||
"JSON"
|
|
||||||
]
|
|
||||||
++ lib.singleton {
|
|
||||||
# NOTE: we need a warnings option for `mkRenamedOptionModule` to warn about unexpected definitions
|
|
||||||
# This can be removed when all rename aliases are gone
|
|
||||||
options.warnings = lib.mkOption {
|
|
||||||
type = with lib.types; listOf str;
|
|
||||||
description = "Warnings to propagate to nixvim's `warnings` option.";
|
|
||||||
default = [ ];
|
|
||||||
internal = true;
|
|
||||||
visible = false;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
description = "Configuration for each filetype. Use `all` to match any filetype.";
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config =
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.efmls-configs;
|
inherit (import ./packages.nix lib) packaged;
|
||||||
|
tools = lib.importJSON ../../../generated/efmls-configs-sources.json;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
externallyManagedPackages = lib.mkOption {
|
||||||
|
type = with lib.types; either (enum [ "all" ]) (listOf str);
|
||||||
|
description = ''
|
||||||
|
Linters/Formatters to skip installing with nixvim. Set to `all` to install no packages
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
|
||||||
|
toolPackages = lib.pipe packaged [
|
||||||
|
# Produce package a option for each tool
|
||||||
|
(lib.attrsets.mapAttrs (
|
||||||
|
name: loc:
|
||||||
|
lib.mkPackageOption pkgs name {
|
||||||
|
nullable = true;
|
||||||
|
default = loc;
|
||||||
|
}
|
||||||
|
))
|
||||||
|
# Filter package defaults that are not compatible with the current platform
|
||||||
|
(lib.attrsets.mapAttrs (
|
||||||
|
_: opt:
|
||||||
|
opt
|
||||||
|
// {
|
||||||
|
default = if lib.meta.availableOn pkgs.stdenv.hostPlatform opt.default then opt.default else null;
|
||||||
|
defaultText = lib.literalMD ''
|
||||||
|
`${opt.defaultText.text}` if available on the current system, otherwise null
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
))
|
||||||
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
|
Users can set the options as follows:
|
||||||
|
|
||||||
|
{
|
||||||
|
c = {
|
||||||
|
linter = "cppcheck";
|
||||||
|
formatter = ["clang-format" "uncrustify"];
|
||||||
|
};
|
||||||
|
go = {
|
||||||
|
linter = ["djlint" "golangci_lint"];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
setup = lib.mkOption {
|
||||||
|
type = lib.types.submodule {
|
||||||
|
freeformType = lib.types.attrsOf lib.types.anything;
|
||||||
|
|
||||||
|
options = lib.mapAttrs (
|
||||||
|
_:
|
||||||
|
lib.mapAttrs (
|
||||||
|
kind:
|
||||||
|
{ lang, possible }:
|
||||||
|
let
|
||||||
|
toolType = lib.types.maybeRaw (lib.types.enum possible);
|
||||||
|
in
|
||||||
|
lib.mkOption {
|
||||||
|
type = lib.types.either toolType (lib.types.listOf toolType);
|
||||||
|
default = [ ];
|
||||||
|
description = "${kind} tools for ${lang}";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) tools;
|
||||||
|
|
||||||
|
# Added 2025-06-25 in https://github.com/nix-community/nixvim/pull/3503
|
||||||
|
imports =
|
||||||
|
map (name: lib.mkRenamedOptionModule [ name ] [ (lib.toLower name) ]) [
|
||||||
|
"HTML"
|
||||||
|
"JSON"
|
||||||
|
]
|
||||||
|
++ lib.singleton {
|
||||||
|
# NOTE: we need a warnings option for `mkRenamedOptionModule` to warn about unexpected definitions
|
||||||
|
# This can be removed when all rename aliases are gone
|
||||||
|
options.warnings = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
description = "Warnings to propagate to nixvim's `warnings` option.";
|
||||||
|
default = [ ];
|
||||||
|
internal = true;
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
description = "Configuration for each filetype. Use `all` to match any filetype.";
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig =
|
||||||
|
cfg:
|
||||||
|
let
|
||||||
# Tools that have been selected by the user
|
# Tools that have been selected by the user
|
||||||
tools = lib.lists.unique (
|
tools = lib.lists.unique (
|
||||||
lib.filter lib.isString (
|
lib.filter lib.isString (
|
||||||
|
|
@ -152,7 +166,7 @@ in
|
||||||
mkToolValue =
|
mkToolValue =
|
||||||
kind: opt:
|
kind: opt:
|
||||||
map (
|
map (
|
||||||
tool: if lib.isString tool then helpers.mkRaw "require 'efmls-configs.${kind}.${tool}'" else tool
|
tool: if lib.isString tool then lib.nixvim.mkRaw "require 'efmls-configs.${kind}.${tool}'" else tool
|
||||||
) (lib.toList opt);
|
) (lib.toList opt);
|
||||||
|
|
||||||
setupOptions =
|
setupOptions =
|
||||||
|
|
@ -177,9 +191,7 @@ in
|
||||||
(mkToolValue "linters" cfg.setup.all.linter) ++ (mkToolValue "formatters" cfg.setup.all.formatter);
|
(mkToolValue "linters" cfg.setup.all.linter) ++ (mkToolValue "formatters" cfg.setup.all.formatter);
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.mkIf cfg.enable {
|
{
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
# TODO: print the location of the offending options
|
# TODO: print the location of the offending options
|
||||||
warnings = lib.nixvim.mkWarnings "plugins.efmls-configs" {
|
warnings = lib.nixvim.mkWarnings "plugins.efmls-configs" {
|
||||||
when = nixvimPkgs.wrong != [ ];
|
when = nixvimPkgs.wrong != [ ];
|
||||||
|
|
@ -196,20 +208,5 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
extraPackages = map (name: cfg.toolPackages.${name}) nixvimPkgs.right;
|
extraPackages = map (name: cfg.toolPackages.${name}) nixvimPkgs.right;
|
||||||
dependencies.efm-langserver.enable = lib.mkDefault true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
imports = [
|
|
||||||
{
|
|
||||||
# Propagate setup warnings
|
|
||||||
inherit (config.plugins.efmls-configs.setup) warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO: added 2025-10-23, remove after 26.05
|
|
||||||
(lib.nixvim.mkRemovedPackageOptionModule {
|
|
||||||
plugin = "efmls-configs";
|
|
||||||
oldPackageName = "efmLangServer";
|
|
||||||
packageName = "efm-langserver";
|
|
||||||
})
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue