-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathflake.nix
More file actions
237 lines (210 loc) · 7.21 KB
/
Copy pathflake.nix
File metadata and controls
237 lines (210 loc) · 7.21 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
{
description = "Worktrunk - A CLI for Git worktree management";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Pin to the channel declared in rust-toolchain.toml so rustup and Nix
# stay on the same version. Extensions are dev-shell-only, so we keep
# them here rather than in rust-toolchain.toml (which CI also reads).
toolchainChannel = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
rustToolchain = pkgs.rust-bin.stable.${toolchainChannel}.default.override {
extensions = [
"rust-src"
"rust-analyzer"
];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Filter source to include Cargo files plus templates (needed by askama)
# and the Gemini extension manifest (embedded via include_str! in
# src/testing/mod.rs; lives at the repo root because Gemini's loader
# reads it only from the clone root — see #2807).
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
p: type:
(craneLib.filterCargoSources p type)
|| (pkgs.lib.hasInfix "/templates/" p)
|| (baseNameOf (dirOf p) == "templates")
|| (pkgs.lib.hasInfix "/dev/" p)
|| (baseNameOf (dirOf p) == "dev")
|| (baseNameOf p == "gemini-extension.json");
};
# Common arguments for crane builds
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs =
with pkgs;
[
# Required for tree-sitter (syntax-highlighting feature, enabled by default)
tree-sitter
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
libiconv
];
# vergen-gitcl needs git info; VERGEN_IDEMPOTENT makes it emit
# placeholder values when .git isn't available (which is the case
# in Nix builds since the store doesn't include .git)
VERGEN_IDEMPOTENT = "1";
# Optionally provide git describe via environment if flake has rev
VERGEN_GIT_DESCRIBE =
self.shortRev or self.dirtyShortRev or "nix-${self.lastModifiedDate or "unknown"}";
};
# Build just the cargo dependencies for caching.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual package
worktrunk = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# Skip tests during package build - they require snapshot files (insta)
# which bloat the source. Tests should run in CI instead.
doCheck = false;
meta = with pkgs.lib; {
description = "A CLI for Git worktree management, designed for parallel AI agent workflows";
homepage = "https://github.com/max-sixty/worktrunk";
license = with licenses; [
mit
asl20
];
maintainers = [ ];
mainProgram = "wt";
};
}
);
# Build with git-wt feature for Windows compatibility
worktrunk-with-git-wt = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoExtraArgs = "--features git-wt";
doCheck = false;
meta = worktrunk.meta // {
description = "Worktrunk with git-wt binary (for 'git wt' subcommand)";
};
}
);
in
{
checks = {
inherit worktrunk;
# Run clippy
worktrunk-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
# Check formatting
worktrunk-fmt = craneLib.cargoFmt { inherit src; };
# Run tests inside the nix sandbox. Catches packaging-environment
# bugs (#2624 is the canonical example) before nixpkgs maintainers
# do — see .github/workflows/nightly.yaml.
#
# Wider src than the package build: tests need .snap files and
# tests/ fixtures (prebuilt _git/ trees, .sh scripts, no-extension
# git database files). Default features only — shell-integration-
# tests requires zsh/fish/nushell + PTY (see CLAUDE.md → "Shell/PTY
# Integration Tests").
worktrunk-tests = craneLib.cargoTest (
commonArgs
// {
inherit cargoArtifacts;
src = pkgs.lib.cleanSource ./.;
# Tests shell out to a few host tools — `git` for the harness,
# `python3` for argv-quoting and post-start fixtures, `ps`
# (procps) for the pgid invariant test, `lsof` for the
# `--reap` process-discovery test. Without these on PATH
# the sandbox surfaces them as `No such file or directory`.
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
pkgs.git
pkgs.python3
pkgs.procps
pkgs.lsof
];
}
);
};
packages = {
default = worktrunk;
inherit worktrunk;
inherit worktrunk-with-git-wt;
};
apps = {
default = flake-utils.lib.mkApp {
drv = worktrunk;
name = "wt";
};
wt = flake-utils.lib.mkApp {
drv = worktrunk;
name = "wt";
};
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [
# Rust tooling
cargo-watch
cargo-edit
cargo-outdated
cargo-release
cargo-llvm-cov
# For shell integration tests
bash
zsh
fish
# Development tools
git
gh
pre-commit
];
shellHook = ''
echo "Worktrunk development shell"
echo " Build: cargo build"
echo " Test: cargo test"
echo " Lint: cargo clippy"
'';
};
}
)
// {
homeModules = {
default =
{
lib,
config,
pkgs,
...
}:
(import ./nix/home-manager-module.nix) {
inherit lib config pkgs;
worktrunk-pkgs = self.packages.${pkgs.stdenv.hostPlatform.system};
};
};
};
}