-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathflake.nix
More file actions
261 lines (225 loc) · 9.54 KB
/
Copy pathflake.nix
File metadata and controls
261 lines (225 loc) · 9.54 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{
description = "xum - coding agent multiplexer";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
# package.json pins Electron 40.x; keep Electron evaluation permissive
# so nixpkgs security metadata does not break the devShell before we
# intentionally move to the next supported Electron line.
config.allowInsecurePredicate = attrs: builtins.match "electron.*" (attrs.pname or "") != null;
};
xum = pkgs.stdenv.mkDerivation rec {
pname = "xum";
version = self.rev or self.dirtyRev or "dev";
src = ./.;
nativeBuildInputs = with pkgs; [
bun
nodejs
makeWrapper
gnumake
git # Needed by scripts/generate-version.sh
python3 # Needed by node-gyp for native module builds
];
buildInputs = with pkgs; [
# Pin the major Electron version explicitly so `pkgs.electron`
# floating to a new major doesn't silently ship the wrong
# Node.js ABI for our prebuilt native modules.
electron_40
stdenv.cc.cc.lib # Provides libstdc++ for native modules like sharp
];
# Fetch dependencies in a separate fixed-output derivation.
# Include Bun patch files alongside package.json and bun.lock so patched
# dependencies install identically in local and remote Nix evaluations.
offlineCache = pkgs.stdenvNoCC.mkDerivation {
name = "xum-deps-${version}";
src = pkgs.runCommand "xum-lock-files" { } ''
mkdir -p $out
cp ${./package.json} $out/package.json
cp -r ${./patches} $out/patches
cp ${./bun.lock} $out/bun.lock
'';
nativeBuildInputs = [
pkgs.bun
pkgs.cacert
];
# Don't patch shebangs in node_modules - it creates /nix/store references
dontPatchShebangs = true;
dontFixup = true;
# --ignore-scripts: postinstall scripts (e.g., lzma-native's node-gyp-build)
# fail in the sandbox because shebangs like #!/usr/bin/env node can't resolve.
# Native modules are rebuilt in the main derivation after patchShebangs runs.
buildPhase = ''
export HOME=$TMPDIR
export BUN_INSTALL_CACHE_DIR=$TMPDIR/.bun-cache
bun install --frozen-lockfile --no-progress --ignore-scripts
'';
installPhase = ''
mkdir -p $out
cp -r node_modules $out/
'';
outputHashMode = "recursive";
# Marker used by scripts/update_flake_hash.sh to update this hash in place.
outputHash = "sha256-Ci2q4ZCIymKhf4rinh6VKdzaGVBCRBsMUgjQOXTqotM="; # xum-offline-cache-hash
};
configurePhase = ''
export HOME=$TMPDIR
# Use pre-fetched dependencies (copy so tools can write to it)
cp -r ${offlineCache}/node_modules .
chmod -R +w node_modules
# Patch shebangs in node_modules binaries and scripts
patchShebangs node_modules
patchShebangs scripts
# Run postinstall to rebuild node-pty for Electron
# (skipped in offlineCache due to --ignore-scripts)
./scripts/postinstall.sh
# Touch sentinel to prevent make from re-running bun install
touch node_modules/.installed
'';
buildPhase = ''
echo "Building xum with make..."
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH"
# Nix strips .git from the build sandbox, so generate-version.sh's
# git describe/rev-parse fall back to "unknown". Feed the revision
# the flake already resolved so the version stamp is accurate.
export RELEASE_TAG="${version}"
export XUM_GIT_COMMIT="${builtins.substring 0 12 version}"
make SHELL=${pkgs.bash}/bin/bash build
'';
installPhase = ''
mkdir -p $out/lib/xum
mkdir -p $out/bin
# Copy built files and runtime dependencies
cp -r dist $out/lib/xum/
cp -r node_modules $out/lib/xum/
cp package.json $out/lib/xum/
# Ensure vendored binaries have execute permission.
# agent-browser's postinstall normally does this, but
# --ignore-scripts in offlineCache skips it, and the
# Nix store is read-only at runtime so chmod is impossible.
chmod +x $out/lib/xum/node_modules/agent-browser/bin/* 2>/dev/null || true
# Keep one canonical wrapper and make the old command a symlink so
# nix profile upgrades/downgrades never fork the implementation.
makeWrapper ${pkgs.electron_40}/bin/electron $out/bin/xum \
--add-flags "$out/lib/xum/dist/cli/index.js" \
--set XUM_E2E_LOAD_DIST "1" \
--prefix LD_LIBRARY_PATH : "${pkgs.stdenv.cc.cc.lib}/lib" \
--prefix PATH : ${
pkgs.lib.makeBinPath [
pkgs.git
pkgs.bash
]
}
ln -s xum $out/bin/mux
# Install canonical launcher assets and leave old filenames pointing forward.
install -Dm644 public/icon.png $out/share/icons/hicolor/512x512/apps/xum.png
ln -s xum.png $out/share/icons/hicolor/512x512/apps/mux.png
mkdir -p $out/share/applications
cat > $out/share/applications/xum.desktop << EOF
[Desktop Entry]
Name=Xum
GenericName=Coding Agent Multiplexer
Comment=Coding Agent Multiplexer
Exec=$out/bin/xum %U
Icon=xum
Terminal=false
Type=Application
Categories=Development;
StartupWMClass=xum
EOF
ln -s xum.desktop $out/share/applications/mux.desktop
'';
meta = with pkgs.lib; {
description = "xum - coding agent multiplexer";
homepage = "https://github.com/coder/mux";
license = licenses.agpl3Only;
platforms = platforms.linux ++ platforms.darwin;
mainProgram = "xum";
};
};
in
{
packages.default = xum;
packages.xum = xum;
packages.mux = xum;
formatter = pkgs.nixfmt-rfc-style;
apps.default = {
type = "app";
program = "${xum}/bin/xum";
};
apps.xum = {
type = "app";
program = "${xum}/bin/xum";
};
apps.mux = {
type = "app";
program = "${xum}/bin/mux";
};
devShells.default = pkgs.mkShell {
buildInputs =
with pkgs;
[
bun
# Node + build tooling
nodejs
gnumake
stdenv.cc.cc.lib # Provides libstdc++.so.6 for DuckDB native bindings under Bun
# Common CLIs
git
bash
# Nix tooling
nixfmt-rfc-style
# Repo linting (make static-check)
go
hadolint
shellcheck
shfmt
gh
jq
duckdb
# Documentation
mdbook
mdbook-mermaid
mdbook-linkcheck2
mdbook-pagetoc
# Browser automation
agent-browser
# Terminal bench + browser recording
uv
asciinema
ffmpeg
]
++ lib.optionals stdenv.isLinux [
docker
# The Electron binary shipped in node_modules/electron/dist
# is dynamically linked against standard FHS paths
# (libglib-2.0.so.0, libnss3.so, etc.) that don't exist on
# NixOS, so `make start` / `make dev` fail with "error while
# loading shared libraries". Expose Nix's autoPatchelf'd
# Electron and redirect the npm wrapper to it via
# ELECTRON_OVERRIDE_DIST_PATH below.
electron_40
];
# Bun does not carry libstdc++ on Linux, so native modules like @duckdb/node-bindings
# fail to dlopen during tests unless we expose the GCC runtime in the shell.
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ];
# Point `node_modules/electron/cli.js` at the Nix-patched Electron
# binary on Linux so `bunx electron` (used by `make start`/`make dev`)
# finds its shared libraries on NixOS without needing an FHS wrapper.
# Left unset on Darwin where the npm-shipped binary runs as-is.
ELECTRON_OVERRIDE_DIST_PATH = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.electron_40}/libexec/electron";
};
}
);
}