From 61de9222b029ab4e9b8ad8697945371ddd6cd855 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 8 Dec 2025 15:34:15 -0500 Subject: [PATCH] Use SRI hash (strings) as the official JSON format for Hash after all The fact that we were introducing a conversion from the output of `nix path-info` into the input of `builtins.fetchTree` was the deciding factor. We want scripting outputs into inputs like that to be easy. Since JSON strings and objects are trivially distinguishable, we still have the option of introducing the JSON format as an alternative input scheme in the future, should we want to. (The output format would still be SRI in that case, presumably.) --- doc/manual/rl-next/json-format-changes.md | 11 ++---- doc/manual/source/protocols/json/hash.md | 4 +-- .../source/protocols/json/schema/hash-v1.yaml | 35 ++++--------------- src/json-schema-checks/meson.build | 4 +-- .../data/common-protocol/content-address.json | 18 ++-------- .../optional-content-address.json | 6 +--- .../data/content-address/nar.json | 6 +--- .../data/content-address/text.json | 6 +--- .../data/derivation/output-caFixedFlat.json | 6 +--- .../data/derivation/output-caFixedNAR.json | 6 +--- .../data/derivation/output-caFixedText.json | 6 +--- .../data/dummy-store/one-flat-file.json | 12 ++----- .../data/nar-info/json-2/impure.json | 18 ++-------- .../data/nar-info/json-2/pure.json | 12 ++----- .../data/path-info/json-2/empty_impure.json | 6 +--- .../data/path-info/json-2/empty_pure.json | 6 +--- .../data/path-info/json-2/impure.json | 12 ++----- .../data/path-info/json-2/pure.json | 12 ++----- .../data/serve-protocol/content-address.json | 18 ++-------- .../optional-content-address.json | 6 +--- .../unkeyed-valid-path-info-2.3.json | 12 ++----- .../unkeyed-valid-path-info-2.4.json | 18 ++-------- .../data/worker-protocol/content-address.json | 18 ++-------- .../optional-content-address.json | 6 +--- .../unkeyed-valid-path-info-1.15.json | 12 ++----- .../worker-protocol/valid-path-info-1.15.json | 12 ++----- .../worker-protocol/valid-path-info-1.16.json | 24 +++---------- .../data/hash/blake3-base16.json | 5 --- src/libutil-tests/data/hash/blake3.json | 1 + .../data/hash/sha256-base16.json | 5 --- .../data/hash/sha256-base64.json | 5 --- src/libutil-tests/data/hash/sha256-nix32.json | 5 --- src/libutil-tests/data/hash/sha256.json | 1 + src/libutil-tests/data/hash/sha512.json | 1 + src/libutil-tests/data/hash/simple.json | 5 --- src/libutil-tests/hash.cc | 24 ++----------- src/libutil/hash.cc | 20 ++--------- tests/functional/fixed.sh | 6 +--- tests/functional/git-hashing/simple-common.sh | 13 ++++--- tests/functional/impure-derivations.sh | 2 +- tests/functional/nix-profile.sh | 2 +- tests/functional/path-info.sh | 12 ++----- tests/functional/signing.sh | 2 +- tests/nixos/fetchers-substitute.nix | 5 ++- 44 files changed, 78 insertions(+), 348 deletions(-) delete mode 100644 src/libutil-tests/data/hash/blake3-base16.json create mode 100644 src/libutil-tests/data/hash/blake3.json delete mode 100644 src/libutil-tests/data/hash/sha256-base16.json delete mode 100644 src/libutil-tests/data/hash/sha256-base64.json delete mode 100644 src/libutil-tests/data/hash/sha256-nix32.json create mode 100644 src/libutil-tests/data/hash/sha256.json create mode 100644 src/libutil-tests/data/hash/sha512.json delete mode 100644 src/libutil-tests/data/hash/simple.json diff --git a/doc/manual/rl-next/json-format-changes.md b/doc/manual/rl-next/json-format-changes.md index e264daf04..78e543512 100644 --- a/doc/manual/rl-next/json-format-changes.md +++ b/doc/manual/rl-next/json-format-changes.md @@ -49,17 +49,10 @@ The new structured format follows the [JSON guidelines](@docroot@/development/js Content address is now a structured JSON object instead of a string: - Old: `"ca": "fixed:r:sha256:1abc..."` - - New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base16", "hash": "10c209fa..."}}` + - New: `"ca": {"method": "nar", "hash": "sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="}` - Still `null` values for input-addressed store objects -- **Structured hash fields**: - - Hash values (`narHash` and `downloadHash`) are now structured JSON objects instead of strings: - - - Old: `"narHash": "sha256:FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="` - - New: `"narHash": {"algorithm": "sha256", "format": "base16", "hash": "15e3c5608946..."}` - - Same structure applies to `downloadHash` in NAR info contexts - - The `format` field is always `"base16"` (hexadecimal) + The `hash` field uses the [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) format like other hashes. Nix currently only produces, and doesn't consume this format. diff --git a/doc/manual/source/protocols/json/hash.md b/doc/manual/source/protocols/json/hash.md index f2af5303f..3ecff4da0 100644 --- a/doc/manual/source/protocols/json/hash.md +++ b/doc/manual/source/protocols/json/hash.md @@ -5,13 +5,13 @@ ### SHA-256 ```json -{{#include schema/hash-v1/sha256-base16.json}} +{{#include schema/hash-v1/sha256.json}} ``` ### BLAKE3 ```json -{{#include schema/hash-v1/blake3-base16.json}} +{{#include schema/hash-v1/blake3.json}} ```