2022-08-05 12:08:19 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
{
|
2022-09-18 11:19:23 +01:00
|
|
|
mkServer =
|
|
|
|
{ name
|
|
|
|
, sourceType
|
|
|
|
, description ? "Enable ${name} source, for null-ls."
|
2023-01-19 10:45:15 +00:00
|
|
|
, package ? null
|
|
|
|
, extraPackages ? [ ]
|
2022-09-18 11:19:23 +01:00
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
# returns a module
|
|
|
|
{ pkgs, config, lib, ... }@args:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
helpers = import ../helpers.nix args;
|
|
|
|
cfg = config.plugins.null-ls.sources.${sourceType}.${name};
|
2023-01-19 10:45:15 +00:00
|
|
|
# does this evaluate package?
|
|
|
|
packageOption = if package == null then { } else {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = package;
|
|
|
|
description = "Package to use for ${name} by null-ls";
|
|
|
|
};
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.plugins.null-ls.sources.${sourceType}.${name} = {
|
|
|
|
enable = mkEnableOption description;
|
2022-08-05 12:08:19 +00:00
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
# TODO: withArgs can exist outside of the module in a generalized manner
|
|
|
|
withArgs = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = with types; nullOr str;
|
|
|
|
description = ''Raw Lua code to be called with the with function'';
|
|
|
|
# Not sure that it makes sense to have the same example for all servers
|
|
|
|
# example = ''
|
|
|
|
# '\'{ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }'\'
|
|
|
|
# '';
|
2022-08-05 12:08:19 +00:00
|
|
|
};
|
2023-01-19 10:45:15 +00:00
|
|
|
} // packageOption;
|
2022-08-05 12:08:19 +00:00
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
config = mkIf cfg.enable {
|
2023-01-19 10:45:15 +00:00
|
|
|
# Does this evaluate package?
|
|
|
|
extraPackages = packages ++ optional (package != null) cfg.package;
|
2022-08-05 12:08:19 +00:00
|
|
|
|
2022-09-18 11:19:23 +01:00
|
|
|
# Add source to list of sources
|
|
|
|
plugins.null-ls.sourcesItems =
|
|
|
|
let
|
|
|
|
sourceItem = "${sourceType}.${name}";
|
|
|
|
withArgs = if (isNull cfg.withArgs) then sourceItem else "${sourceItem}.with ${cfg.withArgs}";
|
|
|
|
finalString = ''require("null-ls").builtins.${withArgs}'';
|
|
|
|
in
|
|
|
|
[ (helpers.mkRaw finalString) ];
|
2022-08-05 12:08:19 +00:00
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
2022-08-05 12:08:19 +00:00
|
|
|
}
|