feat(tvix/derivation): serialize Nix Derivation
This adds a Derivation structure and allows to write it to a structure that implements std::fmt:Write. The implementation is based on the go-nix version. Change-Id: Ib54e1202b5c67f5d206b21bc109a751e971064cf Reviewed-on: https://cl.tvl.fyi/c/depot/+/7659 Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
42fe3941c2
commit
bb185b2c6e
22 changed files with 516 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar","r:sha256","08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba")],[],[],":",":",[],[("builder",":"),("name","bar"),("out","/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar"),("outputHash","08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba"),("outputHashAlgo","sha256"),("outputHashMode","recursive"),("system",":")])
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
|
||||
"hash_algorithm": "r:sha256",
|
||||
"hash": "08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"builder": ":",
|
||||
"name": "bar",
|
||||
"out": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
|
||||
"outputHash": "08813cbee9903c62be4c5027726a418a300da4500b2d369d3af9286f4815ceba",
|
||||
"outputHashAlgo": "sha256",
|
||||
"outputHashMode": "recursive",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json","","")],[],[],":",":",[],[("builder",":"),("json","{\"hello\":\"moto\\n\"}"),("name","nested-json"),("out","/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json"),("system",":")])
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"builder": ":",
|
||||
"json": "{\"hello\":\"moto\\n\"}",
|
||||
"name": "nested-json",
|
||||
"out": "/nix/store/pzr7lsd3q9pqsnb42r9b23jc5sh8irvn-nested-json",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo","","")],[("/nix/store/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv",["out"])],[],":",":",[],[("bar","/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar"),("builder",":"),("name","foo"),("out","/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo"),("system",":")])
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {
|
||||
"/nix/store/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv": [
|
||||
"out"
|
||||
]
|
||||
},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"bar": "/nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar",
|
||||
"builder": ":",
|
||||
"name": "foo",
|
||||
"out": "/nix/store/5vyvcwah9l9kf07d52rcgdk70g2f4y13-foo",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/vgvdj6nf7s8kvfbl2skbpwz9kc7xjazc-unicode","","")],[],[],":",":",[],[("builder",":"),("letters","räksmörgås\nrødgrød med fløde\nLübeck\n肥猪\nこんにちは / 今日は\n🌮\n"),("name","unicode"),("out","/nix/store/vgvdj6nf7s8kvfbl2skbpwz9kc7xjazc-unicode"),("system",":")])
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/vgvdj6nf7s8kvfbl2skbpwz9kc7xjazc-unicode"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"builder": ":",
|
||||
"letters": "räksmörgås\nrødgrød med fløde\nLübeck\n肥猪\nこんにちは / 今日は\n🌮\n",
|
||||
"name": "unicode",
|
||||
"out": "/nix/store/vgvdj6nf7s8kvfbl2skbpwz9kc7xjazc-unicode",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/6a39dl014j57bqka7qx25k0vb20vkqm6-structured-attrs","","")],[],[],":",":",[],[("__json","{\"builder\":\":\",\"name\":\"structured-attrs\",\"system\":\":\"}"),("out","/nix/store/6a39dl014j57bqka7qx25k0vb20vkqm6-structured-attrs")])
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo","","")],[("/nix/store/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv",["out"])],[],":",":",[],[("bar","/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar"),("builder",":"),("name","foo"),("out","/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo"),("system",":")])
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {
|
||||
"/nix/store/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv": [
|
||||
"out"
|
||||
]
|
||||
},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"bar": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
|
||||
"builder": ":",
|
||||
"name": "foo",
|
||||
"out": "/nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("lib","/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib","",""),("out","/nix/store/55lwldka5nyxa08wnvlizyqw02ihy8ic-has-multi-out","","")],[],[],":",":",[],[("builder",":"),("lib","/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib"),("name","has-multi-out"),("out","/nix/store/55lwldka5nyxa08wnvlizyqw02ihy8ic-has-multi-out"),("outputs","out lib"),("system",":")])
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"outputs": {
|
||||
"lib": {
|
||||
"path": "/nix/store/2vixb94v0hy2xc6p7mbnxxcyc095yyia-has-multi-out-lib"
|
||||
},
|
||||
"out": {
|
||||
"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": ":"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Derive([("out","/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar","r:sha1","0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")],[],[],":",":",[],[("builder",":"),("name","bar"),("out","/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar"),("outputHash","0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"),("outputHashAlgo","sha1"),("outputHashMode","recursive"),("system",":")])
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"outputs": {
|
||||
"out": {
|
||||
"path": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
|
||||
"hash_algorithm": "r:sha1",
|
||||
"hash": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
|
||||
}
|
||||
},
|
||||
"input_sources": [],
|
||||
"input_derivations": {},
|
||||
"platform": ":",
|
||||
"builder": ":",
|
||||
"arguments": [],
|
||||
"environment": {
|
||||
"builder": ":",
|
||||
"name": "bar",
|
||||
"out": "/nix/store/mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar",
|
||||
"outputHash": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
|
||||
"outputHashAlgo": "sha1",
|
||||
"outputHashMode": "recursive",
|
||||
"system": ":"
|
||||
}
|
||||
}
|
||||
32
tvix/derivation/src/tests/mod.rs
Normal file
32
tvix/derivation/src/tests/mod.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use super::{serialize_derivation, Derivation};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use test_generator::test_resources;
|
||||
|
||||
fn read_file(path: &str) -> String {
|
||||
let path = Path::new(path);
|
||||
let mut file = File::open(path).unwrap();
|
||||
let mut data = String::new();
|
||||
|
||||
file.read_to_string(&mut data).unwrap();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
fn assert_derivation_ok(path_to_drv_file: &str) {
|
||||
let data = read_file(&format!("{}.json", path_to_drv_file));
|
||||
let derivation: Derivation = serde_json::from_str(&data).expect("JSON was not well-formatted");
|
||||
|
||||
let mut serialized_derivation = String::new();
|
||||
serialize_derivation(derivation, &mut serialized_derivation).unwrap();
|
||||
|
||||
let expected = read_file(path_to_drv_file);
|
||||
|
||||
assert_eq!(expected, serialized_derivation);
|
||||
}
|
||||
|
||||
#[test_resources("src/tests/derivation_tests/*.drv")]
|
||||
fn derivation_files_ok(path: &str) {
|
||||
assert_derivation_ok(path);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue