Skip to content

feat(ron): Add native RON format support - #19360

Open
nikooozzz wants to merge 40 commits into
nushell:mainfrom
nikooozzz:feat/native-ron-support
Open

nikooozzz wants to merge 40 commits into
nushell:mainfrom
nikooozzz:feat/native-ron-support

Conversation

@nikooozzz

@nikooozzz nikooozzz commented Oct 27, 2026 •

Copy link
Copy Markdown

Description

This PR introduces native support for RON (Rusty Object Notation) in Nushell by adding two new core format commands:

  • from ron: Parses RON string data into structured Nushell values (records, lists, primitives).
  • to ron: Serializes Nushell structured data (records, lists, primitives) into pretty-printed or raw RON text.

This enables seamless pipelines for parsing and serializing RON configuration files and data structures directly within Nushell.

User-facing changes (Release notes)

  • Added from ron and to ron commands to natively support parsing and serializing Rusty Object Notation (RON) data formats.

Checklist

  • Implement from ron command
  • Implement to ron command
  • Add integration tests and command examples

Additional notes

@nikooozzz

Copy link
Copy Markdown
Author

@DevWizard13 I've given you collaborator permissions on my fork. I need to rebase and clean up some failing tests, but if you could check into adding file extension support (I haven't figured out how) that would be awesome!

@nikooozzz
nikooozzz force-pushed the feat/native-ron-support branch from c551adf to 6692eec Compare October 27, 2026 16:03
@DevWizard13

Copy link
Copy Markdown

I'll get on that in a few minutes

@DevWizard13

Copy link
Copy Markdown

So it appears that it can automatically infer the file extension from the name of a command, as far as I can tell. As far as I can tell is the key phrase, this is a lot more advanced than most things I've dealt with before. I'm still getting my bearings in the codebase, so I'll return with a more detailed analysis in an hour or two.

@DevWizard13

Copy link
Copy Markdown

Yeah, it can automatically infer the file extension type if you put in a ron.rs file in ./crates/nu-command/src/formats/from, which it appears you did. Unless there are other file extensions that ron files often have, it looks like you're all set. I'll test real quick.

@DevWizard13

Copy link
Copy Markdown

Test looks good. I've been able to both read and write RON files. I'll continue to use it and we'll see if we can get it merged.

@DevWizard13

Copy link
Copy Markdown

It can't yet read or write the size of a file. I'm going to implement this.

Before, it couldn't write either of these values. It now achives feature
parity with json in both, it can write Filesize as the number of bytes
and Date as a string. The only problem left I can identify is that it
seems to write dictionary items in alphabetical order rather than in the
order they were provided. I will go through the list of nu data types
and implement them all, where possible, comparing the results to to and
from json.
Every type in nushell (besides closures, but those can't be saved to
most file formats either) can now be saved to RON files.
@nikooozzz

nikooozzz commented Oct 27, 2026 •

Copy link
Copy Markdown
Author

Great! I edited the PR description since we don't need an explicit implementation for file extension support.

@nikooozzz
nikooozzz force-pushed the feat/native-ron-support branch from 45bfef7 to 855c6fb Compare October 28, 2026 01:05
@nikooozzz

Copy link
Copy Markdown
Author

I've now added a suite of integration tests and expanded the examples I wrote in my initial commit.

I also want to note that we aren't retaining enum variants, and option mappings (Some(value)) are lossy and become just the value. I'd like to hear your opinions on whether this should be implemented now or at some later stage?

I used `to_string()` to format the date previously. I now use a function
that uses the same format that is saved in json files. Also, I've tested
it with a recod containing every data type nushell has (besides
closures, which I don't think will be supported in the near future), the
output of `ls -la`, and several random RON files I found floating around
in my system. It works on all of them, as far as I can tell. I recommend
running your own tests too.

Either way, I think we've worked most of the problems out and we're to
the testing and refinement phase. Most if not all of the development is
done. It's basically reached feature parity with json support.
@DevWizard13

Copy link
Copy Markdown

You probably saw the commit, but I fixed the final few little things and tested it with multiple different tasks. It can read and write RON just as well as it can read and write JSON. The only thing that it doesn't do as well is that it seems to write records to the RON file in alphabetical order rather than in the order of the record, but this is honestly so minor I don't even think it's worth fixing.

TLDR, it's done. I recommend testing it a little more just in case, but I'm pretty sure I've worked out everything. Great job!

@DevWizard13

Copy link
Copy Markdown

As for enums, I think it depends on what else we have to do. If we don't have anything else here to do, then yes, we should probably at least attempt to add them. If not, we should focus on those other things first.

The type system of nushell unfortunately doesn't support enums, so our only options are to either find a way to serialize them to/from strings, to add enums to the nushell type system, or to ignore them.

Serializing enums to and from strings would probably be difficult and risk accidentally treating normal strings as enums in the unlikely event that the syntax collided. Adding enums to the type system is the only reliable solution, but it would both be a giant pain to do and require coordination with the rest of the nushell team because it's a major change. Ignoring it would leave support out.

So, I've thought about it, and I came to a decision. I think we should focus on stabilizing and merging what we have now, without worrying about Option or enums. Once we've done that, then we should ask the nushell team what they think of adding enums to the type system and make our decision about what to do with enums after that. Any thoughts, opinions, or objections?

@DevWizard13

Copy link
Copy Markdown

We could also represent enums as a record with a singular element, the name being the single key of the enum and the contents being whatever the enum contains. This is probably the cleanest and simplest solution, but it could also get difficult to work with once you've converted it to nu data types. It's probably the best solution yet. But I still stand by what I said earlier, we should probably focus on other things first.

@nikooozzz

Copy link
Copy Markdown
Author

I completely agree with you, trying to introduce enums into Nushell's type system or making unstable patches would just blow up the scope and stall the PR. Let's get what we have stable, tested and merged first, and we can always change the enum handling at a later stage with the core team.

As for the alphabetical record ordering, I believe that it stems from ron's internal usage of BTreeMap, which by default serializes into sorted keys. It's definitely not worth blocking the PR for, but may result in an issue later (since there always is a need to be precise).

I've got the test suite ready to go, and haven't experienced any issues yet. I'll clean up the PR, and let's get this merged!

@DevWizard13

Copy link
Copy Markdown

Sounds good!

@nikooozzz
nikooozzz marked this pull request as ready for review October 28, 2026 15:32
@DevWizard13

DevWizard13 commented Oct 29, 2026 •

Copy link
Copy Markdown

To anyone impatient for this to hit the mainline and eventually the package manager of your system, I just compiled it, installed it to /usr/local/bin/nu, added it to /etc/shells, and set that as my default shell using chsh. You can do the same if you use a Unix-like system (maybe not macOS, I wouldn't know but I hear it's pretty restrictive).

@DevWizard13

Copy link
Copy Markdown

Oh, hey @nikooozzz your fork of nushell is out of date, I thought of updating it but I don't wanna risk breaking anything so can I update it? Also, you should enable issues there so that in the event someone wants to make future improvements or has things to discuss in it that don't belong here, we can do so outside the pull request.

As a side note, fun plot twist (as you put it): someone actually read your blog! That's me. Life has a way of surprising us sometimes. Been a long time since I've seen someone just be themselves online rather than trying to perform for an algorithm, which is really nice.

@nikooozzz

Copy link
Copy Markdown
Author

Sure! Feel free to update it. I was thinking it'd be better to have any issues be directly attached to the main repo instead of my fork, since people wouldn't want to go out of their way to find it and report through there when this gets merged.

@fdncred

fdncred commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

i could probably support this pr. can you get it green? if so i'll review it

@DevWizard13

Copy link
Copy Markdown

On it.

@nikooozzz nikooozzz left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just sat down to fix the ordering and dependency issues myself since I realized I hadn't refreshed the PR, great that you had already fixed them. On the struct question: I think we should serialize records as struct-like by default (as demonstrated by @fdncred) and fall back to quoted-key maps only for records whose keys aren't valid identifiers. Since Nu doesn't distinguish between structs and maps, a file mixing both won't roundtrip perfectly either way, but the PR advertises config files as the primary use case, so staying as close as possible to what serde structs and RON configs require seems right. I'll document the limitation in the to ron help text and the release notes as well.

@DevWizard13

Copy link
Copy Markdown

Sounds good, but I'm not sure how to serialize a record to a RON struct, so I'll leave that one to you (or research it later if you don't get to it). But anyway, I think a fundamental issue here is that RON and nu have incompatible type systems, so we're gonna be fighting it a lot.

fdncred added a commit that referenced this pull request Nov 14, 2026
## Description

The `Security audit` job fails on PRs that touch `Cargo.toml` or
`Cargo.lock` (seen on #19360). RUSTSEC-2026-0538 flags `quinn-udp
0.5.14`, and RUSTSEC-2026-0486 warns that `rustix 1.1.4` is unsound.
This PR changes only `Cargo.lock`.

| Crate | Old | New | Why |
| --- | --- | --- | --- |
| `quinn-udp` | 0.5.14 | 0.5.16 | RUSTSEC-2026-0538, receive loop can
spin after a truncated datagram |
| `rustix` | 1.1.4 | 1.1.6 | RUSTSEC-2026-0486, unsound xattr calls with
a zero-length buffer |
| `xattr` | 1.6.1 | 1.7.0 | `xattr 1.6.1` breaks on `rustix 1.1.6` |

The `quinn-udp` bump alone turns the check green. The other two clear
the unsound warning and have to move together. In `rustix 1.1.6`,
`getxattr` and `listxattr` with an empty buffer return 0 instead of the
size, which now comes from new `*_query` functions. `xattr 1.6.1` uses
the empty-buffer call to size values over 4 KiB, and `xattr 1.7.0` uses
`*_query` instead. nushell reaches this through `uucore::fsxattr` in `cp
--preserve [xattr]` and cross-device `mv`.

`cp --preserve [xattr]` on macOS, copying a file with a 6000-byte
attribute:

| Lockfile | Copied attribute |
| --- | --- |
| main (`rustix 1.1.4`, `xattr 1.6.1`) | 6000 bytes |
| `rustix 1.1.6`, `xattr 1.6.1` | 0 bytes |
| this PR (`rustix 1.1.6`, `xattr 1.7.0`) | 6000 bytes |


## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
@fdncred

fdncred commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

need to rebase to fix the security audit

nikooozzz and others added 18 commits November 14, 2026 02:39
Before, it couldn't write either of these values. It now achives feature
parity with json in both, it can write Filesize as the number of bytes
and Date as a string. The only problem left I can identify is that it
seems to write dictionary items in alphabetical order rather than in the
order they were provided. I will go through the list of nu data types
and implement them all, where possible, comparing the results to to and
from json.
Every type in nushell (besides closures, but those can't be saved to
most file formats either) can now be saved to RON files.
I used `to_string()` to format the date previously. I now use a function
that uses the same format that is saved in json files. Also, I've tested
it with a recod containing every data type nushell has (besides
closures, which I don't think will be supported in the near future), the
output of `ls -la`, and several random RON files I found floating around
in my system. It works on all of them, as far as I can tell. I recommend
running your own tests too.

Either way, I think we've worked most of the problems out and we're to
the testing and refinement phase. Most if not all of the development is
done. It's basically reached feature parity with json support.
In the description of `from/ron.rs', I added a note to `description()`
warning the user that it cannot parse enums and that `Some` is expanded
automatically.
RON is now a workspace dependency, and ordering is preserved instead of
being overriden by alphabetical order.
Unix newlines (LF) and tabs ("\t") are now standard for the pretty
config.
It now reports errors as the error rather than as an unsupported type.
It conuses me as to why it was messed up to start with, but it was.
Fixed it.
Remove unnecessary borrow.

Co-authored-by: Darren Schroeder <[email protected]>
Add glob support (as a string)

Co-authored-by: Darren Schroeder <[email protected]>
@nikooozzz
nikooozzz force-pushed the feat/native-ron-support branch from 534084e to f146749 Compare November 14, 2026 01:44
@DevWizard13

Copy link
Copy Markdown

So, about the struct thing, I did some looking and I don't think it's going to be possible anytime soon. There is no struct type in ron::value. I opened an issue over in their repo on this subject, but honestly, I don't have high hopes. If they were going to add it, they would have by now. So, this means that we're going to have to write a RON serializer ourselves, which is... a lot.

Basically, I think that this is more of a long-term goal. I've talked about this before, but RON and nu have fundamentally incompatible type systems. We're probably not going to get data to roundtrip through it anytime soon. I think that we should focus on getting something that works before we get something that's perfect. So, I think the best approach would be to focus on stabilizing and merging what we have, accept that for the time being, it will be primarily for reading RON and that the write functionality will be relatively limited. We should, however, also discuss what we want this to look like in the long term. However, let's focus on getting stuff working right now.

What do you think about this?

@DevWizard13

Copy link
Copy Markdown

Also, about the struct vs map thing, I talked with the maintainers of RON and it's not an issue with RON, it's an issue with serde. Serde requires &'static strs for struct names, and these can't be generated without risking a memory leak unless they're known at compile time. Or, they could violate the rules of serde, but I don't think they're going to do that.

I generally got the message that while they hope it's going to happen eventually, they're waiting on serde and it doesn't seem to be happening quickly. So, we'll probably have to implement something ourselves or wait for support from serde.

@nikooozzz

Copy link
Copy Markdown
Author

Makes complete sense. Given how serde handles static identifiers and how Nushell's Value system works, it seems like a massive rabbit hole to chase fully lossless roundtrips upfront. I agree 100% on merging something stable and solid first, so we need to finish from ron for standard records, lists and scalars, keep to ron straightforward on Nu's values without overpromising on the struct names and maps keys yet, and get the PR in shape to merge. We can always open followup issues for deeper type/roundtrip support later!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RON (.ron) File Support

3 participants