chore(tvix/derivation): align json serialization with nix output

Use the #[serde(rename = "…")] field attributes to match the field names
that Nix uses in its JSON output (nix show-derivation).

This allows us to just re-use the exact same fixtures from go-nix,
without manual post-massaging.

Change-Id: Ifd5c08e43cd4f50d5e02903eccd8cb37230b70a6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7757
Reviewed-by: jrhahn <mail.jhahn@gmail.com>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-01-04 19:26:05 +01:00 committed by flokli
parent 77cc6a1f78
commit 407a9cd90f
11 changed files with 113 additions and 103 deletions

View file

@ -9,13 +9,23 @@ use tvix_store::nixpath::STORE_DIR;
#[derive(Serialize, Deserialize)]
pub struct Derivation {
pub outputs: BTreeMap<String, Output>,
pub input_sources: Vec<String>,
pub input_derivations: BTreeMap<String, Vec<String>>,
pub platform: String,
pub builder: String,
#[serde(rename = "args")]
pub arguments: Vec<String>,
pub builder: String,
#[serde(rename = "env")]
pub environment: BTreeMap<String, String>,
#[serde(rename = "inputDrvs")]
pub input_derivations: BTreeMap<String, Vec<String>>,
#[serde(rename = "inputSrcs")]
pub input_sources: Vec<String>,
pub outputs: BTreeMap<String, Output>,
pub system: String,
}
impl Derivation {
@ -26,7 +36,7 @@ impl Derivation {
write::write_outputs(writer, &self.outputs)?;
write::write_input_derivations(writer, &self.input_derivations)?;
write::write_input_sources(writer, &self.input_sources)?;
write::write_platfrom(writer, &self.platform)?;
write::write_system(writer, &self.system)?;
write::write_builder(writer, &self.builder)?;
write::write_arguments(writer, &self.arguments)?;
write::write_enviroment(writer, &self.environment)?;

View file

@ -12,7 +12,7 @@ pub struct Output {
pub struct Hash {
#[serde(rename = "hash")]
pub digest: String,
#[serde(rename = "hash_algorithm")]
#[serde(rename = "hashAlgo")]
pub algo: String,
}

View file

@ -1,17 +1,7 @@
{
"outputs": {
"out": {
"path": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
"hash_algorithm": "r:sha256",
"hash": "08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
{
"args": [],
"builder": ":",
"arguments": [],
"environment": {
"env": {
"builder": ":",
"name": "bar",
"out": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
@ -19,5 +9,15 @@
"outputHashAlgo": "sha256",
"outputHashMode": "recursive",
"system": ":"
}
},
"inputDrvs": {},
"inputSrcs": [],
"outputs": {
"out": {
"hash": "08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba",
"hashAlgo": "r:sha256",
"path": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar"
}
},
"system": ":"
}

View file

@ -1,19 +1,19 @@
{
"outputs": {
"out": {
"path": "/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
"args": [],
"builder": ":",
"arguments": [],
"environment": {
"env": {
"builder": ":",
"json": "{\"hello\":\"moto\\n\"}",
"name": "nested-json",
"out": "/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json",
"system": ":"
}
},
"inputDrvs": {},
"inputSrcs": [],
"outputs": {
"out": {
"path": "/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json"
}
},
"system": ":"
}

View file

@ -1,23 +1,23 @@
{
"outputs": {
"out": {
"path": "/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo"
}
},
"input_sources": [],
"input_derivations": {
"/nix/store/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv": [
"out"
]
},
"platform": ":",
"args": [],
"builder": ":",
"arguments": [],
"environment": {
"env": {
"bar": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
"builder": ":",
"name": "foo",
"out": "/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo",
"system": ":"
}
},
"inputDrvs": {
"/nix/store/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv": [
"out"
]
},
"inputSrcs": [],
"outputs": {
"out": {
"path": "/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo"
}
},
"system": ":"
}

View file

@ -4,12 +4,12 @@
"path": "/nix/store/vgvdj6nf7s8kvfbl2skbpwz9kc7xjazc-unicode"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
"inputSrcs": [],
"inputDrvs": {},
"system": ":",
"builder": ":",
"arguments": [],
"environment": {
"args": [],
"env": {
"builder": ":",
"letters": "räksmörgås\nrødgrød med fløde\nLübeck\n肥猪\nこんにちは / 今日は\n🌮\n",
"name": "unicode",

View file

@ -1,16 +1,16 @@
{
"args": [],
"builder": ":",
"env": {
"__json": "{\"builder\":\":\",\"name\":\"structured-attrs\",\"system\":\":\"}",
"out": "/nix/store/6a39dl014j57bqka7qx25k0vb20vkqm6-structured-attrs"
},
"inputDrvs": {},
"inputSrcs": [],
"outputs": {
"out": {
"path": "/nix/store/6a39dl014j57bqka7qx25k0vb20vkqm6-structured-attrs"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
"builder": ":",
"arguments": [],
"environment": {
"__json": "{\"builder\":\":\",\"name\":\"structured-attrs\",\"system\":\":\"}",
"out": "/nix/store/6a39dl014j57bqka7qx25k0vb20vkqm6-structured-attrs"
}
"system": ":"
}

View file

@ -1,23 +1,23 @@
{
"outputs": {
"out": {
"path": "/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo"
}
},
"input_sources": [],
"input_derivations": {
"/nix/store/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv": [
"out"
]
},
"platform": ":",
"args": [],
"builder": ":",
"arguments": [],
"environment": {
"env": {
"bar": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
"builder": ":",
"name": "foo",
"out": "/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo",
"system": ":"
}
},
"inputDrvs": {
"/nix/store/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv": [
"out"
]
},
"inputSrcs": [],
"outputs": {
"out": {
"path": "/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo"
}
},
"system": ":"
}

View file

@ -1,4 +1,16 @@
{
"args": [],
"builder": ":",
"env": {
"builder": ":",
"lib": "/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib",
"name": "has-multi-out",
"out": "/nix/store/55lwldka5nyxa08wnvlizyqw02ihy8ic-has-multi-out",
"outputs": "out lib",
"system": ":"
},
"inputDrvs": {},
"inputSrcs": [],
"outputs": {
"lib": {
"path": "/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib"
@ -7,17 +19,5 @@
"path": "/nix/store/55lwldka5nyxa08wnvlizyqw02ihy8ic-has-multi-out"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
"builder": ":",
"arguments": [],
"environment": {
"builder": ":",
"lib": "/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib",
"name": "has-multi-out",
"out": "/nix/store/55lwldka5nyxa08wnvlizyqw02ihy8ic-has-multi-out",
"outputs": "out lib",
"system": ":"
}
"system": ":"
}

View file

@ -1,17 +1,7 @@
{
"outputs": {
"out": {
"path": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
"hash_algorithm": "r:sha1",
"hash": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
}
},
"input_sources": [],
"input_derivations": {},
"platform": ":",
"args": [],
"builder": ":",
"arguments": [],
"environment": {
"env": {
"builder": ":",
"name": "bar",
"out": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
@ -19,5 +9,15 @@
"outputHashAlgo": "sha1",
"outputHashMode": "recursive",
"system": ":"
}
},
"inputDrvs": {},
"inputSrcs": [],
"outputs": {
"out": {
"hash": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
"hashAlgo": "r:sha1",
"path": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar"
}
},
"system": ":"
}

View file

@ -133,7 +133,7 @@ pub fn write_input_sources(
Ok(())
}
pub fn write_platfrom(writer: &mut impl Write, platform: &str) -> Result<(), fmt::Error> {
pub fn write_system(writer: &mut impl Write, platform: &str) -> Result<(), fmt::Error> {
writer.write_char(COMMA)?;
writer.write_str(escape_string(platform).as_str())?;
Ok(())