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-31T13·46+0200
committerclbot <clbot@tvl.fyi>2023-10-16T12·23+0000
commit2410f2292f53a17242ed54b0af2d7b04ec3173f6 (patch)
tree476d93504a2c21d48011fce4f4afe79bfb0b0cca /tvix/nix-compat/src/derivation/mod.rs
parent8b09ae54b1d635e77c394dd965915479283489a2 (diff)
feat(nix-compat/{aterm,derivation}): init parser r/6831
This provides a nom-based parser for Nix derivations in ATerm format,
which can be reached via `Derivation::from_aterm_bytes`.

Some of the lower-level ATerm primitives are moved into a (new) aterm
module, and some more higher-level ones that construct derivation-
specific types.

Also, move the escape_bytes function into there, this is a generic ATerm
thing.

Change-Id: I2b03b8a1461c7ea2fcb8640c2fc3d1fa3ea719fb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9730
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation/mod.rs')
-rw-r--r--tvix/nix-compat/src/derivation/mod.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs
index a06f8eb160ae..d7f894c89a8f 100644
--- a/tvix/nix-compat/src/derivation/mod.rs
+++ b/tvix/nix-compat/src/derivation/mod.rs
@@ -8,8 +8,9 @@ use std::collections::{BTreeMap, BTreeSet};
 use std::io;
 
 mod errors;
-mod escape;
 mod output;
+mod parse_error;
+mod parser;
 mod validate;
 mod write;
 
@@ -89,6 +90,12 @@ impl Derivation {
         buffer
     }
 
+    /// Parse an Derivation in ATerm serialization, and validate it passes our
+    /// set of validations.
+    pub fn from_aterm_bytes(b: &[u8]) -> Result<Derivation, parser::Error<&[u8]>> {
+        parser::parse(b)
+    }
+
     /// Returns the drv path of a [Derivation] struct.
     ///
     /// The drv path is calculated by invoking [build_text_path], using