mirror of
https://github.com/NixOS/nix.git
synced 2025-12-17 14:31:06 +01:00
Introduce --json-format for nix path-info
As discussed today at great length in the Nix meeting, we don't want to break the format, but we also don't want to impede the improvement of JSON formats. The solution is to add a new flag for control the output format. Note that prior to the release, we may want to replace `--json --json-format N` with `--json=N`, but this is being left for a separate PR, as we don't yet have `=` support for CLI flags.
This commit is contained in:
parent
69920f9557
commit
1ad13a1423
36 changed files with 464 additions and 132 deletions
|
|
@ -117,12 +117,12 @@
|
|||
tarball_store_path = json.loads(tarball_store_path_json)
|
||||
|
||||
# Get the NAR hash of the unpacked tarball in SRI format
|
||||
path_info_json = substituter.succeed(f"nix path-info --json {tarball_store_path}").strip()
|
||||
path_info_json = substituter.succeed(f"nix path-info --json-format 2 --json {tarball_store_path}").strip()
|
||||
path_info_dict = json.loads(path_info_json)
|
||||
# nix path-info returns a dict with store paths as keys
|
||||
narHash_obj = path_info_dict[tarball_store_path]["narHash"]
|
||||
# Convert from structured format {"algorithm": "sha256", "format": "base64", "hash": "..."} to SRI string
|
||||
tarball_hash_sri = f"{narHash_obj['algorithm']}-{narHash_obj['hash']}"
|
||||
# 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()
|
||||
print(f"Tarball NAR hash (SRI): {tarball_hash_sri}")
|
||||
|
||||
# Also get the old format hash for fetchTarball (which uses sha256 parameter)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue