about summary refs log tree commit diff
path: root/tvix/nix-compat/src/derivation/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-07-30T07·05+0200
committerclbot <clbot@tvl.fyi>2023-07-31T21·41+0000
commit34b7620764247bb967062a94c06a1750f8069701 (patch)
tree9aee989bed6e2a4086ba274cbe1d343e7f7903d1 /tvix/nix-compat/src/derivation/mod.rs
parent79531c3dab1c24ff3171c0aa067004c8e6c92e3f (diff)
refactor(tvix/nix-compat/derivation): simplify r/6450
Let the escape function only take care of string escaping, not quoting.

Let write_array_elements always quote and escape strings it consumes.
Move the business of writing additional wrapping characters around it to
the caller.

Change-Id: Ib8dea69c409561b49862c531ba5a3fe6c2f061f8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8993
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation/mod.rs')
-rw-r--r--tvix/nix-compat/src/derivation/mod.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs
index 498aa1b59d4c..b416e745a565 100644
--- a/tvix/nix-compat/src/derivation/mod.rs
+++ b/tvix/nix-compat/src/derivation/mod.rs
@@ -5,6 +5,7 @@ use bstr::BString;
 use serde::{Deserialize, Serialize};
 use sha2::{Digest, Sha256};
 use std::collections::{BTreeMap, BTreeSet};
+use std::io;
 
 mod errors;
 mod escape;
@@ -45,8 +46,8 @@ impl Derivation {
     /// write the Derivation to the given [std::io::Write], in ATerm format.
     ///
     /// The only errors returns are these when writing to the passed writer.
-    pub fn serialize(&self, writer: &mut impl std::io::Write) -> Result<(), std::io::Error> {
-        write::write_str(writer, write::DERIVATION_PREFIX)?;
+    pub fn serialize(&self, writer: &mut impl std::io::Write) -> Result<(), io::Error> {
+        io::copy(&mut io::Cursor::new(write::DERIVATION_PREFIX), writer)?;
         write::write_char(writer, write::PAREN_OPEN)?;
 
         write::write_outputs(writer, &self.outputs)?;