!lTqhfnNvIkcEackxxk:matrix.org

Nix Bindings

69 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)18 Servers

Load older messages


SenderMessageTime
21 Jan 2025
@o-santi:matrix.orgLeonardo Santiago ...all of them? As I've stated before, I'm trying to reproduce the nix develop behavior utilizing a different caching mechanism for evaluation 03:00:54
@o-santi:matrix.orgLeonardo Santiago the problem is that I realised that source $stdenv/setup during shell entering is very slow and nix develop can only be so fast because it also caches that behind a derivation 03:01:35
@o-santi:matrix.orgLeonardo Santiago I'd like to do what it does (cache source $stdenv/setup by making it an output of a derivation) but in order to do it I'd need to fiddle with the actual derivation 03:02:19
@o-santi:matrix.orgLeonardo Santiago specifically, I'd like to be able to write it back to the store, so that it can be built, but if I just do it the dumbest way possible (copy the parsed env vars and pass it to derivation primop) then inputSrc and inputDrvs get empty 03:04:49
@o-santi:matrix.orgLeonardo Santiago I know that it's not strictly necessary to get it working in this specific case, but it's expected from the library I'm writing that parse_drv(parse_drv(path).serialize()) == parse_drv(path) 03:11:58
@o-santi:matrix.orgLeonardo Santiago * specifically, I'd like to be able to write it back to the store, so that it can be built, but if I just do it the dumbest way possible (copy the parsed env vars and pass it to derivation primop) then inputSrc and inputDrvs are generated empty 12:33:37
24 Jan 2025
@idioticself55:matrix.org@idioticself55:matrix.org joined the room.14:19:47
@o-santi:matrix.orgLeonardo Santiagoabout memory management16:45:11
@o-santi:matrix.orgLeonardo Santiago let's say I have a Value, how am I supposed to free it? there's nix_gc_decref and nix_value_decref 16:45:50
@o-santi:matrix.orgLeonardo Santiago * let's say I have a Value, how am I supposed to free it? there's nix_gc_decref and nix_value_decref and there's not a clear explanation on which should be used when. 16:46:30
@o-santi:matrix.orgLeonardo Santiago after calling nix_alloc_value, if I don't cal nix_value_incref nor nix_gc_incref, which one should I use to decrement the gc? and am I expected to run anything else in order to force it to be freed? 16:47:33
@o-santi:matrix.orgLeonardo Santiago * after calling nix_alloc_value, if I don't cal nix_value_incref nor nix_gc_incref, which one should I use to decrement the gc (or both?)? and am I expected to run anything else in order to force it to be freed? 16:47:43
@o-santi:matrix.orgLeonardo Santiago * after calling nix_alloc_value, if I don't cal nix_value_incref nor nix_gc_incref, which one should I use to decrement the gc? should I use both? and am I expected to run anything else in order to force it to be freed? 16:48:13
@o-santi:matrix.orgLeonardo Santiago the documentation in nix_alloc_value says that one should use nix_gc_decref but there's no explanation regarding when (if?) to use nix_value_decref 16:48:43
@o-santi:matrix.orgLeonardo Santiago okay, looking at the code it's clear that value_decref is just a gc_decref behind the curtains so it shouldn't make a difference, but the API sure could use some explanation/refinement here 16:52:16
@o-santi:matrix.orgLeonardo Santiago one of my concerns is that nix flake check takes way too much memory (32GB~) as we have a ton of hosts to check (200~), and surely that is because it's not freeing the previous hosts while iterating, and so my idea was to try to explicitly evaluate and deallocate each attribute 17:02:02
@o-santi:matrix.orgLeonardo Santiago ...but the memory is not being freed? I don't understand what is going on, there should only be one ref as the Value's themselves are not being incref'd, and on rust Drop it's calling decref to hopefully free it once and forall 17:03:33
@o-santi:matrix.orgLeonardo Santiagobut that doesn't seem to be happening? or at least, the memory footprint isn't getting any smaller17:03:49
@roberthensing:matrix.orgRobert Hensing (roberth) nix_alloc_value should be released with nix_value_decref. The main benefit for now is that it has a more specific type, but future evaluators might hypothetically require this 17:58:13
@roberthensing:matrix.orgRobert Hensing (roberth)as for the garbage collection, neither bdwgc (a conservative gc) nor the interpreter data model are particularly conducive to gc. See https://github.com/NixOS/nix/issues/8621, and for the representation of closures: https://github.com/NixOS/nix/issues/828518:01:13
@roberthensing:matrix.orgRobert Hensing (roberth) Leonardo Santiago: ^ 18:01:23
@o-santi:matrix.orgLeonardo Santiagonot sure I 100% understand the issue, I'm not holding a reference to a closure18:08:51
@o-santi:matrix.orgLeonardo Santiago even when droping the whole EvalState it still doesn't free the memory 18:12:14
@o-santi:matrix.orgLeonardo Santiago

the specific program I'm using is akin to

nix = EvalState()
# 8MB ~ ish footprint
attribute_set = nix.eval_file(...)
# 8MB
value = attribute_set.get("key") # wrapper around `get_attr_byname` 
# 500 MB
drop(value)
# 500 MB
drop(attribute_set)
# 500 MB
drop(nix)
# 500 MB
18:15:30
@o-santi:matrix.orgLeonardo Santiago even if I'm not freeing memory when dropping individual values (I can see some issues of why it might not decrease), I don't understand why dropping the actual EvalState doesn't work 18:18:50
@o-santi:matrix.orgLeonardo Santiago and yes, I'm using eval_state_free 18:18:56
@o-santi:matrix.orgLeonardo Santiagoalbeit, this is a little bit clunky to assert as I'm testing this through the pyo3 library created from the rust library18:29:05
@o-santi:matrix.orgLeonardo Santiago* albeit, this is a little bit clunky to assert as I'm testing this through the pyo3 library created from the rust library, through the python repl18:29:31
@o-santi:matrix.orgLeonardo Santiago but I'm certain that the drops are executing correctly by virtue of println!("dropping val") inside the impl Drop statement 18:30:07
@o-santi:matrix.orgLeonardo Santiago * but I'm certain that the drops are executing correctly (ie. after del nix_state by virtue of println!("dropping val") inside the impl Drop statement 18:30:46

Show newer messages


Back to Room ListRoom Version: 10