Problem
When regenerating C API bindings, nix_api_store/path_info.h contains a forward declaration typedef struct Store Store; that is identical to the one in nix_api_store.h. Because hs-bindgen's external binding spec matches on (cname, header) pairs, it treats these as distinct types and generates a duplicate Store type in Generated.Nix.Store.PathInfo.
This means all generated functions that use Store end up referencing one or the other depending on generation order, requiring castPtr at call sites in the high-level bindings.
Current workaround
castPtr in Nix/Unsafe/Store.hs (for nix_store_query_path_info_json)
castPtr in Nix/Unsafe/Expr.hs (for nix_eval_state_builder_new, since nix_api_expr.h transitively includes path_info.h)
Root cause
hs-bindgen's --external-binding-spec mechanism matches C type declarations by both cname and headers fields. When the same struct Store is forward-declared in multiple headers, the spec entry for one header doesn't suppress generation from the other.
Upstream
This should ideally be fixed in hs-bindgen. No existing issue covers this exact case (searched their tracker). The fix would be to match external binding specs by cname alone (or at least allow header-agnostic matching).
Problem
When regenerating C API bindings,
nix_api_store/path_info.hcontains a forward declarationtypedef struct Store Store;that is identical to the one innix_api_store.h. Because hs-bindgen's external binding spec matches on(cname, header)pairs, it treats these as distinct types and generates a duplicateStoretype inGenerated.Nix.Store.PathInfo.This means all generated functions that use
Storeend up referencing one or the other depending on generation order, requiringcastPtrat call sites in the high-level bindings.Current workaround
castPtrinNix/Unsafe/Store.hs(fornix_store_query_path_info_json)castPtrinNix/Unsafe/Expr.hs(fornix_eval_state_builder_new, sincenix_api_expr.htransitively includespath_info.h)Root cause
hs-bindgen's
--external-binding-specmechanism matches C type declarations by bothcnameandheadersfields. When the samestruct Storeis forward-declared in multiple headers, the spec entry for one header doesn't suppress generation from the other.Upstream
This should ideally be fixed in hs-bindgen. No existing issue covers this exact case (searched their tracker). The fix would be to match external binding specs by
cnamealone (or at least allow header-agnostic matching).