NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.73k stars 1.52k forks source link

`ValidPathInfo` field does not adhere to the JSON guidlines #10311

Open Ericson2314 opened 7 months ago

Ericson2314 commented 7 months ago

ca field

Strings like fixed:r:sha256:adsfjlawefjliajsdl need to be parsed, and that is no good. We should use an object instead, something like

{
    "method": "nar",
    "hash": "sha256-adsfjlawefjliajsdl"
}

This should be implemented as a canonical nlohmann JSON "instance" for ContentAddress (and friends), with unit test characterization tests checking round trips. The ValidPathInfo JSON methods can then just use that nlohmann JSON instance.

Noticed while working on https://github.com/NixOS/nix/pull/10310 -- comparing the ca field in the tests was way more hackish than it should be.

signatures field

The <name>:<pub-key> format should be replaced with a two-field JSON object.

Other info

See also #9866 for something similar

CC @roberth

roberth commented 7 months ago

I don't think structured strings (oxymoron?) technically violate the JSON guidelines, but otherwise it seems that what you're proposing is an improvement.

Should the hash be parsed into a record object, or should we use SRI hash strings, or both?

Ericson2314 commented 7 months ago

Should the hash be parsed into a record object, or should we use SRI hash strings, or both?

Good question. I am fine either way. At least the SRI string is not our own homegrown convention.