{ pkgs, config, lib, ... }: let inherit (config.grimmShared) enable tooling; inherit (lib) mkOption types mkIf getName getExe filter optionalString concatLines ; conf_def = fmt: ( '' [formatter.${getName fmt.package}] command = "${fmt.command}" 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)) ); 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) { 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)); environment.shellAliases."treefmt" = "${getExe pkgs.treefmt} --config-file $(${getExe find_conf})"; }; options.grimmShared.tooling = { supportedLangs = mkOption { type = types.listOf (types.enum [ ]); default = [ ]; description = "Languages for which to enable support"; }; lang_servers = mkOption { 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"; }; }; } ) ); }; fmt = mkOption { default = null; type = types.nullOr ( types.submodule ( { config, ... }: { options = { package = mkOption { type = types.package; description = "FMT package"; }; options = mkOption { type = types.listOf types.nonEmptyStr; default = [ ]; }; includes = mkOption { type = types.listOf types.nonEmptyStr; default = [ ]; }; command = mkOption { type = types.nonEmptyStr; default = getExe config.package; }; }; } ) ); }; }; } ); default = { }; description = "Language servers available on the system"; }; }; }