-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
281 lines (261 loc) · 9.32 KB
/
Copy pathflake.nix
File metadata and controls
281 lines (261 loc) · 9.32 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
{
description = "claudex — query, search, and analyze Claude Code sessions";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.devshell.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-darwin"
];
perSystem =
{
system,
lib,
...
}:
let
pkgs = import inputs.nixpkgs {
localSystem = system;
overlays = [ inputs.rust-overlay.overlays.default ];
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rustfmt"
"clippy"
];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.path ./.;
darwinInputs = lib.optionals pkgs.stdenv.isDarwin [
pkgs.libiconv
];
# Cargo manifests are the source of truth for package metadata. All
# crates inherit the product version that release-plz maintains in
# [workspace.package].
workspaceToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cliCargoToml = builtins.fromTOML (builtins.readFile ./crates/claudex-cli/Cargo.toml);
claudexMeta = {
description = cliCargoToml.package.description;
homepage = workspaceToml.workspace.package.homepage;
license = lib.licenses.mit;
mainProgram = "claudex";
maintainers = [
{
name = "James Brink";
email = "brink.james@gmail.com";
github = "jamesbrink";
githubId = 28793;
}
];
platforms = lib.platforms.unix;
};
commonArgs = {
inherit src;
pname = "claudex";
version = workspaceToml.workspace.package.version;
strictDeps = true;
buildInputs = darwinInputs;
meta = claudexMeta;
cargoExtraArgs = "-p claudex-cli --bin claudex";
}
// lib.optionalAttrs pkgs.stdenv.isDarwin {
# On Darwin the Xcode clang invoked by crane can't find Nix-provided
# libiconv without an explicit library path. Set both so the rustc
# link step and bindgen's clang find the library.
LIBRARY_PATH = "${pkgs.libiconv}/lib";
NIX_LDFLAGS = "-L${pkgs.libiconv}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
claudex = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
);
in
{
_module.args.pkgs = pkgs;
packages = {
inherit claudex;
default = claudex;
};
apps.default = {
type = "app";
program = "${claudex}/bin/claudex";
meta = claudexMeta;
};
devshells.default = {
motd = ''
{202}claudex{reset} — query, search, and analyze Claude Code sessions ({bold}${system}{reset})
$(type menu &>/dev/null && menu)
'';
packages = [
rustToolchain
pkgs.rust-analyzer
pkgs.cargo-llvm-cov
pkgs.git
pkgs.gh
pkgs.jq
# Docs site (VitePress, Tailwind v4, Vue 3) lives in ./website.
# prettier is a devDependency installed by `bun install`.
pkgs.bun
]
++ darwinInputs;
env = [
{
name = "RUST_BACKTRACE";
value = "1";
}
]
++ lib.optionals pkgs.stdenv.isDarwin [
{
name = "LIBRARY_PATH";
value = "${pkgs.libiconv}/lib";
}
];
commands = [
{
category = "build";
name = "build";
help = "cargo build -p claudex-cli --bin claudex (debug)";
command = "cargo build -p claudex-cli --bin claudex \"$@\"";
}
{
category = "build";
name = "build-release";
help = "cargo build --release -p claudex-cli --bin claudex";
command = "cargo build --release -p claudex-cli --bin claudex \"$@\"";
}
{
category = "check";
name = "check";
help = "cargo check --workspace --all-targets";
command = "cargo check --workspace --all-targets \"$@\"";
}
{
category = "check";
name = "clippy";
help = "cargo clippy --workspace --all-targets -- -D warnings (matches CI)";
command = "cargo clippy --workspace --all-targets \"$@\" -- -D warnings";
}
{
category = "check";
name = "fmt";
help = "cargo fmt";
command = "cargo fmt \"$@\"";
}
{
category = "check";
name = "fmt-check";
help = "cargo fmt --check (matches CI)";
command = "cargo fmt --check \"$@\"";
}
{
category = "check";
name = "run-tests";
help = "cargo test --workspace (matches CI)";
command = "cargo test --workspace \"$@\"";
}
{
category = "check";
name = "ci-local";
help = "run the same sequence CI runs: fmt-check, check, clippy, test, build";
command = ''
set -euo pipefail
cargo fmt --all -- --check
cargo check --workspace --all-targets
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo build --release -p claudex-cli --bin claudex
'';
}
{
category = "check";
name = "coverage";
help = "test coverage summary (pass --html for a browsable report)";
command = ''
set -euo pipefail
# llvm-cov/llvm-profdata ship with the rustc toolchain but
# aren't on PATH; point cargo-llvm-cov at them explicitly.
LLVM_COV="$(find /nix/store -maxdepth 3 -name llvm-cov 2>/dev/null | head -1)"
LLVM_PROFDATA="$(find /nix/store -maxdepth 3 -name llvm-profdata 2>/dev/null | head -1)"
export LLVM_COV LLVM_PROFDATA
if [ "''${1:-}" = "--html" ]; then
cargo llvm-cov --workspace --html --output-dir target/coverage
echo "Report: target/coverage/html/index.html"
else
cargo llvm-cov --workspace --summary-only
fi
'';
}
{
category = "run";
name = "claudex";
help = "run claudex";
command = "cargo run -p claudex-cli --bin claudex -- \"$@\"";
}
{
category = "docs";
name = "docs-dev";
help = "start the VitePress dev server for the docs site";
command = "cd website && bun install && bun run dev \"$@\"";
}
{
category = "docs";
name = "docs-build";
help = "build the documentation site (static output in website/.vitepress/dist)";
command = "cd website && bun install && bun run build";
}
{
category = "docs";
name = "docs-preview";
help = "preview the built documentation site";
command = "cd website && bun run preview \"$@\"";
}
{
category = "docs";
name = "docs-fmt";
help = "format documentation with prettier";
command = "cd website && bun run fmt";
}
{
category = "docs";
name = "docs-fmt-check";
help = "check documentation formatting (matches CI)";
command = "cd website && bun run fmt:check";
}
];
};
treefmt = {
projectRootFile = "flake.nix";
programs.nixfmt.enable = true;
programs.rustfmt = {
enable = true;
edition = "2024";
};
};
};
};
}