plugins/efmls: minor cleanup

This commit is contained in:
Matt Sturgeon 2024-09-04 14:04:40 +01:00
parent 35788bbc5a
commit 2ef974182e
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -7,12 +7,7 @@
}: }:
let let
tools = import ../../../generated/efmls-configs.nix; tools = import ../../../generated/efmls-configs.nix;
packagingStatus = import ./efmls-configs-pkgs.nix pkgs; inherit (import ./efmls-configs-pkgs.nix pkgs) packaged;
# Filter packages that are not compatible with the current platform
toolPkgs = lib.filterAttrs (
a: pkg: lib.meta.availableOn pkgs.stdenv.hostPlatform pkg
) packagingStatus.packaged;
in in
{ {
options.plugins.efmls-configs = { options.plugins.efmls-configs = {
@ -28,13 +23,24 @@ in
default = [ ]; default = [ ];
}; };
toolPackages = lib.attrsets.mapAttrs ( toolPackages = lib.pipe packaged [
tool: pkg: # Produce package a option for each tool
helpers.mkPackageOption { (lib.attrsets.mapAttrs (
name = tool; tool: pkg:
default = pkg; helpers.mkPackageOption {
} name = tool;
) toolPkgs; default = pkg;
}
))
# Filter package defaults that are not compatible with the current platform
(lib.attrsets.mapAttrs (
_: opt:
if lib.meta.availableOn pkgs.stdenv.hostPlatform opt.default then
opt
else
opt // { default = null; }
))
];
/* /*
Users can set the options as follows: Users can set the options as follows:
@ -54,7 +60,7 @@ in
freeformType = lib.types.attrsOf lib.types.anything; freeformType = lib.types.attrsOf lib.types.anything;
options = lib.mapAttrs ( options = lib.mapAttrs (
_: value: _:
lib.mapAttrs ( lib.mapAttrs (
kind: kind:
{ lang, possible }: { lang, possible }:
@ -66,7 +72,7 @@ in
default = [ ]; default = [ ];
description = "${kind} tools for ${lang}"; description = "${kind} tools for ${lang}";
} }
) value )
) tools; ) tools;
}; };
description = "Configuration for each filetype. Use `all` to match any filetype."; description = "Configuration for each filetype. Use `all` to match any filetype.";
@ -80,15 +86,13 @@ in
# 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 (
lib.concatLists ( lib.concatMap (
map ( {
{ linter ? [ ],
linter ? [ ], formatter ? [ ],
formatter ? [ ], }:
}: (lib.toList linter) ++ (lib.toList formatter)
(lib.toList linter) ++ (lib.toList formatter) ) (lib.attrValues cfg.setup)
) (lib.attrValues cfg.setup)
)
) )
); );
@ -132,9 +136,9 @@ in
extraPlugins = [ cfg.package ]; extraPlugins = [ cfg.package ];
# TODO: print the location of the offending options # TODO: print the location of the offending options
warnings = lib.optional ((lib.length nixvimPkgs.wrong) > 0) '' warnings = lib.optional (nixvimPkgs.wrong != [ ]) ''
Nixvim (plugins.efmls-configs): Following tools are not handled by nixvim, please add them to externallyManagedPackages to silence this: Nixvim (plugins.efmls-configs): Following tools are not handled by nixvim, please add them to `externallyManagedPackages` to silence this:
${lib.concatStringsSep " " nixvimPkgs.wrong} ${lib.concatMapStringsSep "\n" (tool: " - ${tool}") nixvimPkgs.wrong}
''; '';
plugins.lsp.servers.efm = { plugins.lsp.servers.efm = {