grimm-nixos-laptop/common/tooling/lsp.nix

138 lines
3.9 KiB
Nix
Raw Normal View History

{
pkgs,
config,
lib,
...
}:
let
inherit (config.grimmShared) enable tooling;
inherit (lib)
mkOption
types
mkIf
getName
mkEnableOption
2024-05-15 23:24:35 +02:00
getExe
filter
2024-05-15 23:24:35 +02:00
optionalString
concatLines
;
2024-05-15 23:24:35 +02:00
conf_def =
fmt:
(
''
[formatter.${getName fmt.package}]
command = "${getExe fmt.package}"
includes = ${builtins.toJSON fmt.includes}
''
+ (optionalString (fmt.options != [ ]) "options = ${builtins.toJSON fmt.options}\n")
);
treefmt_conf = pkgs.writeText "treefmt.toml" (
concatLines (map (v: (conf_def v.fmt)) (filter (v: !isNull v.fmt) tooling.lang_servers))
);
2024-05-16 11:59:05 +02:00
find_conf = pkgs.writeShellScriptBin "find-treefmt-conf" "(${getExe pkgs.rfindup} treefmt.toml -e 2>/dev/null || echo ${treefmt_conf}) | tr -d '\n'";
in
{
config = mkIf (enable && tooling.enable) {
2024-05-15 23:24:35 +02:00
environment.systemPackages =
[
pkgs.treefmt
]
++ (map (v: v.lsp.package) (filter (v: !isNull v.lsp) tooling.lang_servers))
++ (map (v: v.fmt.package) (filter (v: !isNull v.fmt) tooling.lang_servers));
2024-05-16 11:59:05 +02:00
# environment.shellAliases."treefmt" = "${getExe pkgs.treefmt} --config-file ${treefmt_conf}";
environment.shellAliases."treefmt" = "${getExe pkgs.treefmt} --config-file $(${getExe find_conf})";
grimmShared.tooling.nvim.extraLuaRC =
[ "vim.g.coq_settings = { auto_start = 'shut-up' }" ]
++ (map (
2024-05-15 23:24:35 +02:00
v:
"require'lspconfig'.${v.lsp.lspconf_mod_name}.setup(require('coq').lsp_ensure_capabilities(${v.lsp.lspconf_config}))"
) (filter (v: !isNull v.lsp && v.lsp.vimIntegration) tooling.lang_servers));
grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [
nvim-lspconfig
coq_nvim
coq-artifacts
];
};
options.grimmShared.tooling.lang_servers = mkOption {
type = types.listOf (
2024-05-15 23:24:35 +02:00
types.submodule {
options = {
lsp = mkOption {
type = types.nullOr (
types.submodule (
{ config, ... }:
{
options = {
lspconf_mod_name = mkOption {
type = types.nullOr types.nonEmptyStr;
default = getName config.package;
description = "lspconfig module name";
};
lspconf_config = mkOption {
type = types.nonEmptyStr;
default = "{}";
description = "options to pass to lspconfig";
};
package = mkOption {
type = types.package;
default = null;
description = "LSP package";
};
vimIntegration = mkEnableOption "Enable coq/nvim-lspconfig integration" // {
default = true;
};
};
}
)
);
};
fmt = mkOption {
type = types.nullOr (
types.submodule (
{ config, ... }:
{
options = {
package = mkOption {
type = types.package;
description = "FMT package";
};
2024-05-15 23:24:35 +02:00
options = mkOption {
type = types.listOf types.nonEmptyStr;
default = [ ];
};
2024-05-15 23:24:35 +02:00
includes = mkOption {
type = types.listOf types.nonEmptyStr;
default = [ ];
};
2024-05-15 23:24:35 +02:00
command = mkOption {
type = types.nonEmptyStr;
default = getExe config.package;
};
};
}
)
);
};
2024-05-15 23:24:35 +02:00
};
}
);
default = { };
description = "Language servers available on the system";
};
}