Skip to content

fix(nix-cache-server): patch nix-serve-ng for cppnix 2.30+ API drift - #312

Open
Joaqim wants to merge 1 commit into
juspay:mainfrom
Joaqim:cppnix-2.30-api-compat
Open

fix(nix-cache-server): patch nix-serve-ng for cppnix 2.30+ API drift#312
Joaqim wants to merge 1 commit into
juspay:mainfrom
Joaqim:cppnix-2.30-api-compat

Conversation

@Joaqim

@Joaqim Joaqim commented May 12, 2026

Copy link
Copy Markdown

No description provided.

…e transform

Three sed patches against cbits/nix.cpp covering the API drift between the
nix-serve-ng-1.1.0 pin and cppnix 2.30+:

- settings.nixStore is removed from the global Settings singleton; the store
  directory now lives on Store instances via StoreDirConfig::storeDir
  (store-dir-config.hh:33). Switch to getStore()->storeDir, which reuses the
  memoised store helper already used elsewhere in the file.
- ValidPathInfo::sigs is now std::set<nix::Signature> (path-info.hh:105),
  not std::set<std::string>; project each Signature to its string form via
  Signature::to_string() (local-keys.hh:37).
- SecretKey::signDetached now returns nix::Signature (local-keys.hh:78);
  append .to_string() at the call site. The single sed covers both the
  pre-Lix-2.94 and post-Lix-2.94 branches.

Without these patches, vira's nix-cache-server fails to compile on hosts that
build vira from source against cppnix 2.30+ rather than pulling prebuilt
artifacts from cache.nixos.asia.
@Joaqim Joaqim changed the title fix: cppnix 2.30+ API compatibility for nix-serve-ng source transform fix(nix-cache-server): cppnix 2.30+ API compatibility for nix-serve-ng source transform May 12, 2026
@Joaqim

Joaqim commented May 12, 2026

Copy link
Copy Markdown
Author

nix-cache-server now compiles against cppnix 2.30+. vira's transform pipeline patches nix-serve-ng-1.1.0 at build time, but three of the cbits/nix.cpp FFI bridges reference cppnix APIs that have since drifted. Without these sed substitutions, a fresh nix build against cppnix 2.30+ fails — most visibly with std::basic_string constructor ambiguity under gcc-15.

The three drifted call sites

Site Symptom Resolution
nix.cpp:153 settings.nixStore Field removed from cppnix Settings singleton (globals.hh) Use getStore()->storeDir from StoreDirConfig (store-dir-config.hh:33)
nix.cpp:209 std::vector<std::string> sigs(begin, end) ValidPathInfo::sigs is now std::set<nix::Signature> (path-info.hh:105) Project each element through nix::Signature::to_string()
nix.cpp:229,231 std::string = signDetached(...) SecretKey::signDetached returns nix::Signature (local-keys.hh:78) Append .to_string()

The patch

Three sed -i lines in packages/nix-cache-server/haskell-module.nix, alongside the existing #include rewrites:

${pkgs.gnused}/bin/sed -i 's|copyString(settings\.nixStore, output);|copyString(getStore()->storeDir, output);|' $out/cbits/nix.cpp
${pkgs.gnused}/bin/sed -i 's|std::vector<std::string> sigs(validPathInfo->sigs\.begin(), validPathInfo->sigs\.end());|std::vector<std::string> sigs; for (const auto \& s : validPathInfo->sigs) sigs.push_back(s.to_string());|' $out/cbits/nix.cpp
${pkgs.gnused}/bin/sed -i 's|signDetached(message);|signDetached(message).to_string();|' $out/cbits/nix.cpp

The third sed catches both pre- and post-Lix-2.94 branches since they share the trailing pattern.

Why this went undetected

.github/workflows/website.yaml builds only the docs site — CI never realises .#default or nix-cache-server. Runtime artefacts come prebuilt from cache.nixos.asia/oss declared in flake.nix:2-5, so fresh cppnix source rebuilds are never exercised. Upstream aristanetworks/nix-serve-ng has effectively become Lix-onlyaristanetworks/nix-serve-ng#64 flagging cppnix 2.30+ incompatibility has been unanswered since 2026.

Consider adding a CI job that builds .#default (or just nix-cache-server) on Linux against cppnix in a fresh sandbox, so future API drift surfaces in CI rather than at deployment time on downstream forks.

Reproduction

nix build github:Joaqim/vira/cppnix-2.30-api-compat

Verified locally on cppnix 2.34.6: full build succeeds end-to-end, 3135-line build log shows zero error markers, produces vira-0.1.0.0 cleanly. Deployed and running as a systemd user service.


Generated by Claude Code (model claude-opus-4-7). API-drift diagnosis, sed-patch design, and local build verification were AI-orchestrated; patches were reviewed against cppnix 2.34.6 headers before opening this draft.

@srid

srid commented May 12, 2026

Copy link
Copy Markdown
Member

Thanks!

Upstream aristanetworks/nix-serve-ng has effectively become Lix-only — issue aristanetworks/nix-serve-ng#64 flagging cppnix 2.30+ incompatibility is unanswered since 2026-04-26.

Given this, I wonder if there's a alternative or fork that is official-Nix friendly?

@srid

srid commented May 12, 2026

Copy link
Copy Markdown
Member

By the way, I offered to contribute to upstream (so as to obviate mainaining this patch here), but so far they have not responded to me: aristanetworks/nix-serve-ng#48

@Joaqim Joaqim changed the title fix(nix-cache-server): cppnix 2.30+ API compatibility for nix-serve-ng source transform fix(nix-cache-server): patch nix-serve-ng for cppnix 2.30+ API drift May 13, 2026
@Joaqim
Joaqim marked this pull request as ready for review May 13, 2026 04:29
@Joaqim

Joaqim commented May 13, 2026

Copy link
Copy Markdown
Author

Yes, your opened issue surfaced during diagnosis, I choose to follow your established solution with just patching downstream instead.

@srid

srid commented May 13, 2026

Copy link
Copy Markdown
Member

@Joaqim Did you run CI on this PR? Because it fails with:

image

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