[Nix-dev] Re: [Nix-commits] SVN commit: nix - 14424 - MarcWeber - nixpkgs/trunk/pkgs/lib

Marc Weber marco-oweber at gmx.de
Sat Mar 7 16:46:07 CET 2009


> > added overridableDelayableArgs replacing applyAndFun
> This introduces yet another very complicated function with an inscrutable name
> ("overridableDelayableArgs") which I don't understand.  What is the purpose of
> this function, and what are the use cases?

It doesn't introduce a new concept. As I said it in the commit message
it replaces the older function applyAndFun. So it's not yet another
feature :-). I've written and told about some features in the past.
I'll repost a small use case here. Let me know if you have a better
name.  I'll rename instantly.


# most simple use case:
let default = (overridableDelayableArgs f) { ... initial args ... }
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ behaves like f but can do more

let x = default.merge { replace anything from "initial" args; }
    # you can even remove an attr as well..
    y = default.replace (x : removeAttr x ["foo"] )

So its simpler now because
default.merge
and
default.replace
say what is happening (compare this to .fun and .funMerge)
.merge can also concatenate values.

after all there is is also default.merged (r@{fixed, ...} : ...)
which allows passing required arguments later ("delayed").

One use case is a kernel derivation:
rec {
   derivation = overridableDelayableArgs stdenv.mkDerivation ({fixed,
...} : {
    name = "kernel-2.6.24";
    src = ..;

    availiblePatches = {
      tuxonIce = { ... }; # must fit 2.6.26
      foo = { ... }; # ...
    };

    patches = [ fixed.availiblePatches.foo ];
  });

  derviationKernelExperiment = derivation.merge ( {fixed, ...} : {
    name = "kernel-2.6.28";
    src = .. newer source ..;
    availiblePatches = {
      tuxonIce = { .. }; # this fits kernel 2.6.28
    };

    # patches does get the newer patch automatically now !

  });

}

Now you can use in your configuration.nix file:
kernel = pkgs.(one of the two derviations above).merge ({ fixed, ...} : {
  patches = [ fixed.availiblePatches.tuxonIce ]
    # this will pick the right tux on ice patch not matter wether you're
    # using the newer experimenatl kernel or the older one.
    #
    # Also note that this may either replace the patch list or ammend to
    # it depending on merge settings!
})

.merge ( { fixed, ..} : {} )
  is roughly the same as

.replace ( a@{ fixed, ..} : a // {} )
  where // is a function paying attention to merge settings.

So in the end you get what the function says:
* overridable args ( by .merge and .replace )
* delayable args by using fixed (which means you can use values may be
  passed laster)
But you can if you want without changing much code.
Its main purpose is prototyping (because the result is hard to read. I agree on that)

I want to write some more documentation and use cases introducing
the ideas step by step after having got up my vserver running.
I'd like to add this documentation to a wiki. Next thing to work on:
add support for adding databases automatically.. That's all why I want
to push the fix-style configuration system because this all can be done
easily..

Sincerly
Marc Weber



More information about the nix-dev mailing list