Take the following set as an example:
{
top1 = {
middle1 = {
bottom1 = 1;
};
};
top2 = {
middle2 = {
bottom2 = 2;
};
};
}
I want to apply n
updates to this set in the following format:
{
"top1.middle1.bottom1" = 99;
"top2.middle2.bottom2" = 88;
# `n` entries
}
The result should be:
{
top1 = {
middle1 = {
bottom1 = 99;
};
};
top2 = {
middle2 = {
bottom2 = 88;
};
};
}
I’ve figured out how to apply one update to the set using a function I wrote:
with pkgs.lib;
updateValue = (config: path: value:
let
parts = splitString "." path;
in
overrideExisting config (setAttrByPath parts value)
);
With this, I can do something like:
> updateValue set "top1.middle1.bottom1" 99
And get the expected result. Where I’m stuck is figuring out how to apply the entire list of updates recursively and end up with the finalized result. I can use mapAttrsToList
to map updateValue
across the set, but then I end up with a list of partially modified sets that I have to somehow combine again.
I’m hoping there’s just some internal lib function I’m missing that does all of this. Otherwise, I could use some help