-
-
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
pkgs-lib.formats.xml: init #342633
base: master
Are you sure you want to change the base?
pkgs-lib.formats.xml: init #342633
Conversation
f50c8ab
to
f8a2453
Compare
pkgs/pkgs-lib/formats.nix
Outdated
type = let | ||
valueType = oneOf [ | ||
bool | ||
int | ||
float | ||
str | ||
path | ||
(attrsOf valueType) | ||
(listOf valueType) | ||
] // { | ||
description = "XML value"; | ||
}; | ||
in valueType; |
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.
to be honest: i just copied and pasted this from the json... not sure if this is a problem
not sure where to note the |
I'm wondering whether something could/should be done to ensure we can order attributes properly and still have control of the parent node? With the current implementation, it seems like you can either ensure the order of the child attributes by choosing to use a list, or you can use unordered attributes and be allowed to set "@ asdf" (sorry, accidentally pinged this user...) and "#asdf" properties. |
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.
Better XML support seems very useful. Thank you ❤️
pkgs/pkgs-lib/formats.nix
Outdated
@@ -517,4 +517,37 @@ rec { | |||
'') {}; | |||
}; | |||
|
|||
xml = {}: json {} // { |
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.
Is this format suitable for markup-like XML, such as XHTML? Based on the examples here and there, that seems to be an unsolved problem.
I doubt that this is the only and best Nix representation of XML, so I'd prefer a more specific name, like xmltodict
.
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.
it is the other way around: attrsToXml
right?
maybe we include the badgerfish
notation in the name? like badgerfishToXml
?
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.
Only referred to xmltodict
as the project name, assuming they didn't name the input format. So they implement the badgerfish format? Then that's great!
I guess we could group representations of XML under an xml
attrset, so that it's formats.xml.badgerfish
? That way it's more easily discoverable in documentation and the repl.
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.
Or formats.xml.fromBadgerfish
.
formats.badgerFishToXml
also works. We don't have nesting yet, actually.
Maybe @infinisil has an opinion, as he's started this library.
Otherwise, current name will do.
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 am open for suggestions. formats.xml.fromBadgerfish
sounds good. but lets wait for feedback from others.
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.
What about formats.xml { format = "badgerfish" }
(probably the default value)? This seems to be the intent with having the attrset parameter.
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.
implemented the idea from @ambroisie
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 @infinisil
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 someone is looking for different kinds of formats here is a good list: https://wiki.open311.org/JSON_and_XML_Conversion/
But when searching for implementations on GitHub; xmltodict
is the most actively maintained and famous one.
So IMHO it make sense to have this as default, because it is the only thing that has "prevailed"
</child2> | ||
</root> | ||
''; | ||
}; |
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.
How would namespaces look?
Does definition merging work as expected?
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.
it follows: https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html:
doesn't take into consideration the following:
- XML declaration
- processing instructions
- explicit handling of namespace declarations
- XML comments
i found: https://github.com/martinblech/xmltodict/blob/master/README.md#namespace-support
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.
namespaces are "mainly problematic" for parsing the other way around. it can be achieved via:
{
"RSS": {
"@xmlns:jwplayer": "http://support.jwplayer.com/customer/portal/articles/1403635-media-format-reference#feeds";
"@version": "2.0";
"Channel": {
...
to create:
<?xml version="1.0" encoding="utf-16"?>
<RSS xmlns:jwplayer="http://support.jwplayer.com/customer/portal/articles/1403635-media-format-reference#feeds" version="2.0">
<Channel>
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.
Ok, makes sense.
Handling foreign input while programming with hardcoded prefixes is basically wrong; an XML document should behave exactly the same under prefix renaming, but a lot of software requires certain prefixes, which is - in principle - wrong.
However, we will have to cater to such applications, and users who are kinda ok with such requirements, so that's just that.
Treating any node as URI + tag instead of prefix + tag makes any XML processing more robust (for an option type, the processing means implementing a merge
operation for the XML representation), so that may be worth considering, but it seems that we'd end up writing a small library for that purpose; a bit of a research project.
So for now I think we only need to point out in the docs that the type deals with the concrete syntax of the XML, and all responsibility is on the user when it comes to the correctness of any use of namespace features.
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.
since this will not be the "perfect/best" xml-exporter for nix, I would suggest to get started, but name it "specially" (not xml
as we both agreed above.).
Surely there are a lot of things to improve, but in the end we should enable other users to enable new NixOS-options. Migrating this to other formats seems tedious (manual work), but doable.
Documentation is currently missing completely, because I do not know where to put it. Any suggestions where to put it?
f8a2453
to
153d6ed
Compare
153d6ed
to
84aa26c
Compare
ping @infinisil ? Is this not wanted? |
This seems like a fine addition, I'm just very behind on things to review and on holidays (well at least since last week, not since the PR was opened 😅) :) After taking a look:
|
84aa26c
to
a353c23
Compare
a353c23
to
110f500
Compare
110f500
to
658a490
Compare
@infinisil thanks for the feedback. the two functions were placed to give a choice which one is preferred. Additionally I fixed the merge-conflicts. |
Description of changes
add XML export format. beneficial for https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
tested via:
nix-build . -A tests.pkgs-lib.formats
sonarr
can be improved to have settings e.g.: master...Stunkymonkey:nixpkgs:exportarr-sonarr-test. which can be tested vianix-build . -A nixosTests.prometheus-exporters.exportarr-sonarr
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.