about summary refs log tree commit diff
path: root/tvix/nix-daemon/src/lib.rs
diff options
context:
space:
mode:
authorVova Kryachko <v.kryachko@gmail.com>2024-11-08T19·22-0500
committerVladimir Kryachko <v.kryachko@gmail.com>2024-11-12T03·06+0000
commit9d114bf040b92b87196d0621aef00188f801265f (patch)
tree3a1fac60448befec525e0341311e86cbe95e5586 /tvix/nix-daemon/src/lib.rs
parentb564ed9d43f17c620439815b86d2940be197bd47 (diff)
feat(nix-daemon): Implement QueryPathInfo and IsValidPath. r/8908
Change-Id: Ia601e2eae24a2bc13d8851b2e8ed9d6c1808bb35
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12745
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: Vladimir Kryachko <v.kryachko@gmail.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-daemon/src/lib.rs')
-rw-r--r--tvix/nix-daemon/src/lib.rs38
1 files changed, 34 insertions, 4 deletions
diff --git a/tvix/nix-daemon/src/lib.rs b/tvix/nix-daemon/src/lib.rs
index f10d6c7ad669..89bfbf9b3dc0 100644
--- a/tvix/nix-daemon/src/lib.rs
+++ b/tvix/nix-daemon/src/lib.rs
@@ -1,7 +1,11 @@
-use std::sync::Arc;
+use std::{io::Result, sync::Arc};
 
-use nix_compat::nix_daemon::NixDaemonIO;
-use tvix_store::pathinfoservice::PathInfoService;
+use nix_compat::{
+    nix_daemon::{types::UnkeyedValidPathInfo, NixDaemonIO},
+    nixbase32,
+    store_path::StorePath,
+};
+use tvix_store::{path_info::PathInfo, pathinfoservice::PathInfoService};
 
 #[allow(dead_code)]
 pub struct TvixDaemon {
@@ -15,4 +19,30 @@ impl TvixDaemon {
 }
 
 /// Implements [NixDaemonIO] backed by tvix services.
-impl NixDaemonIO for TvixDaemon {}
+impl NixDaemonIO for TvixDaemon {
+    async fn query_path_info(
+        &self,
+        path: &StorePath<String>,
+    ) -> Result<Option<UnkeyedValidPathInfo>> {
+        match self.path_info_service.get(*path.digest()).await? {
+            Some(path_info) => Ok(Some(into_unkeyed_path_info(path_info))),
+            None => Ok(None),
+        }
+    }
+}
+
+// PathInfo lives in the tvix-store crate, but does not depend on nix-compat's wire feature,
+// while UnkeyedValidPathInfo is only available if that feature is enabled. To avoid complexity
+// we manually convert as opposed to creating a From<PathInfo>.
+fn into_unkeyed_path_info(info: PathInfo) -> UnkeyedValidPathInfo {
+    UnkeyedValidPathInfo {
+        deriver: info.deriver,
+        nar_hash: nixbase32::encode(&info.nar_sha256),
+        references: info.references,
+        registration_time: 0,
+        nar_size: info.nar_size,
+        ultimate: false,
+        signatures: info.signatures,
+        ca: info.ca,
+    }
+}