Repository navigation
Conversation
|
Like mentioned in #4910 (comment), we might want to consider to encode the yaml version into the function somehow. Instead of |
If this should be implemented, then a decision about the versioning scheme is needed and how the versioning should be done, i.e. whether the builtins should have different names or whether a function with additional version argument should be used instead. Having explicitly different function names would be advantageous with respect to reproducibility. The versioning should apply to different code versions, not only to different YAML standards, so that bug compatibility can be retained. The YAML standard is ugly and we need to parse real world data, i.e. the "YAML" might be invalid, so that some tradeoffs are required... I'm wondering how updates of |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
I discussed this once more with @NaN-git and it doesn't seem like a good idea to encode the yaml spec version in the function name. Whatever naming schema we would come up right now, there is a high chance that it won't be meaningful. Therefore I think the builtin should just be introduced as a plain |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
Discussed in Nix team meeting on 2023-01-09:
Complete discussion
|
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
@edolstra any reason not to merge this? |
Decisions
Issues to clarify
VersioningIf the underlying library returns different results over time, this impacts reproducibility |
Regarding the tests:
builtins.fromYAML ''
---
values:
- &value someValue
---
# some YAML template
template: *value
''evaluates to (I'm not very happy with the handling of multiple documents) [
{
values = [ "someValue" ];
}
{
template = "someValue";
}
]Build questionsrapidyaml uses cmake as build system. I don't think that this a good choice for nix because bootstrapping of nix has to be easy. The only dependency of rapidyaml is c4core from the same author. Even with rapidyaml as single header file the build time of |
I would package it and its dependency in Nixpkgs. I am happy to help with that part if you want. I personally am not to concerned about the bootstrapping because we could always make YAML a (compile time of Nix) optional feature. |
Packaging rapidyaml is rather easy: { cmake
, fetchFromGitHub
, git
, stdenv
, enableStatic ? true
}:
stdenv.mkDerivation rec {
pname = "rapidyaml";
version = "0.5.0";
src = fetchFromGitHub {
owner = "biojppm";
repo = pname;
rev = "v${version}";
fetchSubmodules = true;
hash = "sha256-1/P6Szgng94UU8cPFAtOKMS+EmiwfW/IJl2UTolDU5s=";
};
nativeBuildInputs = [ cmake git ];
cmakeFlags = [
"-DRYML_WITH_TAB_TOKENS=ON"
"-DBUILD_SHARED_LIBS=${if enableStatic then "OFF" else "ON"}"
];
}I prefer to statically link this because the static library is rather small (~500 KB). In my opinion not only bootstrapping of nix has to be easy, but compiling it for other distributions should be easy, too. I don't know how to add rapidyaml as optional dependency to nix, so that builds without nix aren't messed up. |
|
I removed rapidyaml as single header file and made it an optional library instead. If the library cannot be found then Regarding the testing framework: I need more information what's actually required/wanted. I commented some point in #7340 (comment). Of course it would be possible to preprocess the tests differently so that less logic is needed in the testing code and it would be more obvious which tests are executed actually. |
@edolstra what do you think about an optional built-in? Doesn't sound right to me. |
Supporting a build without yaml library might be useful for some build-from-source bootstrapping process, but in this case it must be an explicit choice to remove the yaml feature and create an incomplete Nix. It must not happen by accident. |
|
Whether that's even a worthwhile effort, I don't know. Personally I think bootstrapping Nix from source is not an important use case, but packaging by other distros is. Those distros must not package a Nix without yaml though! I'd rather require rapidyaml unconditionally. |
Ok, I see two possible solutions:
|
- add additional argument to fromYAML for optional parameters of the parser - adhere to the YAML 1.2 core schema - much stronger error checks and improved error messages - proper conversion of null, floats, integers and booleans - additional testcases and more checks for expected failures
- restrict patterns of floats and ints to patterns defined by YAML 1.2 core schema - parse integers with tag !!float - map: enforce key uniqueness
fix: parse "!!float -0" as -0.0
- detect integer over- and underflow - disallow denormal numbers
610cd2f to
ce61749
Compare
|
It seems the PR is ready, but it still hasn't been merged. Is there an underlying reason that hasn't been mentioned here? |
|
@roberth Could you maybe give this another chance, loading yaml is so utterly needed :). Thanks a lot. Even if it becomes experimental feature, I am happy about it. |
| Value rymlJson = fromYAML(state, root, {}); | ||
| EXPECT_EQ(printValue(state, refJson), printValue(state, rymlJson)); | ||
| start = ss.tellg() + std::streampos(1); | ||
| } |
There was a problem hiding this comment.
sugg: maybe a comment why this empty catch here
| bindings.alloc("useBoolYAML1_1").mkBool(true); | ||
| options.mkAttrs(bindings); | ||
|
|
||
| Value val = parseYAML("[ true, True, TRUE, y, Y, on, On, ON, yes, Yes, YES ]", options); |
There was a problem hiding this comment.
question: is this really yaml ( then I didnt know) or does Nix parse these as booleans?
There was a problem hiding this comment.
Sadly, YAML 1.1 specifies that this should be parsed as booleans, e.g. kubernetes relies on this behavior. By default Nix uses YAML 1.2, where this is parsed as strings.
There was a problem hiding this comment.
It's a misconception that YAML would be simple. Instead the standard is very complex and making YAML 1.2 a superset of JSON didn't simplify it.
There was a problem hiding this comment.
Hmm. jeah thats why people probably want toml over yaml sometimes. I am happy when this gets merged, not sure whats taking so long, ok its a new dependency? I guess the ecosystem benefits from such a function a lot.
Does that yaml parser also support references?
| {.name = "__fromYAML", | ||
| .args = {"e", "attrset"}, | ||
| .doc = R"( | ||
| Convert a YAML 1.2 string *e* to a Nix value, if a conversion is possible. |
|
I can't wait to test this new experimental features! Do we know if the merge is planned, and if so, when? |
|
The pain of things like #13741 and NixOS/nixpkgs#433710 would make me extremely hesitant to bake another complex and underspecified serialization format into the evaluation semantics of the language. |
I don't think that something like #13741 can happen here. Rapidyaml parses the YAML tree only. The application (nix) is responsible to chose the type of leaf nodes and to parse them. The type of scalars is chosen according to the rather simple YAML core schema (keys are always parsed as strings because nix cannot handle anything else). The number parsing has an external dependency, so that some risk remains, but neither the nix parser vendors number parsing. No YAML serialization is done. |
|
I looked at the changelog for the most recent version of Rapid YAML. It seems like the fix for biojppm/rapidyaml#484 would cause a breaking change in Nix evaluation semantics, right? |
Yes, a bug in the library can affect nix and before this PR is merged I would update the minimum required version (still it would be an experimental feature). Would your quoted bug affect builds? The concerns have to be tackled before this feature can become non-experimental. |
|
@NaN-git : Isnt it that we can trust this function to be deterministic to the future by locking the dependencies for |
This would effectively constitute forking/vendoring those libraries and maintaining them ourselves for all eternity to be compatible with newer compilers e.t.c. It's also doubtful that we'd want to bake problematic and buggy behaviour and declare that to be stable for all eternity. The problem is that such underspecified and hard to implement stuff as YAML is too much of an API surface to effectively guarantee stability. Doing this would absolutely require adding comprehensive fuzzing and a gigantic corpus of tests to regular regression tests. This is something nix is totally lacking at the moment. |
|
Aha: Then the only way forward is ditch this PR, which is really sad given the amount of work went in and implement a simple yaml parser in Nix which nobody wants to do, resulting in the same problem |
If so, you could always roll your own, like I did here: https://git.sr.ht/~x10an14/nix-conf-langs/tree/main/item/languages.nix#L32 |
|
@NaN-git Any chance this PR gets merged and experimental status? |
|
I can't speak for the nix team, but:
This could be done if there's sufficient interest in refining a YAML spec and (possibly) maintaining a fork of |
|
Edit: Never mind. I thought the author was waiting for the team to merge. |
|
@samos667 I would also like to remind you that every line of code is a liability, and every new feature is a liability. Remember https://www.hyrumslaw.com/ . It might sound silly, but this is the reality of maintaining a widely use piece of software, trying to preserve simplicity, and maintain stability |
I need deserialization. |
Why
builtins.fromYAML?YAML is widely used amongst other package managers and deployment tools. If we want better compatibility to these ecosystems, the ability to parse yaml efficiently in nix is useful, as it is for TOML and JSON, which we already support. Further discussion can be found, i.a., in #4910.
Description
YAML 1.2 is a complex standard and nix has a limited set of data types. Thus only a subset of YAML can be represented in nix. For example attribute sets require String keys, i.e. attribute sets can represent YAML maps with String keys only, and nix has no data types for binary data or dates. If
builtins.fromYAMLencounters YAML with incompatible data types, then it fails similar tobuiltins.fromTOML.First, the implementation uses rapidyaml to parse the YAML string and afterwards the nix objects are created while traversing the YAML tree similar to
builtins.fromTOML. Tags are mostly ignored and affect only scalars. Custom tags are always ignored and I don't see how custom tags could be handled by nix.Why rapidyaml?
As part of nix robustness and safety of the implementation of
builtins.fromYAMLare important.Some reasons why rapidyaml was chosen:
limitations of rapidyaml
rapidyaml has a few limitations. Most of these limitations are not really relevant for the nix use case because of the limitations of nix.
Some comments with respect to the limitations:
RYML_WITH_TAB_TOKENSis defined forbuiltins.fromYAML.{ &anchor: key: val, anchor: *anchor: }is parsed correctly, but this test case fails. The test case is ignored in thebuiltins.fromYAML-tests because it is an edge case and it's no valid YAML 1.3.Otherwise the only issue that I found is that a string/block containing only tab-, space- and new line-characters might be parsed incorrectly as empty string (test case). I don't think that this limits the real world usage.UPDATE: This is fixed in the newest rapidyaml release.:-token and missing value, e.g. this example cannot be parsed.Also rapidyaml parses some invalid YAML successfully, but that is actually helpful.
Otherwise the valid JSONUPDATE: Actually this is allowed in flow mappings.{"a":"b"}, which is emitted bybuiltins.toJSON, could not be parsed bybuiltins.fromYAMLbecause it is no valid YAML due to the missing separation white space after the:-token.Tested platforms