Skip to content

Commit 61515c0

Browse files
gui-wfclaude
andcommitted
fix: Use buildNpmPackage for proper Nix flake builds
- Switch from stdenv.mkDerivation to buildNpmPackage - Add npmDepsHash for reproducible dependency fetching - Fix npm dependency installation in Nix sandbox - Update executable path to purelymail-mcp-server - Enable nix run github:gui-wf/purelymail-mcp-server This fixes the hanging build issue caused by npm ci trying to access the network in Nix's sandboxed build environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ee6298a commit 61515c0

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
.env
77

88
output
9+
result

.mcp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"mcpServers": {
33
"purelymail": {
4-
"command": "npx",
5-
"args": ["-y", "purelymail-mcp-server"],
4+
"command": "nix",
5+
"args": ["run", "github:gui-wf/purelymail-mcp-server"],
66
"env": {
77
"PURELYMAIL_API_KEY": "${PURELYMAIL_API_KEY}",
88
"MOCK_MODE": "false"

flake.nix

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,46 +67,42 @@
6767
'';
6868

6969
# Production package build
70-
packages.default = pkgs.stdenv.mkDerivation {
70+
packages.default = pkgs.buildNpmPackage {
7171
pname = "purelymail-mcp-server";
72-
# AIDEV-TODO: Make version update dynamic and based on whats defined in package.json - to not have to edit many files
7372
version = "2.0.0-rc2";
7473
src = ./.;
7574

76-
buildInputs = [ pkgs.nodejs_20 ];
75+
npmDepsHash = "sha256-aUS8yO2xscDjJZf6KjVzCnEA4ZxawVH5gxlTZUyuO0g=";
7776

78-
buildPhase = ''
79-
# Install dependencies (production only)
80-
npm ci --omit=dev
81-
82-
# Generate types if spec exists (no network calls during build)
77+
# Generate types before building
78+
preBuild = ''
8379
if [ -f purelymail-api-spec.json ]; then
8480
npm run generate:types
85-
else
86-
echo "Warning: purelymail-api-spec.json not found"
87-
echo "Run 'nix run .#update-api' to fetch latest spec"
8881
fi
89-
90-
# Build using package.json script
91-
npm run build
9282
'';
9383

84+
# buildNpmPackage automatically runs: npm run build
85+
9486
installPhase = ''
95-
mkdir -p $out/{bin,share/purelymail-mcp}
87+
runHook preInstall
9688
97-
# Copy built artifacts
98-
cp -r dist $out/share/purelymail-mcp/
99-
cp -r src/types $out/share/purelymail-mcp/
100-
cp -r src/mocks $out/share/purelymail-mcp/
101-
cp package.json $out/share/purelymail-mcp/
102-
cp purelymail-api-spec.json $out/share/purelymail-mcp/ 2>/dev/null || true
89+
mkdir -p $out/{bin,lib}
10390
104-
# Create executable
105-
cat > $out/bin/purelymail-mcp <<EOF
91+
# Copy everything needed
92+
cp -r dist $out/lib/
93+
cp -r node_modules $out/lib/
94+
cp -r src $out/lib/
95+
cp package.json $out/lib/
96+
cp purelymail-api-spec.json $out/lib/ 2>/dev/null || true
97+
98+
# Create executable that matches package.json bin field
99+
cat > $out/bin/purelymail-mcp-server <<EOF
106100
#!/usr/bin/env bash
107-
exec ${pkgs.nodejs_20}/bin/node $out/share/purelymail-mcp/dist/index.js "\$@"
101+
exec ${pkgs.nodejs_20}/bin/node $out/lib/dist/index.js "\$@"
108102
EOF
109-
chmod +x $out/bin/purelymail-mcp
103+
chmod +x $out/bin/purelymail-mcp-server
104+
105+
runHook postInstall
110106
'';
111107
};
112108

@@ -174,7 +170,7 @@
174170
# Default app - run the MCP server
175171
apps.default = {
176172
type = "app";
177-
program = "${self.packages.${system}.default}/bin/purelymail-mcp";
173+
program = "${self.packages.${system}.default}/bin/purelymail-mcp-server";
178174
};
179175
}
180176
);

0 commit comments

Comments
 (0)