Skip to content

Migrate to C API - #653

Draft
roberth wants to merge 1 commit into
masterfrom
c-api
Draft

Migrate to C API#653
roberth wants to merge 1 commit into
masterfrom
c-api

Conversation

@roberth

@roberth roberth commented Nov 21, 2025

Copy link
Copy Markdown
Member

Goals

  • Get rid of Template Haskell, which remains problematic for tooling reasons
  • Use a more stable API necessitating fewer compatibility updates

TODO

  • generate code and use C API store type
  • more testing
  • get upstream hs-bindgen to emit no TH (see branch)
  • figure out interrupts without ReceiveInterrupts _;
  • migrate all calls
  • migrate calls that require custom C code
  • make hs-bindgen available in Nixpkgs
  • follow-up: upstream custom C code to become part of C API (and polyfilling until available)

TH trouble:

This commit makes the first incremental step toward replacing inline-c
with the Nix C API by changing the Store type to wrap a C API Store
pointer instead of a C++ ref<Store>.

Changes:
- Store now wraps Ptr CAPI.Store instead of Ptr (Ref NixStore)
- openStore and withStoreFromURI now use nix_store_open from C API
- Delete instance uses nix_store_free
- All inline-c code dereferences through C API Store to access C++ Store
- Added C API internals header to access Store::ptr field
- Created nix_store typedef to disambiguate from C++ nix::Store
- Updated Context to map nix_store type name to CAPI.Store
- Qualified all C++ Store and StorePath references in inline-c blocks

The C API Store struct wraps a nix::ref<nix::Store> in its ptr field,
which we dereference in inline-c code using: $(nix_store* store)->ptr
@roberth roberth changed the title Migrate to C API (partially) Migrate to C API Nov 21, 2025
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.

1 participant