On 28/05/17 13:18, Sergiu Ivanov wrote:
> Hello,
> 
> I found myself in the need of a function which would take a list of
> Nix attribute sets and concatenate them to produce one big attribute
> set:
> 
> nix-repl> concatAttrs [ {x=1;} {y=2;} ]
> {x=1; y=2;}
> 
> I did quite some research online and in nixpkgs source tree and found
> a lot of cool functions, but nothing resembling to concatAttrs.
> 
> Does such a function exist?
> 
> 
> In the meantime, I ended up writing the following definition:
> 
> 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.

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. You might also want to look at the merging logic used for nixos
modules (lib/modules.nix), although that's significantly more complex.
_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
https://mailman.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to