-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathflake.nix
More file actions
151 lines (133 loc) · 6.38 KB
/
Copy pathflake.nix
File metadata and controls
151 lines (133 loc) · 6.38 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
{
description = "codebase-memory-mcp — C11 MCP server for codebase indexing";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs }:
let
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
# Cross dev shell (macOS only): build the *other* darwin arch locally.
# The native clang already cross-emits object code via -arch (scripts/env.sh
# exports ARCHFLAGS), so the only thing missing for a cross link is zlib:
# it is the product's single link-time dependency (`-lz`), and the host-arch
# copy cannot satisfy an x86_64 link on arm64 or vice versa. This shell puts
# the TARGET-arch zlib on the include and link paths, and nothing else.
#
# Building needs no Rosetta; *running* an x86_64 binary on Apple Silicon
# does. The target-arch libs come from prebuilt substitutes, so entering the
# shell is a download rather than a cross-build of the dependency tree.
#
# Returns {} off macOS, where there is no second darwin arch to target.
crossDevShells = pkgs:
let
inherit (nixpkgs) lib;
crossTarget =
{
"aarch64-darwin" = "x86_64-darwin";
"x86_64-darwin" = "aarch64-darwin";
}
.${pkgs.system} or null;
mkCrossShell =
targetSystem:
let
tpkgs = nixpkgs.legacyPackages.${targetSystem};
targetArch = if targetSystem == "x86_64-darwin" then "x86_64" else "arm64";
in
pkgs.mkShell {
# Host toolchain only — clang comes from the shell stdenv. Deliberately
# NOT inputsFrom the default package: that would put the HOST-arch zlib
# on the link path, which is exactly the wrong-arch copy this shell
# exists to displace.
nativeBuildInputs = [ pkgs.gnumake ];
shellHook = ''
# zlib is consumed as a bare `-lz` / `#include <zlib.h>`, so its
# include dir (the header is arch-independent) and lib dir are
# supplied by hand. NIX_LDFLAGS is searched ahead of the link's own
# -L, so the target-arch slice wins; a host-arch copy that still
# reaches ld is skipped as "wrong architecture" rather than
# producing a silently mislinked binary.
export NIX_CFLAGS_COMPILE="-I${lib.getDev tpkgs.zlib}/include ''${NIX_CFLAGS_COMPILE:-}"
export NIX_LDFLAGS="-L${lib.getLib tpkgs.zlib}/lib ''${NIX_LDFLAGS:-}"
echo "[cross] target ${targetSystem} — build with: scripts/build.sh --arch ${targetArch}"
'';
};
in
lib.optionalAttrs (crossTarget != null) {
# `nix develop .#cross` then `scripts/build.sh --arch <target>`.
cross = mkCrossShell crossTarget;
};
in
{
packages = forAllSystems (pkgs: rec {
default = pkgs.stdenv.mkDerivation {
pname = "codebase-memory-mcp";
version = "0.10.8";
src = ./.;
nativeBuildInputs = [ pkgs.gnumake ];
buildInputs = [ pkgs.zlib ];
# scripts/build.sh verifies the compiler via `file`, which fails on Nix
# because CC is a bash wrapper script rather than a binary. Call make
# directly to bypass that check; the Nix stdenv already guarantees the
# correct compiler and target architecture.
buildPhase = ''
make -j$NIX_BUILD_CORES -f Makefile.cbm cbm
'';
installPhase = ''
install -Dm755 build/c/codebase-memory-mcp $out/bin/codebase-memory-mcp
'';
meta = {
description = "MCP server that builds and queries a semantic graph of your codebase";
homepage = "https://github.com/DeusData/codebase-memory-mcp";
license = nixpkgs.lib.licenses.mit;
mainProgram = "codebase-memory-mcp";
platforms = systems;
};
};
# The graph-ui React frontend, built to static assets (graph-ui/dist).
# buildNpmPackage fetches npm deps offline via the pinned package-lock.json;
# bump npmDepsHash whenever that lockfile changes:
# nix run nixpkgs#prefetch-npm-deps -- graph-ui/package-lock.json
graph-ui = pkgs.buildNpmPackage {
pname = "codebase-memory-graph-ui";
version = "0.1.0";
src = ./graph-ui;
npmDepsHash = "sha256-P1JVo+GFr+Gsq88dnn9OsedZqrTaj3DDGbej+nHbp4U=";
# `npm run build` runs `tsc -b && vite build`, emitting to dist/.
installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';
};
# Same server binary as `default`, but with the graph-ui assets embedded
# so `--ui=true` starts the HTTP server. The frontend is built separately
# by the graph-ui package above; here we drop its dist/ into place and run
# the embed + link path (cbm-with-ui) — no network access needed.
codebase-memory-mcp-ui = default.overrideAttrs (old: {
pname = "codebase-memory-mcp-ui";
buildPhase = ''
# cbm-with-ui depends on `embed`, which depends on `frontend`, which
# runs `npm ci && npm run build` — needs network access, unavailable
# in the sandbox. Supply the pre-built assets, run the embed script
# directly, then link with `cbm-with-ui` while telling make its
# `frontend`/`embed` prerequisites are already up to date (-o) so it
# won't re-run the npm build.
mkdir -p graph-ui/dist
cp -r ${graph-ui}/. graph-ui/dist/
chmod -R u+w graph-ui/dist
bash scripts/embed-frontend.sh graph-ui/dist build/c/embedded
make -j$NIX_BUILD_CORES -f Makefile.cbm \
-o frontend -o embed \
cbm-with-ui
'';
meta = old.meta // {
description = "codebase-memory-mcp with the embedded graph UI (--ui)";
};
});
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
inputsFrom = [ self.packages.${pkgs.system}.default ];
};
} // crossDevShells pkgs);
};
}