New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/nixos-option: add --nesting-limit
option to avoid infinite recursions
#79360
Conversation
…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 :) |
Motivation for this change
Until now,
nixos-option
tried to show all sub-attributes of a configvalue 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
.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)