Added workaround for nil configuration

This commit is contained in:
Liyua 2025-07-01 20:02:26 +02:00
commit 3fa41b6d8b
No known key found for this signature in database
GPG key ID: AFF37010586DE14D

View file

@ -4,7 +4,8 @@
lib,
inputs,
...
}: let
}:
let
inherit (builtins) attrNames;
inherit (lib) concatStringsSep;
inherit (lib.meta) getExe;
@ -12,7 +13,16 @@
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.strings) optionalString;
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.lua) expToLua toLuaObject;
@ -22,10 +32,9 @@
noFormat = "on_attach = attach_keymaps";
defaultServer = "nil";
packageToCmd = package: defaultCmd:
if isList package
then expToLua package
else ''{"${package}/bin/${defaultCmd}"}'';
packageToCmd =
package: defaultCmd:
if isList package then expToLua package else ''{"${package}/bin/${defaultCmd}"}'';
servers = {
nil = {
package = inputs.nil.packages.${pkgs.stdenv.system}.nil;
@ -33,27 +42,22 @@
lspConfig = ''
lspconfig.nil_ls.setup{
capabilities = capabilities,
${
if cfg.format.enable
then useFormat
else noFormat
},
${if cfg.format.enable then useFormat else noFormat},
cmd = ${packageToCmd cfg.lsp.package "nil"},
${optionalString cfg.format.enable ''
settings = {
["nil"] = {
${optionalString (cfg.format.type == "alejandra")
''
formatting = {
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
},
''}
${optionalString (cfg.format.type == "nixfmt")
''
formatting = {
command = {"${cfg.format.package}/bin/nixfmt"},
},
''}
${optionalString (cfg.format.type == "alejandra") ''
formatting = {
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
},
''}
${optionalString (cfg.format.type == "nixfmt") ''
formatting = {
command = {"${cfg.format.package}/bin/nixfmt"},
},
''}
nix = ${toLuaObject cfg.lsp.options},
},
},
''}
@ -67,28 +71,22 @@
lspConfig = ''
lspconfig.nixd.setup{
capabilities = capabilities,
${
if cfg.format.enable
then useFormat
else noFormat
},
${if cfg.format.enable then useFormat else noFormat},
cmd = ${packageToCmd cfg.lsp.package "nixd"},
${optionalString cfg.format.enable ''
settings = {
nixd = {
${optionalString (cfg.format.type == "alejandra")
''
formatting = {
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
},
''}
${optionalString (cfg.format.type == "nixfmt")
''
formatting = {
command = {"${cfg.format.package}/bin/nixfmt"},
},
''}
options = ${toLuaObject cfg.lsp.options},
${optionalString (cfg.format.type == "alejandra") ''
formatting = {
command = {"${cfg.format.package}/bin/alejandra", "--quiet"},
},
''}
${optionalString (cfg.format.type == "nixfmt") ''
formatting = {
command = {"${cfg.format.package}/bin/nixfmt"},
},
''}
nix = ${toLuaObject cfg.lsp.options},
},
},
''}
@ -108,7 +106,10 @@
};
};
defaultDiagnosticsProvider = ["statix" "deadnix"];
defaultDiagnosticsProvider = [
"statix"
"deadnix"
];
diagnosticsProviders = {
statix = {
package = pkgs.statix;
@ -134,17 +135,22 @@
'';
};
};
in {
in
{
options.vim.languages.nix = {
enable = mkEnableOption "Nix language support";
treesitter = {
enable = mkEnableOption "Nix treesitter" // {default = config.vim.languages.enableTreesitter;};
enable = mkEnableOption "Nix treesitter" // {
default = config.vim.languages.enableTreesitter;
};
package = mkGrammarOption pkgs "nix";
};
lsp = {
enable = mkEnableOption "Nix LSP support" // {default = config.vim.lsp.enable;};
enable = mkEnableOption "Nix LSP support" // {
default = config.vim.lsp.enable;
};
server = mkOption {
description = "Nix LSP server to use";
type = enum (attrNames servers);
@ -166,7 +172,9 @@ in {
};
format = {
enable = mkEnableOption "Nix formatting" // {default = config.vim.languages.enableFormat;};
enable = mkEnableOption "Nix formatting" // {
default = config.vim.languages.enableFormat;
};
type = mkOption {
description = "Nix formatter to use";
@ -182,7 +190,9 @@ in {
};
extraDiagnostics = {
enable = mkEnableOption "extra Nix diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
enable = mkEnableOption "extra Nix diagnostics" // {
default = config.vim.languages.enableExtraDiagnostics;
};
types = diagnostics {
langDesc = "Nix";
@ -214,7 +224,7 @@ in {
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
vim.treesitter.grammars = [ cfg.treesitter.package ];
})
(mkIf cfg.lsp.enable {
@ -225,7 +235,7 @@ in {
(mkIf (cfg.format.enable && (!cfg.lsp.enable || !servers.${cfg.lsp.server}.internalFormatter)) {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.nix = [cfg.format.type];
setupOpts.formatters_by_ft.nix = [ cfg.format.type ];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
@ -236,10 +246,11 @@ in {
vim.diagnostics.nvim-lint = {
enable = true;
linters_by_ft.nix = cfg.extraDiagnostics.types;
linters = mkMerge (map (name: {
linters = mkMerge (
map (name: {
${name}.cmd = getExe diagnosticsProviders.${name}.package;
})
cfg.extraDiagnostics.types);
}) cfg.extraDiagnostics.types
);
};
})
]);