-
I just read the chapter about merging in the docs. Is it possible to enable merging of arrays using an annotation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
At the moment Nickel doesn't have a builtin way of merging arrays using This commutativity requirement is also one reason why we wouldn't want to implement merging arrays as sets by default. It would only end up being commutative for a (hypothetical) type of sorted arrays. Another consideration is that elements in arrays are rather difficult to override. Most "patching" implementations that I know of would do this by specifying some sort of path to the element, including an index into the array. But that is extremely fragile. There is an alternative solution in the NixOS module system where instead of building up an array, they build up a directed graph of elements. For example, this is how the stage1 init script is constructed. In essence, instead of just putting an element into an array, you specify ordering constraints and a unique name for the element. Then a postprocessing step finds a topological ordering of the resulting graph and produces an actual array in that order when it is required. This same functionality could be implemented in Nickel as a library and personally I'd prefer it over ad-hoc merging constructions for arrays. But it would of course be a decent amount of work and noone has volunteered to iron out the details, so far. |
Beta Was this translation helpful? Give feedback.
At the moment Nickel doesn't have a builtin way of merging arrays using
&
. When overriding was first suggested in RFC001, there was also a proposal to add custom merge functions. Those would be a principled way of achieving what you're asking for. Namely, you would annotate a record field with a custom function that gets passed two values to be merged in the event of a conflict and it would be able to do just about anything with those values; it might be advisable to implement an associative and commutative merge, though.This commutativity requirement is also one reason why we wouldn't want to implement merging arrays as sets by default. It would only end up being commutative for a (hypo…