chore(snix/nix-daemon): Fix queryValidPaths operation.

Query valid paths is supposed to return List<StorePath> while our
nix-daemon is returning List<UnkeyedValidPathInfo> which crashes nix.

Change-Id: Ibd2d984b6d0d37fd77ecd612bd7acfb4ca69c048
Reviewed-on: https://cl.snix.dev/c/snix/+/30072
Autosubmit: Vova Kryachko <v.kryachko@gmail.com>
Tested-by: besadii
Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
Vova Kryachko 2025-03-17 17:59:57 +00:00 committed by clbot
parent bc62fc0354
commit bca46bf1cf
2 changed files with 15 additions and 16 deletions

View file

@ -117,7 +117,9 @@ where
let io = self.io.clone(); let io = self.io.clone();
loop { loop {
let op_code = self.reader.read_number().await?; let op_code = self.reader.read_number().await?;
match TryInto::<Operation>::try_into(op_code) { let op = TryInto::<Operation>::try_into(op_code);
debug!(?op, "Received operation");
match op {
// Note: please keep operations sorted in ascending order of their numerical op number. // Note: please keep operations sorted in ascending order of their numerical op number.
Ok(operation) => match operation { Ok(operation) => match operation {
Operation::IsValidPath => { Operation::IsValidPath => {

View file

@ -2,7 +2,6 @@ pub mod worker_protocol;
use std::io::Result; use std::io::Result;
use futures::future::try_join_all;
use tokio::io::AsyncRead; use tokio::io::AsyncRead;
use tracing::warn; use tracing::warn;
use types::{AddToStoreNarRequest, QueryValidPaths, UnkeyedValidPathInfo}; use types::{AddToStoreNarRequest, QueryValidPaths, UnkeyedValidPathInfo};
@ -39,19 +38,21 @@ pub trait NixDaemonIO: Sync {
fn query_valid_paths( fn query_valid_paths(
&self, &self,
request: &QueryValidPaths, request: &QueryValidPaths,
) -> impl std::future::Future<Output = Result<Vec<UnkeyedValidPathInfo>>> + Send { ) -> impl std::future::Future<Output = Result<Vec<StorePath<String>>>> + Send {
async move { async move {
if request.substitute { if request.substitute {
warn!("snix does not yet support substitution, ignoring the 'substitute' flag..."); warn!("snix does not yet support substitution, ignoring the 'substitute' flag...");
} }
// Using try_join_all here to avoid returning partial results to the client.
// The only reason query_path_info can fail is due to transient IO errors,
// so we return such errors to the client as opposed to only returning paths
// that succeeded.
let results =
try_join_all(request.paths.iter().map(|path| self.query_path_info(path))).await?;
Ok(results.into_iter().flatten().collect()) let mut results: Vec<StorePath<String>> = Vec::with_capacity(request.paths.len());
for path in request.paths.iter() {
if self.is_valid_path(path).await? {
results.push(path.clone());
}
}
Ok(results)
} }
} }
@ -178,16 +179,12 @@ mod tests {
let result = io let result = io
.query_valid_paths(&QueryValidPaths { .query_valid_paths(&QueryValidPaths {
paths: vec![path], paths: vec![path.clone()],
substitute: false, substitute: false,
}) })
.await .await
.expect("expected to get a non-empty response"); .expect("expected to get a non-empty response");
assert_eq!( assert_eq!(result, vec![path], "expected to get non empty response");
result,
vec![UnkeyedValidPathInfo::default()],
"expected to get non empty response"
);
} }
#[tokio::test] #[tokio::test]