nixos/nixos-option: fix evaluator to render a full submodule entry#75439
nixos/nixos-option: fix evaluator to render a full submodule entry#75439Ma27 merged 4 commits intoNixOS:masterfrom
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"; } ...
lheckemann
left a comment
There was a problem hiding this comment.
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
ma27is 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 foundcondition 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
sandboxinnix.confon non-NixOS linux)nix-shell -p nix-review --run "nix-review wip"./result/bin/)nix path-info -Sbefore and after)Notify maintainers
cc @chkno