What's easiest way of generating multiple items from array in Nix module

I want to generate a multiple items from array. Something along the lines:

{ ... }
let 
    foo = [{...} ...]
    bar = lib.forEach foo (f: {
      x."$f.x".a = ...;
      y."$f.y".a = ...;
    });
in
{
     // ...
}

What is the most idiomatic way of doing this?

Not entirely sure of what the goal is. Do you want to make a new list, or modify an existing attributeset?

For generating a new list you can use builtins.map.

There’s a similar map function for attribute sets lib.attrsets.mapAttrs .

Otherwise (as a newbie myself), your code sample looks like the way to go.

I have a list and function Any -> AttrSet. I want to map function over list and include the result into module.

Alternatively I have a list of AttrSet and I want to include all elements of it into module.

I guess I want the equivalent of foldMap where I AttrSet is monoid where (<>) is whatever nix is doing with configuration.

And then I wand to (<>) it with the rest of the module.

I think you want genAttrs.