Compare commits

...

2 commits

Author SHA1 Message Date
Cole Mickens 4631601e5d send and wait for dnixd flush signal 2025-04-01 13:01:57 -07:00
Cole Mickens cf00f851e1 improve unauthenticated error message 2025-03-26 11:03:21 -07:00
6 changed files with 158 additions and 14 deletions

87
Cargo.lock generated
View file

@ -4,13 +4,19 @@ version = 4
[[package]] [[package]]
name = "addr2line" name = "addr2line"
version = "0.24.2" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [ dependencies = [
"gimli", "gimli",
] ]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "adler2" name = "adler2"
version = "2.0.0" version = "2.0.0"
@ -863,17 +869,17 @@ dependencies = [
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.74" version = "0.3.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
dependencies = [ dependencies = [
"addr2line", "addr2line",
"cc",
"cfg-if", "cfg-if",
"libc", "libc",
"miniz_oxide", "miniz_oxide 0.7.4",
"object", "object",
"rustc-demangle", "rustc-demangle",
"windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -1182,6 +1188,33 @@ dependencies = [
"unicode-width 0.1.14", "unicode-width 0.1.14",
] ]
[[package]]
name = "color-eyre"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
version = "1.0.3" version = "1.0.3"
@ -1760,6 +1793,16 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]] [[package]]
name = "fastcdc" name = "fastcdc"
version = "3.1.0" version = "3.1.0"
@ -1811,7 +1854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide 0.8.4",
] ]
[[package]] [[package]]
@ -2011,9 +2054,9 @@ dependencies = [
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.31.1" version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]] [[package]]
name = "glob" name = "glob"
@ -2568,6 +2611,12 @@ dependencies = [
"icu_properties", "icu_properties",
] ]
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "1.9.3"
@ -2857,6 +2906,7 @@ dependencies = [
"attic-server", "attic-server",
"axum 0.7.9", "axum 0.7.9",
"clap", "clap",
"color-eyre",
"daemonize", "daemonize",
"futures", "futures",
"gha-cache", "gha-cache",
@ -2933,6 +2983,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.4" version = "0.8.4"
@ -3084,9 +3143,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.7" version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -3148,6 +3207,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]] [[package]]
name = "p256" name = "p256"
version = "0.11.1" version = "0.11.1"

View file

@ -58,6 +58,7 @@ http-body-util = "0.1"
hyper = { version = "1.0.0", features = ["full"] } hyper = { version = "1.0.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
xdg = { version = "2.5.2" } xdg = { version = "2.5.2" }
color-eyre = { version = "0.6.3" }
[dependencies.tokio] [dependencies.tokio]
version = "1.28.0" version = "1.28.0"

View file

@ -94,6 +94,10 @@ async fn workflow_finish(
} }
}; };
// maybe here send the request to Dnixd to Flush
// save uuid from response
// then wait on receiver until we get that same uuid back
if let Some(gha_cache) = &state.gha_cache { if let Some(gha_cache) = &state.gha_cache {
tracing::info!("Waiting for GitHub action cache uploads to finish"); tracing::info!("Waiting for GitHub action cache uploads to finish");
gha_cache.shutdown().await?; gha_cache.shutdown().await?;

View file

@ -0,0 +1,52 @@
use serde::{Deserialize, Serialize};
const GITHUB_ACTOR_TYPE_USER: &str = "User";
const GITHUB_ACTOR_TYPE_ORGANIZATION: &str = "Organization";
#[derive(Serialize, Deserialize)]
pub struct WorkflowData {
event: WorkflowDataEvent,
}
#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEvent {
repository: WorkflowDataEventRepo,
}
#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEventRepo {
owner: WorkflowDataEventRepoOwner,
}
#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEventRepoOwner {
login: String,
#[serde(rename = "type")]
kind: String,
}
pub(crate) fn get_actions_event_data() -> color_eyre::Result<WorkflowData> {
let github_context = std::env::var("GITHUB_CONTEXT")?;
let workflow_data: WorkflowData = serde_json::from_str::<WorkflowData>(&github_context)?;
Ok(workflow_data)
}
pub(crate) fn print_unauthenticated_error() {
let mut msg = "::error title=FlakeHub registration required.::Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.".to_string();
if let Ok(workflow_data) = get_actions_event_data() {
let owner = workflow_data.event.repository.owner;
if owner.kind == GITHUB_ACTOR_TYPE_USER {
msg = format!(
"::error title=FlakeHub registration required.::Please create an account for {} on FlakeHub.com to publish flakes.",
&owner.login
);
} else if owner.kind == GITHUB_ACTOR_TYPE_ORGANIZATION {
msg = format!(
"::error title=FlakeHub registration required.::Please create an organization for {} on FlakeHub.com to publish flakes.",
&owner.login
);
}
};
println!("{}", msg);
}

View file

@ -18,6 +18,7 @@ mod env;
mod error; mod error;
mod flakehub; mod flakehub;
mod gha; mod gha;
mod github;
mod pbh; mod pbh;
mod telemetry; mod telemetry;
mod util; mod util;
@ -36,6 +37,7 @@ use clap::Parser;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::fs::File; use tokio::fs::File;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::sync::{oneshot, Mutex, RwLock}; use tokio::sync::{oneshot, Mutex, RwLock};
use tracing_subscriber::filter::EnvFilter; use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
@ -226,6 +228,9 @@ struct StateInner {
/// The paths in the Nix store when Magic Nix Cache started, if store diffing is enabled. /// The paths in the Nix store when Magic Nix Cache started, if store diffing is enabled.
original_paths: Option<Mutex<HashSet<PathBuf>>>, original_paths: Option<Mutex<HashSet<PathBuf>>>,
/// The receiver side of the channel we use to get flush events from dnixd back to the workflow_shutdown handler
dnixd_flush_receiver: Option<UnboundedReceiver<uuid::Uuid>>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -366,8 +371,11 @@ async fn main_cli() -> Result<()> {
Some(state) Some(state)
} }
Err(err) => { Err(err) => {
tracing::error!("FlakeHub cache initialization failed: {}. Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.", err); tracing::error!(
println!("::error title={{FlakeHub: Unauthenticated}}::{{Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.}}"); "FlakeHub: cache initialized failed: Unauthenticated: {}",
err
);
github::print_unauthenticated_error();
None None
} }
} }
@ -418,6 +426,15 @@ async fn main_cli() -> Result<()> {
let (shutdown_sender, shutdown_receiver) = oneshot::channel(); let (shutdown_sender, shutdown_receiver) = oneshot::channel();
let dnixd_flush_channel = if dnixd_available == Dnixd::Available {
Some(tokio::sync::mpsc::unbounded_channel())
} else {
None
};
// ????
let dnixd_flush_sender = dnixd_flush_channel.as_ref().map(|c| c.0.clone());
let dnixd_flush_receiver = dnixd_flush_channel.map(|c| c.1);
let original_paths = args.diff_store.then_some(Mutex::new(HashSet::new())); let original_paths = args.diff_store.then_some(Mutex::new(HashSet::new()));
let state = Arc::new(StateInner { let state = Arc::new(StateInner {
gha_cache, gha_cache,
@ -429,11 +446,12 @@ async fn main_cli() -> Result<()> {
flakehub_state: RwLock::new(flakehub_state), flakehub_state: RwLock::new(flakehub_state),
logfile: guard.logfile, logfile: guard.logfile,
original_paths, original_paths,
dnixd_flush_receiver,
}); });
if dnixd_available == Dnixd::Available { if dnixd_available == Dnixd::Available {
tracing::info!("Subscribing to Determinate Nixd build events."); tracing::info!("Subscribing to Determinate Nixd build events.");
crate::pbh::subscribe_uds_post_build_hook(dnixd_uds_socket_path, state.clone()).await?; crate::pbh::subscribe_uds_post_build_hook(dnixd_uds_socket_path, state.clone(), dnixd_flush_sender).await?;
} else { } else {
tracing::info!("Patching nix.conf to use a post-build-hook."); tracing::info!("Patching nix.conf to use a post-build-hook.");
crate::pbh::setup_legacy_post_build_hook(&args.listen, &mut nix_conf).await?; crate::pbh::setup_legacy_post_build_hook(&args.listen, &mut nix_conf).await?;

View file

@ -21,6 +21,7 @@ use crate::State;
pub async fn subscribe_uds_post_build_hook( pub async fn subscribe_uds_post_build_hook(
dnixd_uds_socket_path: PathBuf, dnixd_uds_socket_path: PathBuf,
state: State, state: State,
dnixd_flush_sender: Option<tokio::sync::mpsc::UnboundedSender<uuid::Uuid>>,
) -> Result<()> { ) -> Result<()> {
tokio::spawn(async move { tokio::spawn(async move {
let dnixd_uds_socket_path = &dnixd_uds_socket_path; let dnixd_uds_socket_path = &dnixd_uds_socket_path;
@ -79,6 +80,9 @@ pub async fn subscribe_uds_post_build_hook(
tracing::debug!("built-paths subscription: ignoring non-data frame"); tracing::debug!("built-paths subscription: ignoring non-data frame");
continue; continue;
}; };
// TODO: check for flush event of flush type - send it to the sender
let Ok(event): core::result::Result<BuiltPathResponseEventV1, _> = let Ok(event): core::result::Result<BuiltPathResponseEventV1, _> =
serde_json::from_slice(event_str) serde_json::from_slice(event_str)
else { else {