forked from apollographql/apollo-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
212 lines (184 loc) · 6.8 KB
/
Copy pathflake.nix
File metadata and controls
212 lines (184 loc) · 6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{
description = "MCP Support for Apollo Tooling";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-24.11";
unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
# Helper utility for keeping certain paths from garbage collection in CI
cache-nix-action = {
url = "github:nix-community/cache-nix-action";
flake = false;
};
# Rust builder
crane.url = "github:ipetkov/crane";
# Rust toolchains
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "unstable";
};
# Overlay for common architecture support
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
cache-nix-action,
crane,
flake-utils,
nixpkgs,
rust-overlay,
unstable,
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
unstable-pkgs = import unstable {
inherit system;
overlays = [(import rust-overlay)];
# Elastic license is non-free, so we allow it to build here
config.allowUnfreePredicate = pkg: let lib = unstable-pkgs.lib; in lib.strings.hasPrefix "apollo-" (lib.getName pkg);
};
# Define the toolchain based on the rust-toolchain file
toolchain = unstable-pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
apollo-mcp-builder = unstable-pkgs.callPackage ./nix/apollo-mcp.nix {
inherit crane toolchain;
};
# Supporting tools
mcphost = pkgs.callPackage ./nix/mcphost.nix {};
mcp-server-tools = pkgs.callPackage ./nix/mcp-server-tools {};
# CI options
garbageCollector = import "${inputs.cache-nix-action}/saveFromGC.nix" {
inherit pkgs inputs;
derivations = [mcphost] ++ apollo-mcp-builder.cache ++ mcp-server-tools;
};
in rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = apollo-mcp-builder.nativeDependencies;
buildInputs =
[
mcphost
toolchain
]
++ apollo-mcp-builder.dependencies
++ mcp-server-tools
++ (with pkgs; [
# For running github action workflows locally
act
# For autogenerating nix evaluations for MCP server tools
node2nix
# Some of the mcp tooling likes to spawn arbitrary node runtimes,
# so we need nodejs in the path here :(
nodejs_22
# For local LLM testing
ollama
# For consistent TOML formatting
taplo
# To allow using dependencies from git repositories in Cargo.toml
git
]);
};
checks =
{
# Check formatting
nix-fmt = pkgs.runCommandLocal "check-nix-fmt" {} "${pkgs.alejandra}/bin/alejandra --check ${./.}; touch $out";
}
// apollo-mcp-builder.checks;
packages = let
# Cross targets for supported architectures
cross = let
# Note: x86_64-apple-darwin doesn't yet work with zig due to an upstream bug
supportedTargets = [
"aarch64-apple-darwin"
"aarch64-pc-windows-gnullvm"
"aarch64-unknown-linux-gnu"
"aarch64-unknown-linux-musl"
"x86_64-apple-darwin"
"x86_64-pc-windows-gnullvm"
"x86_64-unknown-linux-gnu"
"x86_64-unknown-linux-musl"
];
crossBuild = target: let
crossToolchain = toolchain.override {
targets = [target];
};
apollo-mcp-cross = unstable-pkgs.callPackage ./nix/apollo-mcp.nix {
inherit crane;
toolchain = crossToolchain;
};
in
apollo-mcp-cross.packages.builder target;
in
builtins.listToAttrs (builtins.map (target: {
name = "cross-${target}";
value = crossBuild target;
})
supportedTargets);
in
rec {
inherit (garbageCollector) saveFromGC;
default = apollo-mcp;
apollo-mcp = apollo-mcp-builder.packages.apollo-mcp;
}
// cross;
# TODO: This does not work on macOS without cross compiling, so maybe
# we need to disable flake-utils and manually specify the supported
# hosts?
apps = let
# Nix flakes don't yet expose a nice formatted timestamp in ISO-8601
# format, so we need to drop out to date to do so.
commitDate = pkgs.lib.readFile "${pkgs.runCommand "git-timestamp" {env.when = self.lastModified;} "echo -n `date -d @$when --iso-8601=seconds` > $out"}";
# The architecture follows the docker format, which is not what nix uses
archMapper = arch:
builtins.getAttr arch {
"aarch64" = "arm64";
"x86_64" = "amd64";
};
builder = pkgs.dockerTools.streamLayeredImage {
name = "apollo-mcp-server";
tag = archMapper pkgs.stdenv.hostPlatform.uname.processor;
# Use the latest commit time for reproducible builds
created = commitDate;
mtime = commitDate;
contents = [
packages.apollo-mcp
pkgs.cacert
];
# The server expects /data to exist, so we create it in the last layer to
# ensure that the server doesn't crash if nothing is mounted.
fakeRootCommands = ''
mkdir data
chmod a+r data
'';
# Image configuration
# See: https://github.com/moby/moby/blob/46f7ab808b9504d735d600e259ca0723f76fb164/image/spec/spec.md#container-runconfig-field-descriptions
config = let
http-port = 5000;
in {
# Provide default options that can be unset / overridden by the end-user
Env = [
# Use Streamable HTTP transport by default, bound to all addresses
"APOLLO_MCP_TRANSPORT__TYPE=streamable_http"
"APOLLO_MCP_TRANSPORT__ADDRESS=0.0.0.0"
"APOLLO_MCP_TRANSPORT__PORT=${builtins.toString http-port}"
];
WorkingDir = "/data";
# Make the entrypoint the server and have it read the config from /dev/null by default
Cmd = ["/dev/null"];
Entrypoint = [
"apollo-mcp-server"
];
# Listen on container port for Streamable HTTP requests
ExposedPorts = {
"${builtins.toString http-port}/tcp" = {};
};
# Drop to local user
User = "1000";
Group = "1000";
};
};
in {
streamImage = {
type = "app";
program = "${builder}";
meta.description = "Builds the apollo-mcp-server container and streams the image to stdout.";
};
};
});
}