some progress at an attempt

This commit is contained in:
cy 2025-04-17 22:25:36 -04:00
parent b1e59d0a6c
commit a17fa92c78
Signed by: cy
SSH key fingerprint: SHA256:o/geVWV4om1QhUSkKvDQeW/eAihwnjyXkqMwrVdbuts
5 changed files with 38 additions and 11 deletions

View file

@ -211,6 +211,13 @@ mod ffi {
/// Obtains a handle to the Nix store. /// Obtains a handle to the Nix store.
fn open_nix_store() -> Result<UniquePtr<CNixStore>>; fn open_nix_store() -> Result<UniquePtr<CNixStore>>;
/// Creates a NAR dump from a path.
fn nar_from_path(
self: Pin<&mut CNixStore>,
base_name: Vec<u8>,
sender: Box<AsyncWriteSender>,
) -> Result<()>;
// ========= // =========
// CPathInfo // CPathInfo
// ========= // =========

View file

@ -108,6 +108,17 @@ std::unique_ptr<std::vector<std::string>> CNixStore::compute_fs_closure(RBasePat
return std::make_unique<std::vector<std::string>>(result); return std::make_unique<std::vector<std::string>>(result);
} }
void CNixStore::nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender) {
RustSink sink(std::move(sender));
std::string_view sv((const char *)base_name.data(), base_name.size());
nix::StorePath store_path(sv);
// exceptions will be thrown into Rust
this->store->narFromPath(store_path, sink);
sink.eof();
}
std::unique_ptr<CNixStore> open_nix_store() { std::unique_ptr<CNixStore> open_nix_store() {
return std::make_unique<CNixStore>(); return std::make_unique<CNixStore>();
} }

View file

@ -79,6 +79,7 @@ public:
bool flip_direction, bool flip_direction,
bool include_outputs, bool include_outputs,
bool include_derivers); bool include_derivers);
void nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender);
}; };
std::unique_ptr<CNixStore> open_nix_store(); std::unique_ptr<CNixStore> open_nix_store();

View file

@ -4,7 +4,10 @@ use anyhow::{Context, Result};
use nix_compat::store_path::StorePath; use nix_compat::store_path::StorePath;
use tokio::task; use tokio::task;
use crate::{bindings, path_info::PathInfo}; use crate::{
bindings::{self, AsyncWriteAdapter},
path_info::PathInfo,
};
pub struct Store { pub struct Store {
inner: Arc<bindings::FfiNixStore>, inner: Arc<bindings::FfiNixStore>,
@ -75,4 +78,19 @@ impl Store {
.await .await
.unwrap() .unwrap()
} }
pub fn make_nar(&self, path: StorePath<String>) -> AsyncWriteAdapter {
let inner = self.inner.clone();
let (adapter, mut sender) = AsyncWriteAdapter::new();
task::spawn_blocking(move || {
if let Err(e) = inner
.store()
.nar_from_path(path.to_string().as_bytes().to_vec(), sender.clone())
{
let _ = sender.rust_error(e);
}
});
adapter
}
} }

View file

@ -139,16 +139,6 @@ impl<'a> Uploader<'a> {
Ok(()) Ok(())
} }
async fn make_nar(&self) -> Result<Vec<u8>> {
Ok(Command::new("nix")
.arg("nar")
.arg("dump-path")
.arg(self.path.absolute_path())
.output()
.await?
.stdout)
}
fn narinfo_from_nar(&self, nar: &[u8]) -> Result<NarInfo> { fn narinfo_from_nar(&self, nar: &[u8]) -> Result<NarInfo> {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(nar); hasher.update(nar);