mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Change JSON derivation format to use ContentAddress JSON
Keeps it more consistent.
This commit is contained in:
parent
82a736bcbb
commit
d7464ecd96
20 changed files with 52 additions and 44 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{{#include derivation-v3-fixed.md}}
|
{{#include derivation-v4-fixed.md}}
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
## Raw Schema
|
## Raw Schema
|
||||||
|
|
||||||
[JSON Schema for Derivation v3](schema/derivation-v3.json)
|
[JSON Schema for Derivation v3](schema/derivation-v4.json)
|
||||||
-->
|
-->
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ schemas = [
|
||||||
'file-system-object-v1',
|
'file-system-object-v1',
|
||||||
'hash-v1',
|
'hash-v1',
|
||||||
'content-address-v1',
|
'content-address-v1',
|
||||||
'derivation-v3',
|
'derivation-v4',
|
||||||
]
|
]
|
||||||
|
|
||||||
schema_files = files()
|
schema_files = files()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
"$schema": http://json-schema.org/draft-04/schema#
|
"$schema": http://json-schema.org/draft-04/schema#
|
||||||
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json
|
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v4.json
|
||||||
title: Derivation
|
title: Derivation
|
||||||
description: |
|
description: |
|
||||||
Experimental JSON representation of a Nix derivation (version 3).
|
Experimental JSON representation of a Nix derivation (version 3).
|
||||||
|
|
@ -32,10 +32,10 @@ properties:
|
||||||
Used when calculating store paths for the derivation’s outputs.
|
Used when calculating store paths for the derivation’s outputs.
|
||||||
|
|
||||||
version:
|
version:
|
||||||
const: 3
|
const: 4
|
||||||
title: Format version (must be 3)
|
title: Format version (must be 3)
|
||||||
description: |
|
description: |
|
||||||
Must be `3`.
|
Must be `4`.
|
||||||
This is a guard that allows us to continue evolving this format.
|
This is a guard that allows us to continue evolving this format.
|
||||||
The choice of `3` is fairly arbitrary, but corresponds to this informal version:
|
The choice of `3` is fairly arbitrary, but corresponds to this informal version:
|
||||||
|
|
||||||
|
|
@ -47,6 +47,8 @@ properties:
|
||||||
|
|
||||||
- Version 3: Drop store dir from store paths, just include base name.
|
- Version 3: Drop store dir from store paths, just include base name.
|
||||||
|
|
||||||
|
- Version 4: Use canonical content address JSON format for floating content addressed derivation outputs.
|
||||||
|
|
||||||
Note that while this format is experimental, the maintenance of versions is best-effort, and not promised to identify every change.
|
Note that while this format is experimental, the maintenance of versions is best-effort, and not promised to identify every change.
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
|
|
@ -161,9 +163,11 @@ properties:
|
||||||
hashAlgo:
|
hashAlgo:
|
||||||
title: Hash algorithm
|
title: Hash algorithm
|
||||||
"$ref": "./hash-v1.yaml#/$defs/algorithm"
|
"$ref": "./hash-v1.yaml#/$defs/algorithm"
|
||||||
|
description: |
|
||||||
|
For an output which will be [content addressed], but the content address is not specified up front, the name of the hash algorithm used. When the content address is fixed, use `hash.hashAlgo` instead.
|
||||||
|
|
||||||
hash:
|
hash:
|
||||||
type: string
|
|
||||||
title: Expected hash value
|
title: Expected hash value
|
||||||
description: |
|
description: |
|
||||||
For fixed-output derivations, the expected content hash in base-16.
|
For fixed-output derivations, the expected content hash.
|
||||||
|
"$ref": "./hash-v1.yaml"
|
||||||
|
|
@ -48,7 +48,7 @@ schemas = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'stem' : 'derivation',
|
'stem' : 'derivation',
|
||||||
'schema' : schema_dir / 'derivation-v3.yaml',
|
'schema' : schema_dir / 'derivation-v4.yaml',
|
||||||
'files' : [
|
'files' : [
|
||||||
'dyn-dep-derivation.json',
|
'dyn-dep-derivation.json',
|
||||||
'simple-derivation.json',
|
'simple-derivation.json',
|
||||||
|
|
@ -57,7 +57,7 @@ schemas = [
|
||||||
# # Not sure how to make subschema work
|
# # Not sure how to make subschema work
|
||||||
# {
|
# {
|
||||||
# 'stem': 'derivation',
|
# 'stem': 'derivation',
|
||||||
# 'schema': schema_dir / 'derivation-v3.yaml#output',
|
# 'schema': schema_dir / 'derivation-v4.yaml#output',
|
||||||
# 'files' : [
|
# 'files' : [
|
||||||
# 'output-caFixedFlat.json',
|
# 'output-caFixedFlat.json',
|
||||||
# 'output-caFixedNAR.json',
|
# 'output-caFixedNAR.json',
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,5 @@
|
||||||
"system": "my-system"
|
"system": "my-system"
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,5 +101,5 @@
|
||||||
"system": "my-system"
|
"system": "my-system"
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,5 +52,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "x86_64-linux",
|
"system": "x86_64-linux",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,5 +35,5 @@
|
||||||
"name": "dyn-dep-derivation",
|
"name": "dyn-dep-derivation",
|
||||||
"outputs": {},
|
"outputs": {},
|
||||||
"system": "wasm-sel4",
|
"system": "wasm-sel4",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,5 @@
|
||||||
"system": "my-system"
|
"system": "my-system"
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,5 +96,5 @@
|
||||||
"system": "my-system"
|
"system": "my-system"
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,5 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "my-system",
|
"system": "my-system",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
"hash": {
|
||||||
"hashAlgo": "sha256",
|
"algorithm": "sha256",
|
||||||
|
"format": "base64",
|
||||||
|
"hash": "iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="
|
||||||
|
},
|
||||||
"method": "flat"
|
"method": "flat"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
"hash": {
|
||||||
"hashAlgo": "sha256",
|
"algorithm": "sha256",
|
||||||
|
"format": "base64",
|
||||||
|
"hash": "iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="
|
||||||
|
},
|
||||||
"method": "nar"
|
"method": "nar"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
"hash": {
|
||||||
"hashAlgo": "sha256",
|
"algorithm": "sha256",
|
||||||
|
"format": "base64",
|
||||||
|
"hash": "iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="
|
||||||
|
},
|
||||||
"method": "text"
|
"method": "text"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,5 @@
|
||||||
"name": "simple-derivation",
|
"name": "simple-derivation",
|
||||||
"outputs": {},
|
"outputs": {},
|
||||||
"system": "wasm-sel4",
|
"system": "wasm-sel4",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1293,15 +1293,13 @@ void adl_serializer<DerivationOutput>::to_json(json & res, const DerivationOutpu
|
||||||
overloaded{
|
overloaded{
|
||||||
[&](const DerivationOutput::InputAddressed & doi) { res["path"] = doi.path; },
|
[&](const DerivationOutput::InputAddressed & doi) { res["path"] = doi.path; },
|
||||||
[&](const DerivationOutput::CAFixed & dof) {
|
[&](const DerivationOutput::CAFixed & dof) {
|
||||||
|
res = dof.ca;
|
||||||
|
// FIXME print refs?
|
||||||
/* it would be nice to output the path for user convenience, but
|
/* it would be nice to output the path for user convenience, but
|
||||||
this would require us to know the store dir. */
|
this would require us to know the store dir. */
|
||||||
#if 0
|
#if 0
|
||||||
res["path"] = dof.path(store, drvName, outputName);
|
res["path"] = dof.path(store, drvName, outputName);
|
||||||
#endif
|
#endif
|
||||||
res["method"] = std::string{dof.ca.method.render()};
|
|
||||||
res["hashAlgo"] = printHashAlgo(dof.ca.hash.algo);
|
|
||||||
res["hash"] = dof.ca.hash.to_string(HashFormat::Base16, false);
|
|
||||||
// FIXME print refs?
|
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
res["method"] = std::string{dof.method.render()};
|
res["method"] = std::string{dof.method.render()};
|
||||||
|
|
@ -1341,15 +1339,12 @@ adl_serializer<DerivationOutput>::from_json(const json & _json, const Experiment
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (keys == (std::set<std::string_view>{"method", "hashAlgo", "hash"})) {
|
else if (keys == (std::set<std::string_view>{"method", "hash"})) {
|
||||||
auto [method, hashAlgo] = methodAlgo();
|
|
||||||
auto dof = DerivationOutput::CAFixed{
|
auto dof = DerivationOutput::CAFixed{
|
||||||
.ca =
|
.ca = static_cast<ContentAddress>(_json),
|
||||||
ContentAddress{
|
|
||||||
.method = std::move(method),
|
|
||||||
.hash = Hash::parseNonSRIUnprefixed(getString(valueAt(json, "hash")), hashAlgo),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
if (dof.ca.method == ContentAddressMethod::Raw::Text)
|
||||||
|
xpSettings.require(Xp::DynamicDerivations, "text-hashed derivation output in JSON");
|
||||||
/* We no longer produce this (denormalized) field (for the
|
/* We no longer produce this (denormalized) field (for the
|
||||||
reasons described above), so we don't need to check it. */
|
reasons described above), so we don't need to check it. */
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -1392,7 +1387,7 @@ void adl_serializer<Derivation>::to_json(json & res, const Derivation & d)
|
||||||
|
|
||||||
res["name"] = d.name;
|
res["name"] = d.name;
|
||||||
|
|
||||||
res["version"] = 3;
|
res["version"] = 4;
|
||||||
|
|
||||||
{
|
{
|
||||||
nlohmann::json & outputsObj = res["outputs"];
|
nlohmann::json & outputsObj = res["outputs"];
|
||||||
|
|
@ -1450,8 +1445,8 @@ Derivation adl_serializer<Derivation>::from_json(const json & _json, const Exper
|
||||||
|
|
||||||
res.name = getString(valueAt(json, "name"));
|
res.name = getString(valueAt(json, "name"));
|
||||||
|
|
||||||
if (valueAt(json, "version") != 3)
|
if (valueAt(json, "version") != 4)
|
||||||
throw Error("Only derivation format version 3 is currently supported.");
|
throw Error("Only derivation format version 4 is currently supported.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto outputs = getObject(valueAt(json, "outputs"));
|
auto outputs = getObject(valueAt(json, "outputs"));
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ builtins.outputOf
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system": "${system}",
|
"system": "${system}",
|
||||||
"version": 3
|
"version": 4
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
drvPath=$(echo "$json" | nix derivation add)
|
drvPath=$(echo "$json" | nix derivation add)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue