返回 CodeWhale
package.nix
根目录 / nix / package.nix
1 {
2 lib,
3 stdenv,
4 rustPlatform,
5 pkg-config,
6 autoPatchelfHook ? null,
7 openssl,
8 dbus ? null,
9
10 # for cargo test
11 python3,
12 gitMinimal,
13 cacert,
14 procps,
15
16 rev ? "dirty",
17 }:
18 let
19 # Shared libraries the check-phase test binaries need at runtime
20 # (libdbus, libgcc_s). Derived once so LD_LIBRARY_PATH and the patchelf
21 # RPATH can never drift apart.
22 runtimeLibraryPath = lib.makeLibraryPath (
23 lib.optionals stdenv.hostPlatform.isLinux [
24 dbus.lib
25 stdenv.cc.cc.lib
26 ]
27 );
28 in
29 rustPlatform.buildRustPackage (finalAttrs: {
30 pname = "codewhale";
31 version = "git-${rev}";
32
33 src = ../.;
34
35 cargoLock = {
36 lockFile = ../Cargo.lock;
37 };
38
39 nativeBuildInputs = [
40 pkg-config
41 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
42 autoPatchelfHook
43 ];
44
45 buildInputs = [
46 openssl
47 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
48 dbus.dev
49 dbus.lib
50 stdenv.cc.cc.lib
51 ];
52
53 nativeCheckInputs = [
54 python3
55 gitMinimal
56 cacert
57 ]
58 ++ lib.optionals stdenv.hostPlatform.isLinux [
59 # fleet host memory/zombie sampling shells out to `ps`; NixOS has no
60 # system-wide /usr/bin/ps, so make it resolvable through PATH.
61 procps
62 ];
63
64 cargoBuildFlags = [
65 "--package"
66 "codewhale-cli"
67 ]; # single binary — tui crate is a library, not a shipped binary (v0.9.5+)
68 cargoTestFlags = finalAttrs.cargoBuildFlags ++ [
69 "--lib"
70 "--bins"
71 "--"
72 # Requires the checkout itself to be a git repository (the test walks up
73 # from the current dir); the Nix source tree has no .git.
74 "--skip"
75 "tools::subagent::tests::git_repo_root_reports_attempted_paths_when_no_repo_found"
76 # The header width table is calibrated against the git chrome label
77 # populated by the surrounding checkout state, which the sandboxed test
78 # process does not see.
79 "--skip"
80 "tui::underwater::tests::configured_session_tokens_follow_underwater_header_width_priority"
81 ];
82
83 preCheck = ''
84 # Tests write to the default config/home locations; the sandbox HOME
85 # (/homeless-shelter) is not writable.
86 export HOME="$(mktemp -d)"
87 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
88 ''
89 + lib.optionalString stdenv.hostPlatform.isLinux ''
90 # nixpkgs no longer derives LD_LIBRARY_PATH from buildInputs; the cargo
91 # test binaries link libdbus/libgcc_s dynamically and have no RPATH until
92 # autoPatchelfHook runs at fixup (after the check phase).
93 export LD_LIBRARY_PATH=${runtimeLibraryPath}
94 '';
95
96 # Two-stage check: build the harnesses first, give them an explicit RPATH,
97 # then run. Fleet and shell tests re-execute the test binary through a
98 # scrubbed environment (no LD_LIBRARY_PATH), so without this the re-spawned
99 # harness cannot load libdbus and every descendant-tree test times out.
100 checkPhase = ''
101 runHook preCheck
102
103 # Tests mutate process-global environment (PATH/HOME/cwd) via the shared
104 # EnvVarGuard; a concurrent test spawning a shell can then fail to resolve
105 # the interpreter. Run the harness serially so the check is deterministic.
106 export RUST_TEST_THREADS=1
107
108 flagsArray=(-j "$NIX_BUILD_CORES" --profile release --target ${stdenv.hostPlatform.config} --offline)
109 concatTo flagsArray cargoTestFlags checkFlags
110
111 echo "Building test binaries"
112 cargo test --no-run "''${flagsArray[@]}"
113
114 ${lib.optionalString stdenv.hostPlatform.isLinux ''
115 echo "Patching runtime RPATH into test binaries"
116 find "target/${stdenv.hostPlatform.config}/release/deps" \
117 -maxdepth 1 -type f -executable \
118 -exec patchelf --add-rpath "${runtimeLibraryPath}" {} +
119 ''}
120
121 echo "Running tests"
122 cargo test "''${flagsArray[@]}"
123
124 runHook postCheck
125 '';
126
127 meta = {
128 description = "Terminal coding agent for DeepSeek";
129 homepage = "https://github.com/Hmbown/CodeWhale";
130 license = lib.licenses.mit;
131 mainProgram = "codewhale";
132 };
133 })
134
134 lines Plain Text