[Nix-dev] applyAndFun again - kernel derivation proposal and example

Marc Weber marco-oweber at gmx.de
Tue Feb 24 13:08:21 CET 2009


> The merge and the replace function are waiting for an extra argument
> which can be define either inside the new argument or inside the
> initial version.
Yes. But it can also extend the initial version (see the patches example
in the kernel derviation)
 
> One thing which is not clear to me is:
>   args // { inherit fixed; }
> 
> because you can either use the old value and the new value at the same
> time, and apparently in real life example you are frequently using
> "fixed" attributes.  So I will suggest something like:
> 
>   { old = args; } // fixed
> 
> The old attribute will only be used once in your dummy example:

You're right. Of course you need an "old" value which you can extend.
So you suggest me using it this way?

deriv.merge ( attrs = let inherit (attrs) old;
  old // { my overridden stuff ? } )

I fear getting infinite recursion using
deriv.merge ( attrs = let inherit (attrs) old;
  attrs // { my overridden stuff ? } )

But I have to try that..

> >    res5 = let x = defaultOverridableDelayableArgs id { a = 7; };
> >          in (x.merge) ( x: { a = __add x.a 3; });
> >    # { a = 10; }
> Which illustrate that you want to extend something which was not made
> to be extensible.
Of course :-) That's what it is about: Changing things quickly without
duplicating anything else.
 
> > real world example :
> > ...
> 
> So the kernel derivation is no longer a derivation but it is a
> template which can be instantiated with different kernel version.
> This is very nice because with this we can factor code and keep the
> common stuff inside one derivationTemplate (could that be a better
> name for your work ?) and with can override some parts of it to get a
> similar template or derivation (which was a bit hacky with file with
> arguments)

Of course you can just use 
  overridableDelayableArgs customKernel {
    # default settings;
  }

to share the kernel derivation code.
Let me give you another fancy usage example:
You want to make sure that nobody does enable a patch by accident you
don't want to have, you neither want to miss an upstream patch.
You could use this:

kernel.merge (a : 
  assert eqLists (__attrNames a.availiblePatches) ["foo" "bar"]; {} )

You could add similar hooks if you wan't to get to konw version updates
etc.

I don't see how this could be done using a template..

Marc Weber



More information about the nix-dev mailing list