Skip to content

fix(nix): apply the repository cargo config to Nix builds - #1496

Merged
ryoppippi merged 1 commit into
mainfrom
nix/cargo-config-env
Jul 27, 2026
Merged

fix(nix): apply the repository cargo config to Nix builds#1496
ryoppippi merged 1 commit into
mainfrom
nix/cargo-config-env

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

.cargo/config.toml sets 47 SQLITE_OMIT_* values in its [env] section, and
sqlite3-src's build script turns every SQLITE_* environment variable into a -D
define for the bundled amalgamation. That is how this repository trims SQLite down to
what the four SQLite-backed adapters actually use.

Cargo only reads that file when the working directory is the repository root, so it
applied to local cargo runs and to nothing else. Every Nix build unpacks a source
tree rooted at rust/, so all of them — the artifact layers, the flake checks, and
the binaries the release ships — compiled the full SQLite.

package.nix now reads the same file rather than duplicating the values, so there is
still one source of truth and the two cannot drift.

Effect

bytes
before 3,232,896
after 3,030,272

−202,624 bytes, −6.3%, on the aarch64-darwin Nix build. For scale, that is more than
the whole size cost of the crate split in #1428.

Correctness

The omit flags remove SQLite features, so the risk is a query needing one of them.
These values already applied to every local cargo test run, which is what exercises
the adapters' queries, but never to a Nix-built binary — so this is the first time a
shipped binary would carry them. Checked directly by diffing the old and new Nix
binaries against real local data:

  • opencode daily --json --offline — identical
  • goose daily --json --offline — identical
  • kilo daily --json --offline — identical
  • hermes daily --json --offline — identical
  • daily --json --offline (unified) — identical

Testing

  • nix build .#ccusage .#ccusage-tests .#checks.aarch64-darwin.ccusage-clippy .#checks.aarch64-darwin.config-schema
  • just fmt
  • the five output comparisons above

Found while reviewing the diff of #1428; the condition predates it.


View with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is enabled.


Summary by cubic

Apply the repository .cargo/config.toml [env] to Nix builds so SQLITE_OMIT_* flags from sqlite3-src are honored, matching local cargo builds. Shipped binaries shrink by 202,624 bytes (-6.3% on aarch64-darwin) with identical adapter JSON outputs, and the flags now come from a single source of truth.

Written for commit e399375. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved package builds by ensuring required SQLite build settings are applied consistently.
    • Increased reliability when building the bundled SQLite component through Nix.

`.cargo/config.toml` sets 47 `SQLITE_OMIT_*` values, and sqlite3-src's build
script turns every `SQLITE_*` environment variable into a `-D` define for the
bundled amalgamation. Cargo only reads that file when the working directory is the
repository root, so it applied to local `cargo` runs and to nothing else: every
Nix build, including the shipped binaries, compiled the full SQLite.

Reading the same file in package.nix rather than duplicating the values keeps one
source of truth. The aarch64-darwin binary drops 3,232,896 -> 3,030,272 bytes
(-6.3%), and the four SQLite-backed adapters produce byte-identical JSON before
and after.
Copilot AI review requested due to automatic review settings July 27, 2026 11:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 28f9b397-8035-4d77-a98c-f9bc9e059798

📥 Commits

Reviewing files that changed from the base of the PR and between 60f1984 and e399375.

📒 Files selected for processing (1)
  • package.nix

📝 Walkthrough

Walkthrough

package.nix parses the Cargo configuration’s [env] table and merges the resulting variables into commonArgs for the craneLib.buildPackage invocation.

Changes

Cargo environment propagation

Layer / File(s) Summary
Parse and pass Cargo environment values
package.nix
Adds cargoConfigEnv from .cargo/config.toml and merges it into the shared package build arguments.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: making Nix builds use the repository's Cargo config.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nix/cargo-config-env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide e399375 Commit Preview URL

Branch Preview URL
Jul 27 2026, 11:26 AM

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — reads .cargo/config.toml's [env] section into the Nix build so the 47 SQLITE_OMIT_* flags apply uniformly, shrinking the shipped binary by ~6.3% without changing adapter output.

  • Read .cargo/config.toml into cargoConfigEnv — single builtins.fromTOML + builtins.readFile parse, same path-join pattern as the existing package.json read on line 14.
  • Merge into commonArgs via // — env vars propagate cleanly through all three build stages (buildDepsOnly, artifact layers, buildPackage).

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

npx https://pkg.pr.new/ccusage@1496

@ccusage/ccusage-darwin-arm64

npx https://pkg.pr.new/@ccusage/ccusage-darwin-arm64@1496

@ccusage/ccusage-darwin-x64

npx https://pkg.pr.new/@ccusage/ccusage-darwin-x64@1496

@ccusage/ccusage-linux-arm64

npx https://pkg.pr.new/@ccusage/ccusage-linux-arm64@1496

@ccusage/ccusage-linux-x64

npx https://pkg.pr.new/@ccusage/ccusage-linux-x64@1496

@ccusage/ccusage-win32-x64

npx https://pkg.pr.new/@ccusage/ccusage-win32-x64@1496

commit: e399375

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: e39937543975
Base SHA: 60f198460c7d

This compares the PR package against the configured base package on the same CI runner.

Package runtime diagnostics

Compares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 339.6ms 2.96 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 335.9ms 3.00 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 115.0ms 8.76 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 90.6ms 11.11 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude daily --offline --json 0.00 MiB 30.1ms 25.9ms 1.16x 55.00 MiB 55.25 MiB 1.00x 0.05 MiB/s 0.06 MiB/s
claude session --offline --json 0.00 MiB 27.7ms 28.0ms 0.99x 55.00 MiB 55.00 MiB 1.00x 0.06 MiB/s 0.06 MiB/s
codex daily --offline --json 0.00 MiB 24.8ms 23.3ms 1.06x 55.00 MiB 55.00 MiB 1.00x 0.03 MiB/s 0.04 MiB/s
codex session --offline --json 0.00 MiB 24.0ms 22.6ms 1.06x 55.00 MiB 55.00 MiB 1.00x 0.04 MiB/s 0.04 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude --offline --json 1.01 GiB 371.3ms 354.4ms 1.05x 942.58 MiB 922.57 MiB 0.98x 2.71 GiB/s 2.84 GiB/s
codex --offline --json 1.01 GiB 114.3ms 115.6ms 0.99x 406.91 MiB 412.89 MiB 1.01x 8.81 GiB/s 8.71 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 18.70 KiB 18.70 KiB +0.00 KiB 1.00x
installed native package binary 4201.63 KiB 4008.14 KiB -193.48 KiB 1.05x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: e39937543975
Base SHA: 60f198460c7d

This compares the Rust PR release binary against the configured base package on the same CI runner.

Package runtime diagnostics

Compares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 315.0ms 3.20 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 297.5ms 3.38 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 121.3ms 8.30 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 96.1ms 10.48 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published native ccusage binary from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude daily --offline --json 0.00 MiB 34.2ms 7.5ms 4.58x 55.50 MiB 12.45 MiB 0.22x 0.05 MiB/s 0.21 MiB/s
claude session --offline --json 0.00 MiB 31.7ms 6.7ms 4.74x 55.25 MiB 12.44 MiB 0.23x 0.05 MiB/s 0.23 MiB/s
codex daily --offline --json 0.00 MiB 27.7ms 3.4ms 8.08x 55.00 MiB 10.45 MiB 0.19x 0.03 MiB/s 0.25 MiB/s
codex session --offline --json 0.00 MiB 28.6ms 3.4ms 8.29x 55.00 MiB 10.44 MiB 0.19x 0.03 MiB/s 0.25 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/_work/_temp/ccusage-large-fixture (1.01 GiB, 2597 files), Codex /home/runner/_work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published native ccusage binary from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.
Peak RSS is measured separately with /usr/bin/time using 1 runs. Lower RSS ratios are better.

Command Input Base median PR median PR vs base Base peak RSS PR peak RSS PR/base RSS Base throughput PR throughput
claude --offline --json 1.01 GiB 349.6ms 287.3ms 1.22x 944.58 MiB 948.57 MiB 1.00x 2.88 GiB/s 3.50 GiB/s
codex --offline --json 1.01 GiB 120.0ms 98.4ms 1.22x 402.90 MiB 390.88 MiB 0.97x 8.39 GiB/s 10.23 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 18.70 KiB 18.70 KiB +0.00 KiB 1.00x
installed native package binary 4201.63 KiB 4008.14 KiB -193.48 KiB 1.05x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@ryoppippi
ryoppippi merged commit 2ddac5b into main Jul 27, 2026
38 checks passed
@ryoppippi
ryoppippi deleted the nix/cargo-config-env branch July 27, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants