From bec3c5cfcd737cdca2dacb49e174f3464aae18b3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 10 Nov 2025 16:07:28 -0500 Subject: [PATCH] JSON for `Hash` now has to be `Base16` Fix #14532. As discussed on the call today: 1. We'll stick with `format = "base16"` and `hash = ""`, not do `base16 = ""`, in order to be forward compatible with supporting more versioning formats. The motivation we discussed for someday *possibly* doing this is making it easier to write very slap-dash lang2nix tools that create (not consume) derivations with dynamic derivations. 2. We will remove support for non-base16 (and make that the default, not base64) in `Hash`, so this is strictly forward contingency, *not* yet something we support. (And also not something we have concrete plans to start supporting.) --- doc/manual/rl-next/json-format-changes.md | 9 +++-- doc/manual/source/protocols/json/hash.md | 18 ++------- .../source/protocols/json/schema/hash-v1.yaml | 10 ++--- src/json-schema-checks/meson.build | 4 +- .../data/common-protocol/content-address.json | 12 +++--- .../optional-content-address.json | 4 +- .../data/content-address/nar.json | 4 +- .../data/content-address/text.json | 4 +- .../data/derivation/output-caFixedFlat.json | 4 +- .../data/derivation/output-caFixedNAR.json | 4 +- .../data/derivation/output-caFixedText.json | 4 +- .../data/dummy-store/one-flat-file.json | 8 ++-- src/libstore-tests/data/nar-info/impure.json | 12 +++--- src/libstore-tests/data/nar-info/pure.json | 8 ++-- .../data/path-info/empty_impure.json | 4 +- .../data/path-info/empty_pure.json | 4 +- src/libstore-tests/data/path-info/impure.json | 8 ++-- src/libstore-tests/data/path-info/pure.json | 8 ++-- .../data/serve-protocol/content-address.json | 12 +++--- .../optional-content-address.json | 4 +- .../unkeyed-valid-path-info-2.3.json | 8 ++-- .../unkeyed-valid-path-info-2.4.json | 12 +++--- .../data/worker-protocol/content-address.json | 12 +++--- .../optional-content-address.json | 4 +- .../unkeyed-valid-path-info-1.15.json | 8 ++-- .../worker-protocol/valid-path-info-1.15.json | 8 ++-- .../worker-protocol/valid-path-info-1.16.json | 16 ++++---- .../data/hash/blake3-base16.json | 5 +++ .../data/hash/blake3-base64.json | 5 --- .../data/hash/sha256-base16.json | 6 +-- src/libutil-tests/data/hash/simple.json | 4 +- src/libutil-tests/hash.cc | 38 +++++++------------ src/libutil/hash.cc | 13 +++++-- tests/functional/fixed.sh | 5 +-- tests/functional/git-hashing/simple-common.sh | 4 +- tests/functional/path-info.sh | 8 ++-- 36 files changed, 140 insertions(+), 161 deletions(-) create mode 100644 src/libutil-tests/data/hash/blake3-base16.json delete mode 100644 src/libutil-tests/data/hash/blake3-base64.json diff --git a/doc/manual/rl-next/json-format-changes.md b/doc/manual/rl-next/json-format-changes.md index bd7e112435a..009c1639c9b 100644 --- a/doc/manual/rl-next/json-format-changes.md +++ b/doc/manual/rl-next/json-format-changes.md @@ -19,7 +19,7 @@ The store path info JSON format has been updated from version 1 to version 2: 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": "base64", "hash": "EMIJ+giQ..."}}` + - New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base16", "hash": "10c209fa..."}}` - Still `null` values for input-addressed store objects - **Structured hash fields**: @@ -27,8 +27,9 @@ The store path info JSON format has been updated from version 1 to version 2: Hash values (`narHash` and `downloadHash`) are now structured JSON objects instead of strings: - Old: `"narHash": "sha256:FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="` - - New: `"narHash": {"algorithm": "sha256", "format": "base64", "hash": "FePFYIlM..."}` + - New: `"narHash": {"algorithm": "sha256", "format": "base16", "hash": "15e3c5608946..."}` - Same structure applies to `downloadHash` in NAR info contexts + - The `format` field is always `"base16"` (hexadecimal) Nix currently only produces, and doesn't consume this format. @@ -48,8 +49,8 @@ The derivation JSON format has been updated from version 3 to version 4: - **Consistent content addresses**: Floating content-addressed outputs now use structured JSON format. - This is the same format as `ca` in in store path info (after the new version). + This is the same format as `ca` in store path info (after the new version). Version 3 and earlier formats are *not* accepted when reading. -**Affected command**: `nix derivation`, namely it's `show` and `add` sub-commands. +**Affected command**: `nix derivation`, namely its `show` and `add` sub-commands. diff --git a/doc/manual/source/protocols/json/hash.md b/doc/manual/source/protocols/json/hash.md index 988c8466ba3..f2af5303f66 100644 --- a/doc/manual/source/protocols/json/hash.md +++ b/doc/manual/source/protocols/json/hash.md @@ -2,28 +2,16 @@ ## Examples -### SHA-256 with Base64 encoding - -```json -{{#include schema/hash-v1/sha256-base64.json}} -``` - -### SHA-256 with Base16 (hexadecimal) encoding +### SHA-256 ```json {{#include schema/hash-v1/sha256-base16.json}} ``` -### SHA-256 with Nix32 encoding - -```json -{{#include schema/hash-v1/sha256-nix32.json}} -``` - -### BLAKE3 with Base64 encoding +### BLAKE3 ```json -{{#include schema/hash-v1/blake3-base64.json}} +{{#include schema/hash-v1/blake3-base16.json}} ```