claude-code: add lsp servers support

This commit is contained in:
natsukium
2026-03-17 23:52:47 -05:00
committed by Austin Horstman
parent f0e123a7e2
commit a455ac1bb3
5 changed files with 86 additions and 3 deletions
+44 -2
View File
@@ -364,6 +364,33 @@ in
example = lib.literalExpression "./skills";
};
lspServers = lib.mkOption {
type = lib.types.attrsOf jsonFormat.type;
default = { };
description = ''
LSP (Language Server Protocol) servers configuration.
'';
example = {
go = {
command = "gopls";
args = [ "serve" ];
extensionToLanguage = {
".go" = "go";
};
};
typescript = {
command = "typescript-language-server";
args = [ "--stdio" ];
extensionToLanguage = {
".ts" = "typescript";
".tsx" = "typescriptreact";
".js" = "javascript";
".jsx" = "javascriptreact";
};
};
};
};
mcpServers = lib.mkOption {
type = lib.types.attrsOf jsonFormat.type;
default = { };
@@ -408,8 +435,10 @@ in
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = (cfg.mcpServers == { } && !cfg.enableMcpIntegration) || cfg.package != null;
message = "`programs.claude-code.package` cannot be null when `mcpServers` or `enableMcpIntegration` is configured";
assertion =
(cfg.mcpServers == { } && cfg.lspServers == { } && !cfg.enableMcpIntegration)
|| cfg.package != null;
message = "`programs.claude-code.package` cannot be null when `mcpServers`, `lspServers`, or `enableMcpIntegration` is configured";
}
{
assertion = !(cfg.memory.text != null && cfg.memory.source != null);
@@ -448,6 +477,19 @@ in
jsonFormat.generate "claude-code-mcp-config.json" { mcpServers = mergedMcpServers; }
}"
])
(lib.optional (cfg.lspServers != { }) [
"--append-flags"
"--plugin-dir ${
pkgs.runCommand "claude-code-lsp-plugin" { } ''
install -Dm644 ${
jsonFormat.generate "claude-code-lsp-plugin.json" {
name = "claude-code-lsp";
lspServers = cfg.lspServers;
}
} $out/.claude-plugin/plugin.json
''
}"
])
]
);
@@ -47,7 +47,7 @@
};
test.asserts.assertions.expected = [
"`programs.claude-code.package` cannot be null when `mcpServers` or `enableMcpIntegration` is configured"
"`programs.claude-code.package` cannot be null when `mcpServers`, `lspServers`, or `enableMcpIntegration` is configured"
"Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`"
"Cannot specify both `programs.claude-code.agents` and `programs.claude-code.agentsDir`"
"Cannot specify both `programs.claude-code.commands` and `programs.claude-code.commandsDir`"
@@ -1,6 +1,7 @@
{
claude-code-basic = ./basic.nix;
claude-code-full-config = ./full-config.nix;
claude-code-lsp = ./lsp.nix;
claude-code-mcp = ./mcp.nix;
claude-code-mcp-integration = ./mcp-integration.nix;
claude-code-assertion = ./assertion.nix;
@@ -0,0 +1,2 @@
#! /nix/store/00000000000000000000000000000000-bash/bin/bash -e
exec -a "$0" "/nix/store/00000000000000000000000000000000-claude-code/bin/.claude-wrapped" "$@" --plugin-dir /nix/store/00000000000000000000000000000000-claude-code-lsp-plugin
@@ -0,0 +1,38 @@
{ config, ... }:
{
programs.claude-code = {
package = config.lib.test.mkStubPackage {
name = "claude-code";
buildScript = ''
mkdir -p $out/bin
touch $out/bin/claude
chmod 755 $out/bin/claude
'';
};
enable = true;
lspServers = {
go = {
command = "gopls";
args = [ "serve" ];
extensionToLanguage = {
".go" = "go";
};
};
typescript = {
command = "typescript-language-server";
args = [ "--stdio" ];
extensionToLanguage = {
".ts" = "typescript";
".tsx" = "typescriptreact";
};
};
};
};
nmt.script = ''
normalizedWrapper=$(normalizeStorePaths home-path/bin/claude)
assertFileContent $normalizedWrapper ${./expected-lsp-wrapper}
'';
}