nix: migrate to conform/nvim-lint

This commit is contained in:
Ching Pei Yang 2025-03-27 16:32:58 +01:00
parent 7e1ffe40f5
commit 2bc0492af3
No known key found for this signature in database
GPG key ID: B3841364253DC4C8

View file

@ -6,6 +6,7 @@
}: let }: let
inherit (builtins) attrNames; inherit (builtins) attrNames;
inherit (lib) concatStringsSep; inherit (lib) concatStringsSep;
inherit (lib.meta) getExe;
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList; inherit (lib.lists) isList;
@ -13,7 +14,6 @@
inherit (lib.types) anything attrsOf enum either listOf nullOr package str; inherit (lib.types) anything attrsOf enum either listOf nullOr package str;
inherit (lib.nvim.types) mkGrammarOption diagnostics; inherit (lib.nvim.types) mkGrammarOption diagnostics;
inherit (lib.nvim.lua) expToLua toLuaObject; inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.languages) diagnosticsToLua;
cfg = config.vim.languages.nix; cfg = config.vim.languages.nix;
@ -100,26 +100,10 @@
formats = { formats = {
alejandra = { alejandra = {
package = pkgs.alejandra; package = pkgs.alejandra;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.alejandra.with({
command = "${cfg.format.package}/bin/alejandra"
})
)
'';
}; };
nixfmt = { nixfmt = {
package = pkgs.nixfmt-rfc-style; package = pkgs.nixfmt-rfc-style;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.nixfmt.with({
command = "${cfg.format.package}/bin/nixfmt"
})
)
'';
}; };
}; };
@ -237,17 +221,24 @@ in {
vim.lsp.lspconfig.sources.nix-lsp = servers.${cfg.lsp.server}.lspConfig; vim.lsp.lspconfig.sources.nix-lsp = servers.${cfg.lsp.server}.lspConfig;
}) })
(mkIf (cfg.format.enable && !servers.${cfg.lsp.server}.internalFormatter) { (mkIf (cfg.format.enable && (!cfg.lsp.enable || !servers.${cfg.lsp.server}.internalFormatter)) {
vim.lsp.null-ls.enable = true; vim.formatter.conform-nvim = {
vim.lsp.null-ls.sources.nix-format = formats.${cfg.format.type}.nullConfig; enable = true;
setupOpts.formatters_by_ft.nix = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
};
}) })
(mkIf cfg.extraDiagnostics.enable { (mkIf cfg.extraDiagnostics.enable {
vim.lsp.null-ls.enable = true; vim.diagnostics.nvim-lint = {
vim.lsp.null-ls.sources = diagnosticsToLua { enable = true;
lang = "nix"; linters_by_ft.nix = cfg.extraDiagnostics.types;
config = cfg.extraDiagnostics.types; linters = mkMerge (map (name: {
inherit diagnosticsProviders; ${name}.cmd = getExe diagnosticsProviders.${name}.package;
})
cfg.extraDiagnostics.types);
}; };
}) })
]); ]);