about summary refs log tree commit diff
path: root/tvix/cli
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-29T12·52+0300
committertazjin <tazjin@tvl.su>2023-01-31T08·51+0000
commite4bb750b3bcdac4c9c138af2828e32587ec2a5ca (patch)
tree9ed20ae4a6c00cc6060b363b1fbc3f1ad785eeb1 /tvix/cli
parent8ec8d03175e5e658600543dd0ba895f3f40e51e6 (diff)
refactor(tvix/cli): force outside of output configuration helper r/5782
Change-Id: I28357fe131cefedcef9761b08a72f675f4a10789
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7939
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/cli')
-rw-r--r--tvix/cli/src/derivation.rs90
1 files changed, 36 insertions, 54 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs
index 012294375e11..17211baa1c3e 100644
--- a/tvix/cli/src/derivation.rs
+++ b/tvix/cli/src/derivation.rs
@@ -164,39 +164,15 @@ fn construct_output_hash(digest: &str, algo: &str, hash_mode: Option<&str>) -> R
 /// parameters, including invalid ones.
 fn populate_output_configuration(
     drv: &mut Derivation,
-    vm: &mut VM,
-    hash: Option<&Value>,      // in nix: outputHash
-    hash_algo: Option<&Value>, // in nix: outputHashAlgo
-    hash_mode: Option<&Value>, // in nix: outputHashmode
+    hash: Option<String>,      // in nix: outputHash
+    hash_algo: Option<String>, // in nix: outputHashAlgo
+    hash_mode: Option<String>, // in nix: outputHashmode
 ) -> Result<(), ErrorKind> {
     match (hash, hash_algo, hash_mode) {
-        (Some(hash), Some(algo), hash_mode) => match drv.outputs.get_mut("out") {
+        (Some(digest), Some(algo), hash_mode) => match drv.outputs.get_mut("out") {
             None => return Err(Error::ConflictingOutputTypes.into()),
             Some(out) => {
-                let algo = strong_coerce_to_string(
-                    vm,
-                    &algo,
-                    "evaluating outputHashAlgo of a derivation",
-                )?;
-
-                let digest_str =
-                    strong_coerce_to_string(vm, &hash, "evaluating outputHash of a derivation")?;
-
-                let hash_mode = match hash_mode {
-                    None => None,
-                    Some(mode) => Some(strong_coerce_to_string(
-                        vm,
-                        &mode,
-                        "evaluating outputHashMode of a derivation",
-                    )?),
-                };
-
-                // construct out.hash
-                out.hash = Some(construct_output_hash(
-                    &digest_str,
-                    &algo,
-                    hash_mode.as_deref(),
-                )?);
+                out.hash = Some(construct_output_hash(&digest, &algo, hash_mode.as_deref())?);
             }
         },
 
@@ -309,10 +285,22 @@ mod derivation_builtins {
         // Configure fixed-output derivations if required.
         populate_output_configuration(
             &mut drv,
-            vm,
-            input.select("outputHash"),
-            input.select("outputHashAlgo"),
-            input.select("outputHashMode"),
+            input
+                .select("outputHash")
+                .map(|v| strong_coerce_to_string(vm, v, "evaluating the `outputHash` parameter"))
+                .transpose()?,
+            input
+                .select("outputHashAlgo")
+                .map(|v| {
+                    strong_coerce_to_string(vm, v, "evaluating the `outputHashAlgo` parameter")
+                })
+                .transpose()?,
+            input
+                .select("outputHashMode")
+                .map(|v| {
+                    strong_coerce_to_string(vm, v, "evaluating the `outputHashMode` parameter")
+                })
+                .transpose()?,
         )?;
 
         for (name, value) in input.into_iter_sorted() {
@@ -545,10 +533,9 @@ mod tests {
 
     #[test]
     fn populate_output_config_std() {
-        let mut vm = fake_vm();
         let mut drv = Derivation::default();
 
-        populate_output_configuration(&mut drv, &mut vm, None, None, None)
+        populate_output_configuration(&mut drv, None, None, None)
             .expect("populate_output_configuration() should succeed");
 
         assert_eq!(drv, Derivation::default(), "derivation should be unchanged");
@@ -556,18 +543,16 @@ mod tests {
 
     #[test]
     fn populate_output_config_fod() {
-        let mut vm = fake_vm();
         let mut drv = Derivation::default();
         drv.outputs.insert("out".to_string(), Default::default());
 
-        let hash = Value::String(
-            "0000000000000000000000000000000000000000000000000000000000000000".into(),
-        );
-
-        let algo = Value::String("sha256".into());
-
-        populate_output_configuration(&mut drv, &mut vm, Some(&hash), Some(&algo), None)
-            .expect("populate_output_configuration() should succeed");
+        populate_output_configuration(
+            &mut drv,
+            Some("0000000000000000000000000000000000000000000000000000000000000000".into()),
+            Some("sha256".into()),
+            None,
+        )
+        .expect("populate_output_configuration() should succeed");
 
         let expected = Hash {
             algo: "sha256".into(),
@@ -579,19 +564,16 @@ mod tests {
 
     #[test]
     fn populate_output_config_fod_recursive() {
-        let mut vm = fake_vm();
         let mut drv = Derivation::default();
         drv.outputs.insert("out".to_string(), Default::default());
 
-        let hash = Value::String(
-            "0000000000000000000000000000000000000000000000000000000000000000".into(),
-        );
-
-        let algo = Value::String("sha256".into());
-        let mode = Value::String("recursive".into());
-
-        populate_output_configuration(&mut drv, &mut vm, Some(&hash), Some(&algo), Some(&mode))
-            .expect("populate_output_configuration() should succeed");
+        populate_output_configuration(
+            &mut drv,
+            Some("0000000000000000000000000000000000000000000000000000000000000000".into()),
+            Some("sha256".into()),
+            Some("recursive".into()),
+        )
+        .expect("populate_output_configuration() should succeed");
 
         let expected = Hash {
             algo: "r:sha256".into(),