about summary refs log tree commit diff
path: root/tvix/nix-compat
diff options
context:
space:
mode:
authorBrian Olsen <brian@maven-group.org>2024-07-22T14·51+0200
committerclbot <clbot@tvl.fyi>2024-08-25T15·05+0000
commitced05a2bb6b66d30208520d0791f4fa298c429e2 (patch)
treed295eb9766db79df8f3053bc5022e24059012f16 /tvix/nix-compat
parent9af69204787d47cfe551f524d01b1a726971f06e (diff)
feat(tvix/nix-compat-derive): Add deriver for NixDeserialize r/8586
This adds a nix-compat-derive derive crate that implements a deriver
for NixDeserialize implementations. This is to reduce the amount of
code needed to implement deserialization for all the types used by
the Nix daemon protocol.

Change-Id: I484724b550e8a1d5e9adad9555d9dc1374ae95c2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12022
Autosubmit: Brian Olsen <me@griff.name>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/nix-compat')
-rw-r--r--tvix/nix-compat/Cargo.toml8
-rw-r--r--tvix/nix-compat/src/nix_daemon/protocol_version.rs7
2 files changed, 14 insertions, 1 deletions
diff --git a/tvix/nix-compat/Cargo.toml b/tvix/nix-compat/Cargo.toml
index 9f43bb24efcc..87e9b1e6760c 100644
--- a/tvix/nix-compat/Cargo.toml
+++ b/tvix/nix-compat/Cargo.toml
@@ -8,9 +8,10 @@ edition = "2021"
 async = ["tokio"]
 # code emitting low-level packets used in the daemon protocol.
 wire = ["tokio", "pin-project-lite", "bytes"]
+test = []
 
 # Enable all features by default.
-default = ["async", "wire"]
+default = ["async", "wire", "nix-compat-derive"]
 
 [dependencies]
 bitflags = "2.4.1"
@@ -33,6 +34,11 @@ tracing = "0.1.37"
 optional = true
 version = "1.6.1"
 
+[dependencies.nix-compat-derive]
+path = "../nix-compat-derive"
+optional = true
+default-features = false
+
 [dependencies.tokio]
 optional = true
 version = "1.32.0"
diff --git a/tvix/nix-compat/src/nix_daemon/protocol_version.rs b/tvix/nix-compat/src/nix_daemon/protocol_version.rs
index 3c8fe663e867..19da28d484dd 100644
--- a/tvix/nix-compat/src/nix_daemon/protocol_version.rs
+++ b/tvix/nix-compat/src/nix_daemon/protocol_version.rs
@@ -54,6 +54,13 @@ impl From<u16> for ProtocolVersion {
     }
 }
 
+#[cfg(any(test, feature = "test"))]
+impl From<(u8, u8)> for ProtocolVersion {
+    fn from((major, minor): (u8, u8)) -> Self {
+        Self::from_parts(major, minor)
+    }
+}
+
 impl TryFrom<u64> for ProtocolVersion {
     type Error = &'static str;