-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Parse TOML timestamps as strings #8120
Parse TOML timestamps as strings #8120
Conversation
Discussed at last Nix team meeting. Verdict: Let's do this, but in a way that round-trips properly, and as an experimental feature. Expand details for an idea of how round-tripping could work.
- @edolstra: Probably the best we can do. The alternative would be encoding it in a structured way, which would be fairly complicated.
|
👍 I think we should follow the TOML's definitions (Offset Date-Time, Local Date-Time, Local Date, Local Date). These types are already available from toml++. AFAIK they are all subsets of RFC 3339 anyway. With some luck I'll find some time to work on this week or the next. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-04-10-nix-team-meeting-minutes-47/27357/1 |
6394e46
to
3eef831
Compare
src/libexpr/primops/fromTOML.cc
Outdated
throw std::runtime_error("Dates and times are not supported"); | ||
case toml::value_t::local_time: { | ||
auto attrs = state.buildBindings(2); | ||
attrs.alloc("_type").mkString("timestamp"); |
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.
"timestamp" is a bit too generic, maybe it should be "toml-datetime" or something like that.
Also, maybe the specific TOML type (toml::value_t::{local_datetime,...}
) should be stored in the attrset (either encoded in _type
, or as a tomlType
attribute). If we ever add a toTOML
builtin, that should make it easier to round-trip.
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.
Related: #3929
Reviewed in Nix team meeting 2023-05-08: We still want this, but we also want to get it right. As @edolstra pointed out we have to take care of not occupying the Complete discussion
|
My take on this is, since it's supposed to be guarded by an experimental feature, we could merge it in whatever form, and then adapt as needed once we have a |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-05-08-nix-team-meeting-minutes-53/27967/1 |
3eef831
to
a20c53a
Compare
Thank you @fricklerhandwerk. I followed the rest of the code w.r.t. the experimental flag. Let me know if this is ok. I believe the CI failure is unrelated to the PR. |
Currently fromTOML throws an exception when encountering a timestamp since the nix language lacks a way to represent them. This patch changes this beaviour and makes fromTOML parse timestamps as attrsets of the format { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }
a20c53a
to
b258353
Compare
.tag = Xp::ParseTomlTimestamps, | ||
.name = "parse-toml-timestamps", | ||
.description = R"( | ||
Allow parsing of timestamps in builtins.fromTOML. |
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 just about to make a suggestion to link to builtins.fromTOML
documentation, but that's not even documented at all.
That made me realise that we seem to have been talking about making all of builtins.fromTOML
experimental in order to have some time to figure out the roundtrip design. @nixos/nix-team is that correct? @andreabedini sorry that whatever misunderstanding was unearthed here may produce even more work for you...
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.
No problem
Discussed in the Nix team meeting 2023-06-05:
@andreabedini We'd very much welcome a follow up where timestamps are represented as structured Nix values. That would be the precondition to stabilise the feature. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-06-05-nix-team-meeting-minutes-60/28933/1 |
An update of the TOML library has changed the returned timestamp's string representation, either to remove the |
Motivation
Writing foliage I have choosen TOML knowing that nix would be able to read it natively. As it turns out, I cannot parse foliage input metadata because it includes timestamps, which nix does not support. 💔
Context
Currently fromTOML throws an exception when encountering a timestamp since the nix language lacks a way to represent them. This patch changes this beaviour and makes fromTOML parse timestamps as their were strings.
I believe this is the right thing to do here, given that a string is better than nothing.
Note that, ifwe had
toTOML
, ensuringfromTOML (toTOML x) == x
might be impossible anyway because nix values can be expressed in multiple ways in TOML.Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*
Priorities
Add 👍 to pull requests you find important.