mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 17:58:38 +02:00
Introduce `_mk-source-plugin.nix`, which returns a module handling a specific none-ls source plugin. This wasn't possible previously due to IFD conflicting with evaluating module imports. Adjusted the test to use the `options` provided via module args, and cleaned up some stuff allowing "unpackaged" sources to not be listed again in the test file.
58 lines
1.7 KiB
Nix
58 lines
1.7 KiB
Nix
# mkSourcePlugin, returns a module
|
|
sourceType: sourceName:
|
|
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
helpers,
|
|
...
|
|
}:
|
|
let
|
|
inherit (import ./packages.nix pkgs) packaged unpackaged;
|
|
|
|
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 ''
|
|
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} || lib.elem sourceName unpackaged) {
|
|
package =
|
|
let
|
|
pkg = packaged.${sourceName} or null;
|
|
in
|
|
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) ];
|
|
};
|
|
}
|