Skip to content

Use SRI hash (strings) as the official JSON format for Hash after all#14743

Merged
Ericson2314 merged 3 commits intomasterfrom
sri-in-json
Dec 8, 2025
Merged

Use SRI hash (strings) as the official JSON format for Hash after all#14743
Ericson2314 merged 3 commits intomasterfrom
sri-in-json

Conversation

@Ericson2314
Copy link
Member

Motivation

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.

Context

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.)


Add 👍 to pull requests you find important.

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

@Ericson2314 Ericson2314 requested a review from edolstra as a code owner December 8, 2025 21:12
@github-actions github-actions bot added documentation with-tests Issues related to testing. PRs with tests have some priority labels Dec 8, 2025
This will be used for unit testing.
Floating CA outputs just have a hash algorith, not a whole hash. It is
fixed ones which are a pair of a method and a hash, just like the `ca`
field of store object info.
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.)
narHash_obj = path_info_dict[os.path.basename(tarball_store_path)]["narHash"]
# Convert from structured format {"algorithm": "sha256", "format": "base16", "hash": "..."} to SRI string
tarball_hash_sri = substituter.succeed(f"nix hash convert --to sri {narHash_obj['algorithm']}:{narHash_obj['hash']}").strip()
# narHash is already in SRI format
Copy link
Member

Choose a reason for hiding this comment

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

Redundant comment

Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

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

Otherwise looks good.

@Ericson2314 Ericson2314 added this pull request to the merge queue Dec 8, 2025
Merged via the queue into master with commit bc0af77 Dec 8, 2025
20 checks passed
@Ericson2314 Ericson2314 deleted the sri-in-json branch December 8, 2025 23:24
@edolstra edolstra mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 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