feat: make nix lsp install optional

This commit is contained in:
Ching Pei Yang 2023-09-11 15:19:55 +02:00
parent b1184bab47
commit 2f0efdbf15

View file

@ -12,6 +12,10 @@ with builtins; let
noFormat = "on_attach = attach_keymaps"; noFormat = "on_attach = attach_keymaps";
defaultServer = "nil"; defaultServer = "nil";
packageToCmd = package: defaultCmd:
if isList package
then lib.nvim.lua.expToLua package
else ''{"${package}/bin/${defaultCmd}"}'';
servers = { servers = {
rnix = { rnix = {
package = pkgs.rnix-lsp; package = pkgs.rnix-lsp;
@ -24,7 +28,7 @@ with builtins; let
then useFormat then useFormat
else noFormat else noFormat
}, },
cmd = {"${cfg.lsp.package}/bin/rnix-lsp"}, cmd = ${packageToCmd cfg.lsp.package "rnix-lsp"},
} }
''; '';
}; };
@ -40,7 +44,7 @@ with builtins; let
then useFormat then useFormat
else noFormat else noFormat
}, },
cmd = {"${cfg.lsp.package}/bin/nil"}, cmd = ${packageToCmd cfg.lsp.package "nil"},
${optionalString cfg.format.enable '' ${optionalString cfg.format.enable ''
settings = { settings = {
["nil"] = { ["nil"] = {
@ -131,7 +135,7 @@ in {
}; };
package = mkOption { package = mkOption {
description = "Nix LSP server package"; description = "Nix LSP server package";
type = types.package; type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };