Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions doc/manual/rl-next/json-format-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -87,7 +80,7 @@ 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.
Fixed content-addressed outputs now use structured JSON format.
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.
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/source/protocols/json/hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
```

<!-- need to convert YAML to JSON first
Expand Down
35 changes: 6 additions & 29 deletions doc/manual/source/protocols/json/schema/hash-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,13 @@ title: Hash
description: |
A cryptographic hash value used throughout Nix for content addressing and integrity verification.

This schema describes the JSON representation of Nix's `Hash` type.
type: object
properties:
algorithm:
"$ref": "#/$defs/algorithm"
format:
type: string
enum:
- base16
title: Hash format
description: |
The encoding format of the hash value.

`base16` (lowercase hexadecimal) is the only format that is currently supported for JSON serialization.
This field exists primarily to reduce ambiguity about what the hash means.
It would also help us support other formats in the future, but there are no concrete plans to do so at this.
hash:
type: string
title: Hash
description: |
The encoded hash value, itself.
This schema describes the JSON representation of Nix's `Hash` type as an [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) string.
type: string
pattern: "^(blake3|md5|sha1|sha256|sha512)-[A-Za-z0-9+/]+=*$"
examples:
- "sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="
- "sha512-IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="

It is specified in the format specified by the `format` field.
It must be the right length for the hash algorithm specified in the `algorithm` field, also.
The hash value does not include any algorithm prefix.
required:
- algorithm
- format
- hash
additionalProperties: false
"$defs":
algorithm:
type: string
Expand Down
4 changes: 2 additions & 2 deletions src/json-schema-checks/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ schemas = [
'stem' : 'hash',
'schema' : schema_dir / 'hash-v1.yaml',
'files' : [
'sha256-base16.json',
'blake3-base16.json',
'sha256.json',
'blake3.json',
],
},
{
Expand Down
18 changes: 3 additions & 15 deletions src/libstore-tests/data/common-protocol/content-address.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
[
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "f9773d2e5ea670f96dc1a7b0ae4fc1010e7a6371b94ffff0ce1294734ceb62ed"
},
"hash": "sha256-+Xc9Ll6mcPltwaewrk/BAQ56Y3G5T//wzhKUc0zrYu0=",
"method": "text"
},
{
"hash": {
"algorithm": "sha1",
"format": "base16",
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
},
"hash": "sha1-gGemBoenViNZM3hiwqns/Fgzqwo=",
"method": "flat"
},
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
}
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[
null,
{
"hash": {
"algorithm": "sha1",
"format": "base16",
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
},
"hash": "sha1-gGemBoenViNZM3hiwqns/Fgzqwo=",
"method": "flat"
}
]
6 changes: 1 addition & 5 deletions src/libstore-tests/data/content-address/nar.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "f6f2ea8f45d8a057c9566a33f99474da2e5c6a6604d736121650e2730c6fb0a3"
},
"hash": "sha256-9vLqj0XYoFfJVmoz+ZR02i5camYE1zYSFlDicwxvsKM=",
"method": "nar"
}
6 changes: 1 addition & 5 deletions src/libstore-tests/data/content-address/text.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
},
"hash": "sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts=",
"method": "text"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f"
},
"hash": "sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8=",
"method": "flat"
}
6 changes: 1 addition & 5 deletions src/libstore-tests/data/derivation/output-caFixedNAR.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f"
},
"hash": "sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8=",
"method": "nar"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f"
},
"hash": "sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8=",
"method": "text"
}
12 changes: 2 additions & 10 deletions src/libstore-tests/data/dummy-store/one-flat-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@
},
"info": {
"ca": {
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "7f579dbae488602d41a1f5c0d6dc9c17bf408b635230942d504af1e43c4b6125"
},
"hash": "sha256-f1eduuSIYC1BofXA1tycF79Ai2NSMJQtUErx5DxLYSU=",
"method": "nar"
},
"deriver": null,
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "7f579dbae488602d41a1f5c0d6dc9c17bf408b635230942d504af1e43c4b6125"
},
"narHash": "sha256-f1eduuSIYC1BofXA1tycF79Ai2NSMJQtUErx5DxLYSU=",
"narSize": 120,
"references": [],
"registrationTime": null,
Expand Down
18 changes: 3 additions & 15 deletions src/libstore-tests/data/nar-info/json-2/impure.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
{
"ca": {
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
},
"compression": "xz",
"deriver": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
"downloadHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"downloadHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"downloadSize": 4029176,
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 34878,
"references": [
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
Expand Down
12 changes: 2 additions & 10 deletions src/libstore-tests/data/nar-info/json-2/pure.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
{
"ca": {
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
},
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 34878,
"references": [
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"ca": null,
"deriver": null,
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 0,
"references": [],
"registrationTime": null,
Expand Down
6 changes: 1 addition & 5 deletions src/libstore-tests/data/path-info/json-2/empty_pure.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"ca": null,
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 0,
"references": [],
"storeDir": "/nix/store",
Expand Down
12 changes: 2 additions & 10 deletions src/libstore-tests/data/path-info/json-2/impure.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
{
"ca": {
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
},
"deriver": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 34878,
"references": [
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
Expand Down
12 changes: 2 additions & 10 deletions src/libstore-tests/data/path-info/json-2/pure.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
{
"ca": {
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
},
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527"
},
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"narSize": 34878,
"references": [
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
Expand Down
18 changes: 3 additions & 15 deletions src/libstore-tests/data/serve-protocol/content-address.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
[
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "f9773d2e5ea670f96dc1a7b0ae4fc1010e7a6371b94ffff0ce1294734ceb62ed"
},
"hash": "sha256-+Xc9Ll6mcPltwaewrk/BAQ56Y3G5T//wzhKUc0zrYu0=",
"method": "text"
},
{
"hash": {
"algorithm": "sha1",
"format": "base16",
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
},
"hash": "sha1-gGemBoenViNZM3hiwqns/Fgzqwo=",
"method": "flat"
},
{
"hash": {
"algorithm": "sha256",
"format": "base16",
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
},
"hash": "sha256-EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM=",
"method": "nar"
}
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[
null,
{
"hash": {
"algorithm": "sha1",
"format": "base16",
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
},
"hash": "sha1-gGemBoenViNZM3hiwqns/Fgzqwo=",
"method": "flat"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
{
"ca": null,
"deriver": null,
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "0000000000000000000000000000000000000000000000000000000000000000"
},
"narHash": "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"narSize": 34878,
"references": [],
"registrationTime": null,
Expand All @@ -18,11 +14,7 @@
{
"ca": null,
"deriver": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
"narHash": {
"algorithm": "sha256",
"format": "base16",
"hash": "0000000000000000000000000000000000000000000000000000000000000000"
},
"narHash": "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"narSize": 34878,
"references": [
"g1w7hyyyy1w7hy3qg1w7hy3qgqqqqy3q-foo.drv"
Expand Down
Loading
Loading