Skip to content

Commit 1dab5c2

Browse files
authored
refactor(nix): derive package metadata from the npm manifest (#1506)
`package.nix` restated the name, description, homepage, license, and `mainProgram` that `apps/ccusage/package.json` already declares, so the two drifted: the manifest describes the CLI as "Analyze coding (agent) CLI token usage and costs from local data" while Nix dropped the parentheses, and nothing tied the Nix `mainProgram` to the manifest's `bin` entry. Import the published manifest and derive all of it, following the pattern in yusukebe/ax: `lib.getLicenseFromSpdxId` turns the SPDX string into a nixpkgs license, and `mainProgram` comes from the sole `bin` key. `ccusage-static` and `ccusage-darwin-x64` already build their `meta` from `config.packages.ccusage.meta`, so they inherit this too. `version` still comes from the root manifest. `rust/crates/ccusage/ build.rs` falls back to reading it when `CCUSAGE_VERSION` is unset, and `compiled_version_matches_release_package` asserts the compiled version matches it, so moving the Nix source would split the version's origin between the Nix and plain-cargo builds. tagpr bumps both manifests together. `meta.homepage` gains the `#readme` fragment the manifest carries. The URL resolves to the same page. Verified with `nix eval`: `pname`, `version`, `license.spdxId`, and `mainProgram` are unchanged, and `ccusage-darwin-x64` still inherits the license and `mainProgram`.
1 parent caf89e8 commit 1dab5c2

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎package.nix‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
apple-sdk_15,
1212
}:
1313
let
14-
inherit ((builtins.fromJSON (builtins.readFile (root + /package.json)))) version;
14+
# The root manifest is the version source of truth: rust/crates/ccusage/build.rs
15+
# falls back to reading it when CCUSAGE_VERSION is unset, and a test in main.rs
16+
# asserts the compiled version matches it.
17+
inherit (lib.importJSON (root + /package.json)) version;
18+
# The published npm manifest owns the name and the user-facing metadata, so
19+
# `meta` below derives from it instead of restating it in Nix.
20+
cliPackageJson = lib.importJSON (root + /apps/ccusage/package.json);
1521
src = lib.cleanSourceWith {
1622
src = root + /rust;
1723
filter =
@@ -30,7 +36,7 @@ let
3036
# duplicated.
3137
cargoConfigEnv = (builtins.fromTOML (builtins.readFile (root + /.cargo/config.toml))).env;
3238
commonArgs = {
33-
pname = "ccusage";
39+
pname = cliPackageJson.name;
3440
inherit version src;
3541
strictDeps = true;
3642
doCheck = false;
@@ -132,10 +138,9 @@ craneLib.buildPackage (
132138
;
133139
};
134140
meta = {
135-
description = "Analyze coding agent CLI token usage and costs from local data";
136-
homepage = "https://github.com/ccusage/ccusage";
137-
license = lib.licenses.mit;
138-
mainProgram = "ccusage";
141+
inherit (cliPackageJson) description homepage;
142+
license = lib.getLicenseFromSpdxId cliPackageJson.license;
143+
mainProgram = builtins.head (builtins.attrNames cliPackageJson.bin);
139144
};
140145
}
141146
)

0 commit comments

Comments
 (0)