-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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: fix evaluator to render a full submodule entry #75439
Conversation
This patch doesn't fix this problem for me. I still get the same "Attribute not found" error message when I run I agree that this should be fixed. I propose a slightly different way to fix it: chkno@35ac88d (I'm not sure how the PR mechanics work from here. Do I start a separate pull request? Do you switch the source branch of this pull request from Ma27:submodule-fixes-for-nixos-option to chkno:submodule-fix-for-nixos-option? Do you copy that commit to this PR branch?) |
When running e.g. `nixos-option users.users.ma27`, the evaluation breaks since `ma27` is the attribute name in `attrsOf (submodule {})`, but not a part of the option tree and therefore breaks with the following errors: ``` error: At 'ma27' in path 'users.users.ma27': Attribute not found An error occurred while looking for attribute names. Are you sure that 'users.users.ma27' exists? ``` This happens since the option evaluator expects that either the option exists or the option is a submodule and the "next" token in the attribute path points to an option (e.g. `users.users.ma27.createHome`). This patch checks in the `Attribute not found` condition if the attribute-path actually exists in the config tree. If that's true, a dummy-attrset is created which contains `{_type = "__nixos-option-submodule-attr";}`, in that case, the entire entry of the submodule will be displayed.
fddf656
to
e0780c5
Compare
Oof.... you're right, that was an avoidable mistake (it worked in my case due to a coincidence :/). Updated the code now. (I'd prefer to have the attribute printed when running Regarding contributions from your side: feel free to open a PR against this branch on my fork :) |
I created Ma27#2 to pull that change into this PR. |
1. This makes aggregates of submodules (including the very important "nixos-option users.users.<username>" case) behave the same way as any other you-need-to-keep-typing-to-get-to-an-option-leaf (eg: "nixos-option environment"). Before e0780c5: $ nixos-option users.users.root error: At 'root' in path 'users.users.root': Attribute not found An error occurred while looking for attribute names. Are you sure that 'users.users.root' exists? After e0780c5 but before this change, this query just printed out a raw thing, which is behavior that belongs in "nix eval", "nix-instantiate --eval", or "nix repl <<<": $ nixos-option users.users.root { _module = { args = { name = "root"; }; check = true; }; createHome = false; cryptHomeLuks = null; description = "System administrator"; ... After this change: $ nixos-option users.users.root This attribute set contains: createHome cryptHomeLuks description extraGroups group hashedPassword ... 2. For aggregates of other types (not submodules), print out the option that contains them rather than printing an error message. Before: $ nixos-option environment.shellAliases.l error: At 'l' in path 'environment.shellAliases.l': Attribute not found An error occurred while looking for attribute names. Are you sure that 'environment.shellAliases.l' exists? After: $ nixos-option environment.shellAliases.l Note: showing environment.shellAliases instead of environment.shellAliases.l Value: { l = "ls -alh"; ll = "ls -l"; ls = "ls --color=tty"; } ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this and it works nicely, but I haven't reviewed the code changes.
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review-may-2019/3032/99 |
…tion nixos/nixos-option: fix evaluator to render a full submodule entry
Motivation for this change
When running e.g.
nixos-option users.users.ma27
, the evaluation breakssince
ma27
is the attribute name inattrsOf (submodule {})
, but nota part of the option tree and therefore breaks with the following
errors:
This happens since the option evaluator expects that either the option
exists or the option is a submodule and the "next" token in the
attribute path points to an option (e.g.
users.users.ma27.createHome
).This patch checks in the
Attribute not found
condition if the attribute-pathactually exists in the config tree. If that's true, a dummy-attrset is created
which contains
{_type = "__nixos-option-submodule-attr";}
, in that case, theentire entry of the submodule will be displayed.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @chkno