-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugins/none-ls: refactor using mkSourcePlugin
#1853
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# mkSourcePlugin, returns a module | ||
sourceType: sourceName: | ||
{ | ||
config, | ||
pkgs, | ||
lib, | ||
helpers, | ||
... | ||
}: | ||
let | ||
inherit (import ./packages.nix pkgs) packaged; | ||
pkg = packaged.${sourceName}; | ||
|
||
cfg = config.plugins.none-ls; | ||
cfg' = config.plugins.none-ls.sources.${sourceType}.${sourceName}; | ||
in | ||
{ | ||
options.plugins.none-ls.sources.${sourceType}.${sourceName} = | ||
{ | ||
enable = lib.mkEnableOption "the ${sourceName} ${sourceType} source for none-ls"; | ||
withArgs = helpers.mkNullOrOption helpers.nixvimTypes.strLua '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be straighforward (in another PR) to have structured options here no? We'd need some kind of coercion from string to rawLua though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. #1705 is tracking the idea. |
||
Raw Lua code passed as an argument to the source's `with` method. | ||
''; | ||
} | ||
# Only declare a package option if a package is required | ||
// lib.optionalAttrs (packaged ? ${sourceName}) { | ||
package = lib.mkOption ( | ||
{ | ||
type = lib.types.nullOr lib.types.package; | ||
description = | ||
"Package to use for ${sourceName}." | ||
+ (lib.optionalString (pkg == null) ( | ||
"\n\n" | ||
+ '' | ||
Currently not packaged in nixpkgs. | ||
Either set this to `null` and install ${sourceName} outside of nix, | ||
or set this to a custom nix package. | ||
'' | ||
)); | ||
} | ||
// lib.optionalAttrs (pkg != null) { default = pkg; } | ||
); | ||
}; | ||
|
||
config = lib.mkIf (cfg.enable && cfg'.enable) { | ||
plugins.none-ls.settings.sources = lib.mkDefault [ | ||
( | ||
"require('null-ls').builtins.${sourceType}.${sourceName}" | ||
+ lib.optionalString (cfg'.withArgs != null) ".with(${cfg'.withArgs})" | ||
) | ||
]; | ||
|
||
extraPackages = [ (cfg'.package or null) ]; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lazy evaluation is nice :D