Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
nixos/nixos-option: add `--nesting-limit` option to avoid infinite recursions #79360
Motivation for this change
…cursions Until now, `nixos-option` tried to show all sub-attributes of a config value which can result in a never-ending output e.g. when running `nixos-option nixpkgs.pkgs` due to the fixpoint in this attribute set. By default, `nixos-option` only steps three levels into a data-structure (unless `--no-nesting-limit` is set). The limit can be modified using `--nesting-limit`.
I see two problems:
I suspect setting the nesting limit to 6 wouldn't help with nixpkgs.pkgs though. If a limit of 3 prints nixpkgs.pkgs once -- 10,000 packages -- then presumably a nesting limit of six would print 10,000^4 = 10 quadrillion packages. I didn't actually verify this count because ...
I also took a stab at better handling of nixpkgs.pkgs awhile back. Some alternative approaches to consider:
This can be mitigated by only doing this check for attrsets, and then it doesn't break anything.
The other problem is that it didn't actually catch all the fixedpoints. Maybe more careful implementation of this feature could fix this, or maybe it couldn't. (Can the repl printer do it? If yes, then this could also, since it uses the same technique.)
This actually worked pretty well.
I didn't pursue merging these because my attempt to use nixpkgs.pkgs ended in failure. I found that
in the NixOS manual is true and understated -- I found no way to take a NixOS system that defines nixpkgs.pkgs across the 19.03 → 19.09 upgrade because of the
I figured that I'd just learned what everyone else already knew -- that
If you end up continuing along this path, consider sticking
Maybe if printing large attr sets exactly once is what's desired, a combination of attr-set size checking and nesting limit would work: Have the nesting limit be 1, but only increment it when stepping into into huge attr sets. This allows small things like
You're absolutely right - that's AFAIK a known issue (and one of the main reasons why I'm using
Anyway, thanks a lot for the feedback, I agree that this change only makes sense if you have low recursion limits. Unless you're faster, I'll take a closer look at your suggestions next weekend and file another PR :)