-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
lib/options/showOption: fix quoting of attr-names that are not identifiers #194035
Conversation
We shouldn't have been mixing placeholders and unescaped identifiers in the first place. |
@roberth do you think it's possible to implement that without noticeable breaking changes? If yes, I'm happy to give it a try, but otherwise I'd say that this is the pragmatic solution to improve the situation a little bit at least :) |
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.
While I do think the correct solution is feasible, I don't mind getting there in steps.
…to indicate a function inside an option structure The motivation is to have a single identifier for that. Useful for the next commit where I'll try to escape option-parts correctly (options can be any kind of strings, but unless these are Nix identifiers, they must be quoted). Since `<function body>` (or `<name>`/`*`) are special identifiers in error messages and the manual, we need a unique way to mark an option part as function call because these are not to be quoted.
671fc21
to
4cc267c
Compare
…fiers Personally, I think that warnings such as warning: The option `services.redis.enable' defined in `/home/ma27/Projects/nixpkgs/test.nix@node-vm' has been renamed to `services.redis.servers..enable'. are fairly confusing because of the `..` and it's more correct to actually quote that. With this change the warning now looks like this: warning: The option `services.redis.enable' defined in `/home/ma27/Projects/nixpkgs/test.nix@node-vm' has been renamed to `services.redis.servers."".enable'. While implementing that I realized that you'd have a similar problem whenever you use attribute-names that aren't identifiers, e.g. services.nginx.virtualHosts."example.org".locations."/".invalid = 23; now results in the following error: error: The option `interactive.nodes.vm.services.nginx.virtualHosts."example.org".locations."/".invalid' does not exist. Definition values: - In `/home/ma27/Projects/nixpkgs/test.nix@node-vm': 23 Of course there are some corner-cases where this won't work: when generating the manual, you display submodules like this: services.nginx.virtualHosts.<name> Since `<name>` isn't a value, but an indicator for a submodule, it must not be quoted. This also applies to the following identifiers: * `*` for `listOf submodule` * `<function body>` for `functionTo` This might not be correct if you actually have a submodule with an attribute name called `<name>`, but I think it's an improvement over the current situation and for this you'd probably need to make even more complex changes to the module system.
4cc267c
to
6396482
Compare
Thanks a lot for your review! I addressed all of your coments :) |
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.
Looks ok to me
@infinisil please review
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.
This currently breaks the manual build, since the XSLT processing relies on this in some weird way, you can check with
nix-build nixos/release.nix -A manualHTML.x86_64-linux
I previously broke the manual in almost the same way when I tried to change the implementation of showOption
a bit in #82461, which was then subsequently reverted in #85241. There's also a bug report regarding showOption
in #152649
Now we even have options like `services.listmonk.database.settings."app.notify_emails"` shown correctly (i.e. with quotes).
@infinisil I replaced the quotes within the xslt now with a |
'*< >[]:', | ||
'_______' | ||
'*< >[]:"', | ||
'________' |
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.
This changes the identifiers, breaking inbound links. Could you remove the quotes instead of replacing them with underscores?
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.
Shouldn't that throw an error if <xref linkend="" />
points to an unknown location?
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.
Then that would have been a problem before.
You'd have to define options."" = mkOption ...
at the top level, which I don't think is something we have to worry about.
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.
Then that would have been a problem before.
Yes. But considering that I can build the manual locally, doesn't that mean that there are no breaking links?
You'd have to define options."" = mkOption ... at the top level, which I don't think is something we have to worry about.
Even though it's just a theoretical problem, having e.g. settings."foo.bar"
and settings.foo.bar
defined would cause a conflict when removing the quotes, that's why I kept them.
Or am I misunderstanding your point? :)
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.
ping @roberth
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 was more concerned about links from the web to the manual. Passing the internal validation will not detect such broken links.
It does appear that the impact is quite limited:
({+_+}
is git word diff syntax for "add underscore")
- 138 ids relating to sr.ht such as
opt-services.sourcehut.settings.{+_+}sr.ht{+_+}.owner-name
opt-services.listmonk.database.settings.{+_+}app.notify_emails{+_+}
opt-services.listmonk.database.settings.{+_+}bounce.mailboxes{+_+}
opt-services.listmonk.database.settings.{+_+}privacy.domain_blocklist{+_+}
opt-services.listmonk.database.settings.{+_+}privacy.exportable{+_+}
opt-services.xserver.windowManager.{+_+}2bwm{+_+}.enable
This seems like a small price to pay for a simpler and more injective id generating function.
@roberth so is it fine to keep that as-is? And: anything else tbd here? :) |
It's now necessary to also escape `"` (i.e. `"`) in option ids, otherwise the build will fail because `"` is not a valid part of an XML element id. See also NixOS/nixpkgs#196651 and the original change in NixOS/nixpkgs#194035 (comment) for further context. The `translate` expression is directly taken from the nixpkgs's `options-to-docbook.xsl`.
It's now necessary to also escape `"` (i.e. `"`) in option ids, otherwise the build will fail because `"` is not a valid part of an XML element id. See also NixOS/nixpkgs#196651 and the original change in NixOS/nixpkgs#194035 (comment) for further context. The `translate` expression is directly taken from the nixpkgs's `options-to-docbook.xsl`.
…-quoting"" This reverts commit dedb37a.
Description of changes
Personally, I think that warnings such as
are fairly confusing because of the
..
and it's more correct to actually quote that. With this change the warning now looks like this:While implementing that I realized that you'd have a similar problem whenever you use attribute-names that aren't identifiers, e.g.
now results in the following error:
Of course there are some corner-cases where this won't work: when generating the manual, you display submodules like this:
Since
<name>
isn't a value, but an indicator for a submodule, it must not be quoted. This also applies to the following identifiers:*
forlistOf submodule
<function body>
forfunctionTo
This might not be correct if you actually have a submodule with an attribute name called
<name>
, but I think it's an improvement over the current situation and for this you'd probably need to make even more complex changes to the module system.Closes #152649
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes