[Nix-dev] [Nix] Feature request for NixOS introspection.

Nicolas Pierron nicolas.b.pierron at gmail.com
Tue Dec 7 21:06:08 CET 2010


On Mon, Dec 6, 2010 at 23:04, Eelco Dolstra <e.dolstra at tudelft.nl> wrote:
> Why do you need to evaluate it strictly?  That seems dangerous (even if you
> could catch all exceptions) due to the risk of infinite recursion.

After some testing on my current work I succeed to make a working
prototype of a "strict" function implemented as:

  strict = n: x :
    let
      traverse = limit: x: with builtins;
        if limit == 0 then true else let l = sub limit 1; in
        if isAttrs x then
          if x ? outPath && isString x.outPath
          then true      else all (traverse l) (attrValues x)
        else if isList x then all (traverse l) x
        else true;
    in
      assert traverse n x; x;

Unfortunately, I still have issues with the garbage collector when I
use it with n > 1 on the whole NixOS, and the result seems good with
values of n >= 3.  The memory is going to 4G and nix-instantiate get
killed.

One hand a possible workaround could be to split the options in
multiple sets and evaluate them separately, but I found this a bit
hacky.  On the other hand, making this a primitive may solve both the
garbage collection issue by not keeping in the cache the result of the
strict computation and by replacing the attrValues function call.

The difference between the strict function of debug.nix is that there
is a isString on the outPath and that there is no need to check the
precise type if it is not recursive (because previous isAttrs & isList
are already strict functions).

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/



More information about the nix-dev mailing list