fmt support

This commit is contained in:
Grimmauld 2024-05-15 23:24:35 +02:00
parent 7b2265b906
commit a791b41455
Signed by: Grimmauld
GPG Key ID: C2946668769F91FB
5 changed files with 123 additions and 42 deletions

View File

@ -12,18 +12,46 @@ let
mkIf mkIf
getName getName
mkEnableOption mkEnableOption
getExe
filter filter
optionalString
concatLines
; ;
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))
);
in in
{ {
config = mkIf (enable && tooling.enable) { config = mkIf (enable && tooling.enable) {
environment.systemPackages = map (v: v.package) tooling.lang_servers; environment.systemPackages =
[
pkgs.treefmt
pkgs.findup
pkgs.gnused
]
++ (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 ${treefmt_conf}";
grimmShared.tooling.nvim.extraLuaRC = grimmShared.tooling.nvim.extraLuaRC =
[ "vim.g.coq_settings = { auto_start = 'shut-up' }" ] [ "vim.g.coq_settings = { auto_start = 'shut-up' }" ]
++ (map ( ++ (map (
v: "require'lspconfig'.${v.name}.setup(require('coq').lsp_ensure_capabilities(${v.config}))" v:
) (filter (v: v.vimIntegration) tooling.lang_servers)); "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; [ grimmShared.tooling.nvim.plugins = with pkgs.vimPlugins; [
nvim-lspconfig nvim-lspconfig
@ -34,33 +62,73 @@ in
options.grimmShared.tooling.lang_servers = mkOption { options.grimmShared.tooling.lang_servers = mkOption {
type = types.listOf ( type = types.listOf (
types.submodule ( types.submodule {
{ config, ... }: options = {
{ lsp = mkOption {
options = { type = types.nullOr (
name = mkOption { types.submodule (
type = types.nullOr types.nonEmptyStr; { config, ... }:
default = getName config.package; {
description = "lspconfig module name"; options = {
}; lspconf_mod_name = mkOption {
type = types.nullOr types.nonEmptyStr;
default = getName config.package;
description = "lspconfig module name";
};
config = mkOption { lspconf_config = mkOption {
type = types.nonEmptyStr; type = types.nonEmptyStr;
default = "{}"; default = "{}";
description = "options to pass to lspconfig"; description = "options to pass to lspconfig";
}; };
vimIntegration = mkEnableOption "Enable coq/nvim-lspconfig integration" // { package = mkOption {
default = true; type = types.package;
}; default = null;
description = "LSP package";
};
package = mkOption { vimIntegration = mkEnableOption "Enable coq/nvim-lspconfig integration" // {
type = types.package; default = true;
description = "LSP package"; };
}; };
}
)
);
}; };
}
) fmt = mkOption {
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 = { }; default = { };
description = "Language servers available on the system"; description = "Language servers available on the system";

View File

@ -6,7 +6,6 @@
(writeShellScriptBin "rebuild" "bash -c \"nixos-rebuild switch |& nom\"") (writeShellScriptBin "rebuild" "bash -c \"nixos-rebuild switch |& nom\"")
nixpkgs-review nixpkgs-review
nixpkgs-fmt
nixfmt-rfc-style nixfmt-rfc-style
nixd nixd
nixpkgs-hammering nixpkgs-hammering
@ -22,7 +21,15 @@
plugins = with pkgs.vimPlugins; [ vim-nix ]; plugins = with pkgs.vimPlugins; [ vim-nix ];
}; };
grimmShared.tooling.lang_servers = [ { package = pkgs.nixd; } ]; grimmShared.tooling.lang_servers = [
{
lsp.package = pkgs.nixd;
fmt = {
package = pkgs.nixpkgs-fmt;
includes = [ "*.nix" ];
};
}
];
nix.settings = { nix.settings = {
experimental-features = [ experimental-features = [

View File

@ -18,7 +18,6 @@ in
config = mkIf (enable && tooling.enable) { config = mkIf (enable && tooling.enable) {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
dos2unix dos2unix
treefmt
neovim-remote neovim-remote
]; ];

View File

@ -19,22 +19,27 @@ in
config = lib.mkIf (enable && tooling.enable) { config = lib.mkIf (enable && tooling.enable) {
environment.systemPackages = [ environment.systemPackages = [
(pkgs.python3.withPackages pyLibs) (pkgs.python3.withPackages pyLibs)
pkgs.yapf
pkgs.pyright
] ++ lib.optionals graphical (with pkgs; [ jetbrains.pycharm-community ]); ] ++ lib.optionals graphical (with pkgs; [ jetbrains.pycharm-community ]);
programs.xonsh = { programs.xonsh = {
enable = true; enable = true;
config = lib.concatLines ( config = lib.concatLines (
lib.mapAttrsToList ( lib.mapAttrsToList (
name: value: ''aliases["${name}"] = "${value}"'' name: value: "aliases[\"${name}\"] = '''${value}'''"
) config.environment.shellAliases ) config.environment.shellAliases
); );
package = pkgs.xonsh.wrapper.override { extraPackages = pyLibs; }; package = pkgs.xonsh.wrapper.override { extraPackages = pyLibs; };
}; };
grimmShared.tooling.nvim.extraLuaRC = lib.singleton '' grimmShared.tooling.lang_servers = [
require'lspconfig'.pyright.setup{} {
''; lsp.package = pkgs.pyright;
fmt = {
package = pkgs.yapf;
includes = [ "*.py" ];
options = [ "-i" ];
};
}
];
}; };
} }

View File

@ -11,16 +11,18 @@ in
config = lib.mkIf (enable && tooling.enable) { config = lib.mkIf (enable && tooling.enable) {
environment.systemPackages = environment.systemPackages =
with pkgs; with pkgs;
[ [ pkg-config ] ++ lib.optionals graphical [ jetbrains.clion ];
rustfmt
pkg-config
]
++ lib.optionals graphical [ jetbrains.clion ];
grimmShared.tooling.lang_servers = [ grimmShared.tooling.lang_servers = [
{ {
package = pkgs.rust-analyzer; lsp = {
name = "rust_analyzer"; package = pkgs.rust-analyzer;
lspconf_mod_name = "rust_analyzer";
};
fmt = {
package = pkgs.rustfmt;
includes = [ "*.rs" ];
};
} }
]; ];
}; };