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

114 lines
3.0 KiB
Nix
Raw Permalink Normal View History

{
pkgs,
config,
lib,
...
}:
let
inherit (config.grimmShared) enable tooling;
inherit (lib)
mkOption
types
mkIf
getName
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}]
2024-05-18 16:41:17 +02:00
command = "${fmt.command}"
2024-05-15 23:24:35 +02:00
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 =
2024-05-17 12:18:20 +02:00
[ pkgs.treefmt ]
2024-05-15 23:24:35 +02:00
++ (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 $(${getExe find_conf})";
};
2024-05-30 22:12:15 +02:00
options.grimmShared.tooling = {
supportedLangs = mkOption {
type = types.listOf (types.enum [ ]);
default = [ ];
description = "Languages for which to enable support";
};
lang_servers = mkOption {
2024-05-15 23:24:35 +02:00
2024-05-30 22:12:15 +02:00
type = types.listOf (
types.submodule {
options = {
lsp = mkOption {
type = types.nullOr (
types.submodule (
{ config, ... }:
{
options = {
package = mkOption {
type = types.package;
default = null;
description = "LSP package";
};
2024-05-15 23:24:35 +02:00
};
2024-05-30 22:12:15 +02:00
}
)
);
};
2024-05-15 23:24:35 +02:00
2024-05-30 22:12:15 +02:00
fmt = mkOption {
default = null;
type = types.nullOr (
types.submodule (
{ config, ... }:
{
options = {
package = mkOption {
type = types.package;
description = "FMT package";
};
2024-05-30 22:12:15 +02:00
options = mkOption {
type = types.listOf types.nonEmptyStr;
default = [ ];
};
2024-05-30 22:12:15 +02:00
includes = mkOption {
type = types.listOf types.nonEmptyStr;
default = [ ];
};
2024-05-30 22:12:15 +02:00
command = mkOption {
type = types.nonEmptyStr;
default = getExe config.package;
};
2024-05-15 23:24:35 +02:00
};
2024-05-30 22:12:15 +02:00
}
)
);
};
};
2024-05-30 22:12:15 +02:00
}
);
default = { };
description = "Language servers available on the system";
};
};
}