[Nix-dev] joining attribute sets recursively

Florian Friesdorf flo at chaoflow.net
Mon Jan 16 18:28:14 CET 2012


On Mon, 16 Jan 2012 16:50:10 +0100, Eelco Dolstra <e.dolstra at tudelft.nl> wrote:
> On 16/01/12 15:37, Florian Friesdorf wrote:
> 
> > config = mkIf cfg.enable {
> >   ...
> >   powerManagement.cpuFreqGovernor = "ondemand";
> > } // cfg.aggressive ? {
> >   ...
> >   powerManagement.scsiLinkPolicy = "min_power";
> > } : {};
> 
> Indeed it would be good to have a way of writing this down in a nice way.
> (Using two different modules as Marc suggested isn't very elegant.)  Maybe
> something like
> 
>   config = mkUnion
>     [ (mkIf cfg.foo {
>         ... attrs ...
>       })
>       (mkIf cfg.bar {
>         ... attrs ...
>       })
>       ...
>     ];

hmm - not sure whether mkUnion or mkMerge (as Marc suggests) cuts
it. The term *merge* is pretty generic and it would depend on a merge
algorithm what happens. A union for sets is defined as all elements
without duplicates, with a quick search I could not find a definition
for key/val pairs / associative arrays / attribute sets. Maybe looking
at the possible behaviours helps finding a name:

mkX [ {
  a = 1;
  b = 1;
  c.a = 1;
} {
  b = 2;
  c.b = 2;
  d = 2;
} ]

possible results:
- error because of colliding b
- first value taken: { a = 1; b = 1; c = { a = 1; b = 2 }; d = 2}
- last value taken:  { a = 1; b = 2; c = { a = 1; b = 2 }; d = 2}
- both values taken: { a = 1; b = [1 2]; c = { a = 1; b = 2 }; d = 2}

-- 
Florian Friesdorf <flo at chaoflow.net>
  GPG FPR: 7A13 5EEE 1421 9FC2 108D  BAAF 38F8 99A3 0C45 F083
Jabber/XMPP: flo at chaoflow.net
IRC: chaoflow on freenode,ircnet,blafasel,OFTC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20120116/385eeecb/attachment-0001.bin 


More information about the nix-dev mailing list