-
-
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
primops: add builtins.toTOML #8416
Conversation
3e9ecc2
to
398b2ae
Compare
398b2ae
to
5ed0e3d
Compare
Following https://discourse.nixos.org/t/2023-06-02-nix-team-meeting-minutes-59/28666, I have added the builtin behind an experimental feature flag and updated the release notes. I wasn't sure what a good name for the feature would be so I just used |
This commit introduces the a new experimental builtin function: `builtins.toTOML`. The builtin is guarded by an experimental feature `to-toml` to allow more time for testing that round-trips with `builtins.fromTOML` works properly. The functions printValueAsTOML were introduced to serialize Nix values to TOML with a slight difference in behavior from printValueAsJSON being null values are not supported. In order to match the global table structure TOML imposes, the argument of `builtins.toTOML` was restricted to an attribute set but sublevels values have no restriction. A language test was added and the release notes were updated to document the addition.
5ed0e3d
to
ada8cf1
Compare
Discussed in the Nix team meeting 2023-06-05:
@polykernel is there anything that would prevent using a Nix language library to satisfy your use case, apart from implementing one being tedious? Sorry for the back and forth, but as @roberth and @edolstra point out, we don't want to commit to something that may be a huge long-term liability to maintain while keeping reproducibility. It would outweigh the benefits of a symmetric interface for (de)serialising TOML. Unless there's a very strong reason to have a builtin that we haven't considered, we'd close the PR. |
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 |
@fricklerhandwerk I don't have any particular argument against using a Nix language library to fulfill the role of this builtin. I created this PR while looking at some stale issues with the |
@polykernel, your help is much appreciated. We did discuss the possibility of reusing the code you wrote in a test. If that's the sort of thing you're interested in, writing a property test with rapidcheck, that might be a worthwhile destination for this code. Regarding the situation, I feel bad that you've seemingly done the right thing, but it did not lead to the intended result. Nix has some tricky requirements. We want to make an effort to communicate those better in design docs / contribution docs, but I don't think that takes away the risk entirely. We try to triage as much as possible, which should also help prevent situations like this, but that's not guaranteed to happen in time, and may not be thorough enough in some cases. I think the |
@roberth Thanks for the encouragement. I would be happy to help with reusing the code to write property tests. As for the property tests specifically, would the tests be for checking roundtrips with
Not to worry. I understand that design is difficult and that sometimes decisions change based on new inputs and considerations. Regardless of the result, I considered this to be a good learning opportunity to get more familiar with the Nix codebase.
I will definitely look out for issues with the |
Yes, basically
I think it's a bit cleaner to create a new one, mostly because of the branch name, but a fresh discussion thread is also nice imo. |
I am currently looking at the rapidcheck and gtest documentation, it may take some time since I am not familiar with either framework. I will try to get a preliminary implementation as soon as possible and close this PR then. Edit: This did not age well, some real life stuff got in the way. I am restarting work on the PR after some obstacles. I hope to get it ready soon. |
Motivation
This commit introduces the a new experimental builtin function:
builtins.toTOML
.The builtin is guarded by an experimental feature
to-toml
to allowmore time for testing that round-trips with
builtins.fromTOML
worksproperly.
The functions printValueAsTOML were introduced to serialize Nix
values to TOML with a slight difference in behavior from printValueAsJSON
being null values are not supported.
In order to match the global table structure TOML imposes, the argument of
builtins.toTOML
was restricted to an attribute set but sublevels valueshave no restriction.
A language test was added and the release notes were updated to document the addition.
Context
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.