!lTqhfnNvIkcEackxxk:matrix.org

Nix Bindings

84 Members
Nix C API https://github.com/NixOS/nix/blob/master/doc/manual/src/c-api.md, language-specific bindings, and their use cases (currently broken link: https://nixos.org/manual/nix/unstable/c-api)21 Servers

Load older messages


SenderMessageTime
7 Feb 2025
@terrorjack:matrix.orgterrorjack joined the room.22:45:43
8 Feb 2025
@terrorjack:matrix.orgterrorjack set a profile picture.02:24:32
@terrorjack:matrix.orgterrorjack removed their profile picture.02:25:07
12 Feb 2025
@marcel:envs.net@marcel:envs.net joined the room.17:20:19
@idioticself55:matrix.org@idioticself55:matrix.org left the room.22:24:37
13 Feb 2025
@sodiboo:gaysex.cloudsodiboo joined the room.20:54:39
@sodiboo:gaysex.cloudsodiboo in [nix_create_external_value](https://hydra.nixos.org/build/289480061/download/1/html/group__Externals.html#ga3e2edcbbd07dc5c34509de1d7a9773a7), the API takes a pointer void* v in, and this is basically called user_data in most contexts. I get that the returned ExternalValue* is owned by the nix evaluator, but what about my void* v? obviously Nix doesn't know how to free this, so i'd expect to see a free callback in [NixCExternalValueDesc](https://hydra.nixos.org/build/289480061/download/1/html/structNixCExternalValueDesc.html#details), but there is no such function.

i also couldn't easily find any way to detect when a value, in general, is freed (why would there be? only matters for external). so i don't know how my value will ever be freed.

am i just meant to leak my void* v?
23:00:24
@roberthensing:matrix.orgRobert Hensing (roberth)

This seems to be an omission in both the evaluator implementation and in the C API for it. A virtual destructor does exist for ExternalValueBase, but since Value relies entirely on GC and mkExternal doesn't register a finalizer, it seems that this destructor is never called.

It's worth noting that the GC used by Nix can not guarantee that finalizers are called in the first place, as it is a conservative GC, so it is best not to rely on finalization. (Also GC will not run before the process exits, unless e.g. it's the Nix CLI and NIX_SHOW_STATS=1)

Nonetheless, it should be added, because release a resource most of the time, or even sometimes, is better than never.

I'm a bit wary of adding it without ever calling it, because that will cause untested code to start running in the future, which could be a huge surprise when it starts causing crashes etc.
So either the whole thing needs to be implemented correctly and/or we add a test utility that forces the finalization, just for the purpose of unit testing.

23:39:14
@roberthensing:matrix.orgRobert Hensing (roberth)I've opened https://github.com/NixOS/nix/issues/1247023:57:22
14 Feb 2025
@sodiboo:gaysex.cloudsodiboo

also, I noticed the equality function does not take a value descriptor for other. I guess that's because most programs won't have multiple external types. I also happen to be using Rust, so ultimately my void* v will be something like dyn Any or a wrapper containing an Any; so naturally I can use that to check type identity. but it is also possible to load multiple plugins, right? what if several add external types? then I have no idea what the other value has for a type.

is the value descriptor checked for equality/identity first? that's the only reasonable way this API makes sense, and it's consistent with the documented behavior of not being equal if the other value is of a primitive type. but it's not documented that the equality does any such check before invoking the callback.

05:26:15
@sodiboo:gaysex.cloudsodibooactually, for that matter, it looks like it's impossible to query an external value's type, in general, to check if it belongs to "this library" or not. guess i just have to pray that it is, indeed, part of my library?08:10:09
@roberthensing:matrix.orgRobert Hensing (roberth)Seems to be just an oversight. I'd be happy to accept PRs for these things, or even issues to track in the C API milestone08:53:42
@sodiboo:gaysex.cloudsodibooyeah i guess that's why it's not like, stable yet, lol.09:17:35
@roberthensing:matrix.orgRobert Hensing (roberth)The original contributor for the C API tried their best, but their use case did not include externals. We could strip out the externals and call it stable if you prefer, or we could accept the status quo, or we could accept contributions. I think we're going for the latter, but we could change our strategy16:21:15
15 Feb 2025
@benjb83:matrix.orgBenjB83 joined the room.10:16:44
@benjb83:matrix.orgBenjB83 changed their display name from Benjamín Buske to BenjB83.10:43:21
@sodiboo:gaysex.cloudsodiboo for functions taking a nix_get_string_callback, when they return NIX_OK, is the string callback guaranteed to have been called exactly once, and never again? 15:41:33
@roberthensing:matrix.orgRobert Hensing (roberth)I believe that's the contract yes. I wouldn't rule out multiple calls for sets of strings or something in the future, but that will be clearly documented then15:58:51
16 Feb 2025
@kristijan.zic:matrix.orgKristijanZic joined the room.01:04:36
17 Feb 2025
@marcusramberg:matrix.orgMarcus changed their profile picture.21:38:25
21 Feb 2025
@me:linj.techlinj joined the room.11:51:44
5 Mar 2025
@phanirithvij:matrix.orgloudgolem joined the room.02:41:22
17 Mar 2025
@acidbong:envs.net@acidbong:envs.net joined the room.11:38:50
@acidbong:envs.net@acidbong:envs.netafternoon, fellers and felines i hope this is the right channel to ask: is there a language-agnostic API for Nix daemon or does it require C bindings? i'd love to try to use a different language instead of Nix11:44:47
@roberthensing:matrix.orgRobert Hensing (roberth)Reimplementations exist, but I don't have recommendations. Using the C API would be possible, but the store layer C API is very minimal at the moment; just enough to supplement the evaluator C API; not much more than the ability to have a Store, a StorePath and build a derivation20:31:18
@acidbong:envs.net@acidbong:envs.netgot it and I just realized that i'd rather use a transpiler to Nix to do what i want anyway, thx20:34:16
@acidbong:envs.net@acidbong:envs.net left the room.20:34:22
19 Mar 2025
@o-santi:matrix.orgLeonardo Santiagoshould I be able to copy derivation closures between remote stores without passing through my own local machine?12:08:35
@o-santi:matrix.orgLeonardo SantiagoI tried doing it through the FFI but it grinds to a halt and never returns12:08:52
@xokdvium:matrix.orgSergei Zimmerman (xokdvium) changed their display name from xokdvium to Sergei Zimmerman (xokdvium).21:12:16

Show newer messages


Back to Room ListRoom Version: 10