uds subscription wip

This commit is contained in:
Cole Mickens 2024-08-07 17:44:18 -07:00
parent 2506ee0164
commit e5d5118022

View file

@ -31,11 +31,16 @@ use std::sync::Arc;
use ::attic::nix_store::NixStore;
use anyhow::{anyhow, Context, Result};
use axum::body::Body;
use axum::{extract::Extension, routing::get, Router};
use clap::Parser;
use http_body_util::BodyExt;
use hyper_util::rt::{TokioExecutor, TokioIo};
use futures::StreamExt;
use tempfile::NamedTempFile;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use tokio::net::UnixStream;
use tokio::process::Command;
use tokio::sync::{oneshot, Mutex, RwLock};
use tracing_subscriber::filter::EnvFilter;
@ -44,6 +49,9 @@ use tracing_subscriber::util::SubscriberInitExt;
use gha_cache::Credentials;
const DETERMINATE_STATE_DIR: &str = "/nix/var/determinate";
const DETERMINATE_NIXD_SOCKET_NAME: &str = "determinate-nixd.socket";
type State = Arc<StateInner>;
/// GitHub Actions-powered Nix binary cache
@ -292,6 +300,56 @@ async fn main_cli() -> Result<()> {
None
};
let dnixd_uds_socket_dir: &Path = Path::new(&DETERMINATE_STATE_DIR);
let dnixd_uds_socket_path = dnixd_uds_socket_dir.join(DETERMINATE_NIXD_SOCKET_NAME);
if dnixd_uds_socket_path.exists() {
let stream = TokioIo::new(UnixStream::connect(dnixd_uds_socket_path).await?);
// let (mut sender, conn): (SendRequest<Body>, _) =
// hyper::client::conn::http1::handshake(stream).await?;
let executor = TokioExecutor::new();
let (mut sender, conn): (hyper::client::conn::http2::SendRequest<Body>, _) =
hyper::client::conn::http2::handshake(executor, stream)
.await
.unwrap();
// NOTE(colemickens): for now we just drop the joinhandle and let it keep running
let _join_handle = tokio::task::spawn(async move {
if let Err(err) = conn.await {
tracing::error!("Connection failed: {:?}", err);
}
});
let request = http::Request::builder()
.method(http::Method::GET)
.uri("http://localhost/built-paths")
.body(axum::body::Body::empty())?;
let response = sender.send_request(request).await?;
// NOTE(to self): there was a note somewhere to use this _IF_ you wanted all data, including trialers etc
// so ... we'll see..
let mut data = response.into_data_stream();
while let Some(foo) = data.next().await {
tracing::info!("got {:?}", foo);
}
// while let Some(frame_result) = response.frame().await {
// let frame = frame_result?;
// if let Some(segment) = frame.data_ref() {
// tokio::io::stdout()
// .write_all(segment.iter().as_slice())
// .await?;
// }
// }
// TODO: do something with these paths
} else {
// TODO: split into own function(s)
/* Write the post-build hook script. Note that the shell script
* ignores errors, to avoid the Nix build from failing. */
let post_build_hook_script = {
@ -351,6 +409,7 @@ async fn main_cli() -> Result<()> {
.with_context(|| "Writing to nix.conf")?;
drop(nix_conf);
}
let diagnostic_endpoint = match args.diagnostic_endpoint.as_str() {
"" => {