Skip to content

nlohmann::json instance and JSON Schema for MemorySourceAccessor#14319

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:json-schema-fso
Nov 20, 2025
Merged

nlohmann::json instance and JSON Schema for MemorySourceAccessor#14319
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:json-schema-fso

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Oct 21, 2025

Motivation

As documented, this for file system objects themselves, since MemorySourceAccessor is an implementation detail.

Context

Depends on #14598


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

This seemed so simple, but bytes strike again.

Comment on lines +37 to 38
../../src/libutil-tests/data/memory-source-accessor
../../src/libutil-tests/data/hash
Copy link
Member

Choose a reason for hiding this comment

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

Maybe these should point the other way around?
Being a documentation example is more significant than being tested as part of some test suite.
Also it's helpful for the test suite to have an explicit reference to path that's in the manual, to distinguish it from test cases that only exist for the purpose of testing, i.e. corner cases that aren't relevant enough for the manual.

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched it from your version because of how _NIX_TEST_ACCEPT works, especially when making new files.

Copy link
Member

Choose a reason for hiding this comment

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

Can it not write through a symlink? IIRC I had something like tests/data/examples point into the manual. Wouldn't it just write to data/examples/new-file if you passed examples/new-file as the stem?

Otherwise, I guess we could use a naming convention to highlight which examples are for docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will write through the symlink if the symlink already exists, but I like to use _NIX_TEST_ACCEPT=1 for making the initial versions of those files too.

contents:
type: object
description: |
Map of names to nested file system objects (for type=directory)
Copy link
Member

Choose a reason for hiding this comment

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

There's probably semantics we want to document here, like we don't allow /?
Probably best to make a link, so that we don't duplicate all prose here.

I guess we could encode a no / restriction with draft 6 propertyNames if we want.

Copy link
Member

Choose a reason for hiding this comment

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

Names may not be valid UTF-8 and therefore not be valid JSON (sequence of unicode characters, https://www.rfc-editor.org/rfc/rfc8259#section-1)

One possible solution, if this is something we've tested that it even works:

"It is commonly accepted that file names should be UTF-8, but not guaranteed.
Nix will forward invalid names, so if you wish to support all possible NARs in your application, you will need to use a parser that forwards invalid UTF-8 into your application, and allows you to produce invalid UTF-8 in the JSON you may have to output."

Alternatively, we could require base 64 here too.

Same applies to the symlink targets.

Copy link
Member

Choose a reason for hiding this comment

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

Or we could have a LenientString type that's either a valid JSON string, or a { "base64": ... }, but that only helps for values, not field names. I guess we could steal syntax and have "/aGVsbG8=": be an equivalent, non-canonical field name to "hello":.

So LenientString would be a type for representing values that are typically valid strings, but may not always be, and base 64 would be an unwarranted hindrance in practice. (Not sure about the latter; maybe we should just use it for file contents too?)

Copy link
Member Author

@Ericson2314 Ericson2314 Nov 18, 2025

Choose a reason for hiding this comment

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

I was wrong about null bytes (I used the wrong kind of string literal), I think nlohmann::json will happy do escape sequences for pretty arbitrary stuff. (I am not sure we even give it enough unicode support at runtime to not do that, fwiw.)

Not it will complain about invalid UTF-8. I would prefer to fix this in a follow-up PR, however.

const: "symlink"
target:
type: string
description: Target path of the symlink.
Copy link
Member

Choose a reason for hiding this comment

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

Another lack of semantics. Should probably just be a link.
What is the meaning of an absolute path? Or a relative path? Can a relative path be allowed to ..-leave the FSO? I don't think the manual has good answers yet, but this should link to what we have, @docroot@/store/file-system-object.md

Copy link
Member Author

Choose a reason for hiding this comment

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

The manual is now updated a bit, and linked.

@github-actions github-actions bot added the new-cli Relating to the "nix" command label Oct 30, 2025
@Ericson2314 Ericson2314 force-pushed the json-schema-fso branch 4 times, most recently from 31bebf4 to a1c39ed Compare November 7, 2025 04:44
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Nov 7, 2025
@Ericson2314 Ericson2314 force-pushed the json-schema-fso branch 2 times, most recently from d6be2bc to dfbb101 Compare November 10, 2025 23:32
@Ericson2314 Ericson2314 force-pushed the json-schema-fso branch 4 times, most recently from 75a4d88 to 741ded1 Compare November 18, 2025 22:16
Copy link
Member

@edolstra edolstra left a comment

Choose a reason for hiding this comment

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

Approved pending a check that this is a superset of the format produced by listNar().

@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Nov 20, 2025
@Ericson2314 Ericson2314 force-pushed the json-schema-fso branch 2 times, most recently from 966b90e to 59a4fad Compare November 20, 2025 01:42
Also do a better JSON and testing for deep and shallow NAR listings.

As documented, this for file system objects themselves, since
`MemorySourceAccessor` is an implementation detail.
@dpulls
Copy link

dpulls bot commented Nov 20, 2025

🎉 All dependencies have been resolved !

@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 20, 2025
Merged via the queue into NixOS:master with commit a835d6a Nov 20, 2025
16 checks passed
@Ericson2314 Ericson2314 deleted the json-schema-fso branch November 20, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants