I’ve been having a really hard time trying to figure out this simple transformation in the nix language, not finding any examples or tutorial subjects on it either.
Starting with an attrset that looks sort of like this:
{
"folder1"
{
path = "~/Folder1";
subscribers = ["alice" "bob"];
}
"folder2"
{
path = "~/Folder2";
subscribers = ["alice"];
}
}
I want to transform it into an attrset that looks like this:
{
"/wherever/alice/Folder1"
{
source = "/somewhere/Folder1";
}
"/wherever/bob/Folder1"
{
source = "/somewhere/Folder1";
}
"/wherever/alice/Folder2"
{
source = "/somewhere/Folder2";
}
}
If subscribers isn’t a list, this is very easy:
lib.attrsets.mapAttrs' (
name: value:
lib.attrsets.nameValuePair (makeNameFn value.path value.subscriber) (
makeSourceFn value.path value.subscriber
)
) srcFolders
But it’s not clear how I can generate multiple nameValuePair inside of the mapAttrs, or genAttrs for that matter. I’ve tried lists.forEach value.subscribers (…), but that simply errors, claiming that there is no name member present (which I thought nameValuePair would have handled???)
Anyhow, this is all incredibly confusing and nearly impossible to visualize, so any help is appreciated.