[Nix-dev] Re: ‘nix-instantiate --xml’ and self-referential attrsets

Ludovic Courtès ludo at gnu.org
Sun Apr 10 22:22:54 CEST 2011


Hello,

Eelco Dolstra <e.dolstra at tudelft.nl> writes:

> On 04/09/2011 05:29 PM, Ludovic Courtès wrote:
>
>> When parsing this with SAX, the ‘repeated’ element is seen before the
>> first occurrence of the derivation, which is a problem: the program that
>> parses it doesn’t have anything to repeat yet.
>
> It depends on what you're trying to do in the SAX parser, but can't
> you just skip the "repeated" node?

Skip and resolve later?  That’s doable, but it makes things slightly
more complex.

(Time passes...)

Now that I think of it, it's probably the best thing to do since it
forces the user to coalesce occurrences of the same derivation.

>>
>>               if (drvsSeen.find(e) == drvsSeen.end()) {
>> -                drvsSeen.insert(e);
>>                   showAttrs(attrs, doc, context, drvsSeen, location);
>> +                drvsSeen.insert(e);
>
> Wouldn't this introduce a potential infinite recursion?  Also,
> wouldn't it cause the same derivation to be printed twice?

Well, it causes the offending derivation to be printed more than once.
In the original example, it becomes:

--8<---------------cut here---------------start------------->8---
<?xml version='1.0' encoding='utf-8'?>
<expr>
  <derivation drvPath="/nix/store/b1pmg2fhxnlnxy0z9hfglgyk66wpa2ar-x.drv" outPath="/nix/store/fw6flnp42lqn9i62aknpch29sadds5pi-x">
    <attr column="11" line="4" name="b" path="/home/ludo/src/nixpkgs/maintainers/scripts/gnu/self-ref.nix">
      <derivation drvPath="/nix/store/b1pmg2fhxnlnxy0z9hfglgyk66wpa2ar-x.drv" outPath="/nix/store/fw6flnp42lqn9i62aknpch29sadds5pi-x">

[...]

        </attr>
      </derivation>
    </attr>

[...]

  </derivation>
</expr>
--8<---------------cut here---------------end--------------->8---

In Nixpkgs/trunk it makes the result slightly larger.

Thanks,
Ludo'.



More information about the nix-dev mailing list