Skip to content

Commit 266db54

Browse files
authored
feat(wrapperModules.claude-code): init (#181)
1 parent 346f573 commit 266db54

File tree

4 files changed

+124
-2
lines changed

4 files changed

+124
-2
lines changed

flake.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
if inputs.pkgs.stdenv.hostPlatform.system or null == system then
1010
inputs.pkgs
1111
else if inputs.nixpkgs.legacyPackages.${system} or null != null then
12-
inputs.nixpkgs.legacyPackages.${system}
12+
import inputs.nixpkgs {
13+
inherit system;
14+
config.allowUnfree = true;
15+
}
1316
else
14-
import (inputs.pkgs.path or inputs.nixpkgs or <nixpkgs>) { inherit system; };
17+
import (inputs.pkgs.path or inputs.nixpkgs or <nixpkgs>) {
18+
inherit system;
19+
config.allowUnfree = true;
20+
};
1521
lib = inputs.pkgs.lib or inputs.nixpkgs.lib or (import "${inputs.nixpkgs or <nixpkgs>}/lib");
1622
forAllSystems = lib.genAttrs lib.platforms.all;
1723
in

maintainers/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
github = "rencire";
1212
githubId = 546296;
1313
};
14+
vinnymeller = {
15+
name = "Vinny Meller";
16+
github = "vinnymeller";
17+
githubId = 19894025;
18+
};
1419
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
pkgs,
3+
self,
4+
}:
5+
let
6+
claudeCodeWrapped = self.wrappedModules.claude-code.wrap {
7+
inherit pkgs;
8+
9+
mcpConfig = {
10+
nixos = {
11+
command = "${pkgs.mcp-nixos}/bin/mcp-nixos";
12+
type = "stdio";
13+
};
14+
};
15+
strictMcpConfig = true;
16+
};
17+
in
18+
pkgs.runCommand "claude-code-test" { } ''
19+
"${claudeCodeWrapped}/bin/claude" mcp get nixos
20+
touch $out
21+
''
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
config,
3+
lib,
4+
wlib,
5+
pkgs,
6+
...
7+
}:
8+
let
9+
jsonFmt = pkgs.formats.json { };
10+
in
11+
{
12+
imports = [ wlib.modules.default ];
13+
14+
options = {
15+
16+
settings = lib.mkOption {
17+
type = jsonFmt.type;
18+
default = { };
19+
description = ''
20+
Claude Code settings
21+
22+
These settings will override local, project, and user scoped settings.
23+
24+
See <https://code.claude.com/docs/en/settings>
25+
'';
26+
example = {
27+
includeCoAuthoredBy = false;
28+
permissions = {
29+
deny = [
30+
"Bash(sudo:*)"
31+
"Bash(rm -rf:*)"
32+
];
33+
};
34+
};
35+
};
36+
37+
mcpConfig = lib.mkOption {
38+
type = lib.jsonFmt.type;
39+
default = { };
40+
description = ''
41+
MCP Server configuration
42+
43+
Exclude the top-level `mcpServers` key from the configuration as it is automatically handled.
44+
45+
See <https://code.claude.com/docs/en/mcp>
46+
'';
47+
example = {
48+
nixos = {
49+
command = "${pkgs.mcp-nixos}/bin/mcp-nixos";
50+
type = "stdio";
51+
};
52+
};
53+
};
54+
55+
strictMcpConfig = lib.mkOption {
56+
type = lib.types.bool;
57+
default = false;
58+
description = ''
59+
Whether to enable the `--strict-mcp-config` flag for Claude Code.
60+
61+
When enabled, Claude will only use the MCP servers provided by the `mcpConfig` option.
62+
63+
If disabled, Claude may use MCP servers defined elsewhere (e.g., user or project scoped configurations).
64+
'';
65+
};
66+
67+
};
68+
69+
config = {
70+
package = lib.mkDefault pkgs.claude-code;
71+
unsetVar = lib.mkDefault [
72+
"DEV"
73+
# the vast majority of users will want to authenticate with their claude account and not an API key
74+
"ANTHROPIC_API_KEY"
75+
];
76+
envDefault = lib.mkDefault {
77+
DISABLE_AUTOUPDATER = "1";
78+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1";
79+
DISABLE_NON_ESSENTIAL_MODEL_CALLS = "1";
80+
DISABLE_TELEMETRY = "1";
81+
DISABLE_INSTALLATION_CHECKS = "1";
82+
};
83+
flags = {
84+
"--mcp-config" = jsonFmt.generate "claude-mcp-config.json" { mcpServers = config.settings; };
85+
"--strict-mcp-config" = config.strictMcpConfig;
86+
"--settings" = jsonFmt.generate "claude-settings.json" config.settings;
87+
};
88+
meta.maintainers = [ wlib.maintainers.vinnymeller ];
89+
};
90+
}

0 commit comments

Comments
 (0)