[Nix-dev] joining attribute sets recursively

Florian Friesdorf flo at chaoflow.net
Mon Jan 16 18:13:30 CET 2012


On Mon, 16 Jan 2012 16:42:50 +0100, Marc Weber <marco-oweber at gmx.de> wrote:
> > Now for one the syntax is incorrect 
> try this:
>   cfg.enable ({
>     ...
>   } // (if cfg.aggressive then { .. } else { .. } ))

I fail to see the difference to what I tried, which resulted in infinte
recursion, which you also explain below.

> > will be overriden with the value from the second attribute set.
> there are merge functions defined in lib - but they are overkill.
> The solution is to move and duplicate the mkIf or use two different
> modules. I suggested to pierron adding a mkMerge function for exactly
> that reason - and because mkElse can be used in uncommen ways.
> 
> I also rewrote the config system making this easy - but I have done no
> testing yet.
> 
> Try this:
> 
> config.powerManagement = {
>    cpuFreqGovernor = "ondemand";
>    scsiLinkPolicy = if (cfg.aggressive) then "min_power" else mkNoDef; // or something similar, grep nixos code for its usages.
> }

It's not just the scsiLinkPolicy but also a jobs definition and
eventually more.

> if mkNoDef doesn't work try the // trick shown above.
> 
> >> [.. infinite recursion ]
> The problem is that cfg.aggressive can't be evaluated without evaluating
> the top level config attrs. But that contains the condition!
> 
> Let me make it obvious:
> 
> config = mkIf cfg.enable ({
>   aggressive = true;
> } // (if cfg.aggressive then {
> 
> } else { }));
> 
> in order to evaluate aggressive the module system has to evaluate the if
> branch.. but in order to know whether it should be evaluated it has to
> evaluate the condition .. in order to ... :-) You get the point.

see above

-- 
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/dd5d42b5/attachment.bin 


More information about the nix-dev mailing list