[Nix-dev] concatAttrs :: [attrSet] -> attrSet ?

Sergiu Ivanov sivanov at colimite.fr
Sun May 28 14:58:07 CEST 2017


Hello Linus,

Thank you for you prompt reply!

Thus quoth  Linus Heckemann  at 12:24 on Sun, May 28 2017:
> On 28/05/17 13:18, Sergiu Ivanov wrote:
>>
>> concatAttrs = attrList: pkgs.lib.fold (x: y: x // y) {} attrList;
>>
>> Do you see any isssues with such an implementation?
>>
>
> Looks like a sensible way to do it to me, though I'd be surprised if it
> doesn't already exist in nixpkgs.

Yeah, that's what I thought as well.

> Do keep in mind that // is not commutative — the order matters when the
> two sets contain the same key — but other than that I don't see any
> issues.

Indeed, right, the function I wrote should probably be called iterUnion,
to avoid insinuating any special treatment of repeated keys.

My use case is quite specific. I do this, approximately:

  let func name = { "${name}" = something name; };
  in concatAttrs (map func [ "name1" "name2" ])

I don't expect to have repeated names, so key repetitions isn't
something likely to happen.

> You might also want to look at the merging logic used for nixos
> modules (lib/modules.nix), although that's significantly more complex.

Oh, thank you for the reference (I actually took a look!), but in my
case I only merge three-element attribute sets.  My concatAttrs is
essentially me playing around with Nix more than anything else :-)

--
Sergiu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <https://mailman.science.uu.nl/pipermail/nix-dev/attachments/20170528/abebac59/attachment.sig>


More information about the nix-dev mailing list