about summary refs log tree commit diff
path: root/tvix/derivation/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-04T18·26+0100
committerflokli <flokli@flokli.de>2023-01-04T21·58+0000
commit407a9cd90f3a1ea3bb0cf4ced85cfacb29881b0c (patch)
tree410abc93db13321114090a855e58b070c9a4069f /tvix/derivation/src
parent77cc6a1f785caad0c5fb84457013177a99aaf158 (diff)
chore(tvix/derivation): align json serialization with nix output r/5590
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>
Diffstat (limited to 'tvix/derivation/src')
-rw-r--r--tvix/derivation/src/derivation.rs22
-rw-r--r--tvix/derivation/src/output.rs2
-rw-r--r--tvix/derivation/src/tests/derivation_tests/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv.json28
-rw-r--r--tvix/derivation/src/tests/derivation_tests/292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv.json22
-rw-r--r--tvix/derivation/src/tests/derivation_tests/4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv.json30
-rw-r--r--tvix/derivation/src/tests/derivation_tests/52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv.json10
-rw-r--r--tvix/derivation/src/tests/derivation_tests/9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv.json18
-rw-r--r--tvix/derivation/src/tests/derivation_tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv.json30
-rw-r--r--tvix/derivation/src/tests/derivation_tests/h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv.json26
-rw-r--r--tvix/derivation/src/tests/derivation_tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv.json26
-rw-r--r--tvix/derivation/src/write.rs2
11 files changed, 113 insertions, 103 deletions
diff --git a/tvix/derivation/src/derivation.rs b/tvix/derivation/src/derivation.rs
index bed2cc74b29b..a1a05abea601 100644
--- a/tvix/derivation/src/derivation.rs
+++ b/tvix/derivation/src/derivation.rs
@@ -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)?;
diff --git a/tvix/derivation/src/output.rs b/tvix/derivation/src/output.rs
index 69ae8167e972..0d668c3e9952 100644
--- a/tvix/derivation/src/output.rs
+++ b/tvix/derivation/src/output.rs
@@ -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,
 }
 
diff --git a/tvix/derivation/src/tests/derivation_tests/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv.json b/tvix/derivation/src/tests/derivation_tests/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv.json
index abaaa8d4a6fc..c8bbc4cbb5be 100644
--- a/tvix/derivation/src/tests/derivation_tests/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/0hm2f1psjpcwg8fijsmr4wwxrx59s092-bar.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv.json b/tvix/derivation/src/tests/derivation_tests/292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv.json
index a1b763ec9449..9cb0b43b4c09 100644
--- a/tvix/derivation/src/tests/derivation_tests/292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/292w8yzv5nn7nhdpxcs8b7vby2p27s09-nested-json.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv.json b/tvix/derivation/src/tests/derivation_tests/4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv.json
index f6bb5be234d1..957a85ccab82 100644
--- a/tvix/derivation/src/tests/derivation_tests/4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv.json b/tvix/derivation/src/tests/derivation_tests/52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv.json
index bf837b3e8665..f8f33c1bba17 100644
--- a/tvix/derivation/src/tests/derivation_tests/52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/52a9id8hx688hvlnz4d1n25ml1jdykz0-unicode.drv.json
@@ -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",
diff --git a/tvix/derivation/src/tests/derivation_tests/9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv.json b/tvix/derivation/src/tests/derivation_tests/9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv.json
index 97f99acdb140..74e3d7df55c5 100644
--- a/tvix/derivation/src/tests/derivation_tests/9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/9lj1lkjm2ag622mh4h9rpy6j607an8g2-structured-attrs.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv.json b/tvix/derivation/src/tests/derivation_tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv.json
index 2d7dbeb75299..831d27956d86 100644
--- a/tvix/derivation/src/tests/derivation_tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv.json b/tvix/derivation/src/tests/derivation_tests/h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv.json
index 12cb3481980e..0bd7a2991cc7 100644
--- a/tvix/derivation/src/tests/derivation_tests/h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/h32dahq0bx5rp1krcdx3a53asj21jvhk-has-multi-out.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/tests/derivation_tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv.json b/tvix/derivation/src/tests/derivation_tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv.json
index e159a5d12eed..e297d271592f 100644
--- a/tvix/derivation/src/tests/derivation_tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv.json
+++ b/tvix/derivation/src/tests/derivation_tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv.json
@@ -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": ":"
 }
diff --git a/tvix/derivation/src/write.rs b/tvix/derivation/src/write.rs
index 0cbde3c0fb51..842b2c4ab6ad 100644
--- a/tvix/derivation/src/write.rs
+++ b/tvix/derivation/src/write.rs
@@ -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(())