git.delta.rocks / fleet / refs/commits / 48d120aa4aef

difftreelog

ci use in-tree remowt-agent

qztpqskoYaroslav Bolyukin2026-06-18parent: #0ea4b47.patch.diff

42 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -722,9 +722,9 @@
 
 [[package]]
 name = "camino"
-version = "1.2.2"
+version = "1.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"
+checksum = "b4ce8d3bd5823c7504d3f579f13e7b2f3da252fcb938c594d5680ee508bf846f"
 dependencies = [
  "serde_core",
 ]
@@ -1899,9 +1899,9 @@
  "fleet-shared",
  "hex",
  "hmac 0.13.0",
- "pbkdf2 0.12.2",
+ "pbkdf2 0.13.0",
  "rand 0.10.1",
- "sha2 0.10.9",
+ "sha2 0.11.0",
  "x25519-dalek",
 ]
 
@@ -5011,6 +5011,7 @@
  "nix-eval",
  "remowt-client",
  "remowt-endpoints",
+ "remowt-link-shared",
  "serde",
  "thiserror 2.0.18",
  "tokio",
@@ -5031,13 +5032,13 @@
  "iroh-base",
  "n0-watcher",
  "noq-udp",
- "remowt-ui-prompt",
  "serde",
  "serde_json",
  "thiserror 2.0.18",
  "tokio",
  "tokio-util",
  "tracing",
+ "uuid",
 ]
 
 [[package]]
@@ -5093,11 +5094,11 @@
  "anyhow",
  "bifrostlink",
  "bifrostlink-macros",
+ "remowt-link-shared",
  "serde",
  "thiserror 2.0.18",
  "tokio",
  "tracing",
- "zbus",
 ]
 
 [[package]]
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,11 +15,11 @@
 remowt-fleet = { path = "./crates/remowt-fleet" }
 
 remowt-client = { version = "0.1.9", path = "remowt/crates/remowt-client" }
-remowt-polkit-shared = { version = "0.1.9", path = "remowt/crates/polkit-shared" }
+remowt-endpoints = { version = "0.1.9", path = "remowt/crates/remowt-endpoints" }
 remowt-link-shared = { version = "0.1.9", path = "remowt/crates/remowt-link-shared" }
 remowt-plugin = { version = "0.1.9", path = "remowt/crates/remowt-plugin" }
+remowt-polkit-shared = { version = "0.1.9", path = "remowt/crates/polkit-shared" }
 remowt-ui-prompt = { version = "0.1.9", path = "remowt/crates/remowt-ui-prompt" }
-remowt-endpoints = { version = "0.1.9", path = "remowt/crates/remowt-endpoints" }
 
 bifrostlink = "0.2.0"
 bifrostlink-macros = "0.2.0"
@@ -27,16 +27,9 @@
 
 iroh = { version = "1.0.0", features = ["unstable-custom-transports"] }
 iroh-base = "1.0.0"
-noq-udp = { version = "1.0.0", default-features = false }
 n0-watcher = "1.0.0"
+noq-udp = { version = "1.0.0", default-features = false }
 
-uuid = { version = "1", features = ["v4"] }
-russh = { version = "0.61.2", default-features = false, features = [
-        "ring",
-        "flate2",
-        "rsa",
-] }
-russh-config = "0.58.0"
 age = { version = "0.11", features = ["plugin", "ssh"] }
 anyhow = "1.0"
 base64 = "0.22.1"
@@ -64,13 +57,15 @@
 opentelemetry-appender-tracing = "0.32.0"
 opentelemetry-otlp = { version = "0.32.0", features = ["grpc-tonic", "gzip-tonic", "http-json", "reqwest-rustls"] }
 opentelemetry_sdk = "0.32.0"
-pbkdf2 = "0.12"
+pbkdf2 = "0.13"
 peg = "0.8.5"
 pkg-config = "0.3.30"
 rand = "0.10.0"
+russh = { version = "0.61.2", default-features = false, features = ["flate2", "ring", "rsa"] }
+russh-config = "0.58.0"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
-sha2 = "0.10"
+sha2 = "0.11"
 shlex = "2.0.1"
 tabled = "0.21.0"
 tempfile = "3.20"
@@ -81,14 +76,15 @@
 tracing = "0.1"
 tracing-indicatif = "0.3.13"
 tracing-opentelemetry = "0.33.0"
+uuid = { version = "1", features = ["v4"] }
 # For fixed coloring needs to be updated to https://github.com/tokio-rs/tracing/pull/3484
+tokio-util = "0.7.11"
 tracing-subscriber = { version = "0.3.19", features = ["env-filter", "fmt"] }
 unicode_categories = "0.1.1"
 vte = { version = "0.15.0", features = ["ansi"] }
 x25519-dalek = { version = "2.0.1", features = ["getrandom"] }
 zbus = "5.16.0"
 zbus_polkit = "5.0.0"
-tokio-util = "0.7.11"
 
 [profile.dev]
 panic = "abort"
modifiedcmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -5,8 +5,9 @@
 use clap::Parser;
 use fleet_base::{
 	deploy::{DeployAction, deploy_task, upload_task},
-	host::{Config, DeployKind, GenerationStorage},
+	host::{Config, DeployKind},
 	opts::FleetOpts,
+	pins::GenerationStorage,
 };
 use futures::{StreamExt as _, stream::FuturesUnordered};
 use nix_eval::nix_go;
@@ -145,8 +146,7 @@
 					}
 
 					let remote_path =
-						match upload_task(&config, &host, GenerationStorage::Deployer, built).await
-						{
+						match upload_task(&host, GenerationStorage::Deployer, built).await {
 							Ok(v) => v,
 							Err(e) => {
 								error!("upload failed: {e}");
modifiedcmds/fleet/src/cmds/rollback.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/rollback.rs
+++ b/cmds/fleet/src/cmds/rollback.rs
@@ -4,8 +4,9 @@
 use clap::Parser;
 use fleet_base::{
 	deploy::{DeployAction, deploy_task, upload_task},
-	host::{Config, ConfigHost, Generation, GenerationStorage},
+	host::{Config, ConfigHost},
 	opts::FleetOpts,
+	pins::{Generation, GenerationStorage},
 };
 use tabled::Table;
 use tracing::{info, warn};
@@ -103,13 +104,8 @@
 						Table::new(&generations)
 					);
 				};
-				let remote_path = upload_task(
-					config,
-					&host,
-					generation.location,
-					generation.store_path.clone(),
-				)
-				.await?;
+				let remote_path =
+					upload_task(&host, generation.location, generation.store_path.clone()).await?;
 
 				deploy_task(
 					action,
deletedcmds/fleet/src/extra_args.rsdiffbeforeafterboth
--- a/cmds/fleet/src/extra_args.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-use std::ffi::{OsStr, OsString};
-
-use anyhow::{Result, anyhow};
-
-pub fn parse_os(os: &OsStr) -> Result<Vec<OsString>> {
-	Ok(shlex::bytes::split(os.as_encoded_bytes())
-		.ok_or_else(|| anyhow!("invalid arguments"))?
-		.into_iter()
-		.map(|a| {
-			// Unpaired surrogates are not touched
-			unsafe { OsString::from_encoded_bytes_unchecked(a) }
-		})
-		.collect())
-}
-// pub fn parse(s: &str) -> Result<Vec<OsString>> {
-// 	let osstr = OsString::try_from(s)?;
-// 	parse_os(&osstr)
-// }
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
--- a/cmds/fleet/src/main.rs
+++ b/cmds/fleet/src/main.rs
@@ -1,8 +1,6 @@
 #![recursion_limit = "512"]
 
 pub(crate) mod cmds;
-// pub(crate) mod command;
-pub(crate) mod extra_args;
 
 use std::{process::ExitCode, sync::Arc};
 
modifiedcmds/generator-helper/src/main.rsdiffbeforeafterboth
--- a/cmds/generator-helper/src/main.rs
+++ b/cmds/generator-helper/src/main.rs
@@ -14,7 +14,7 @@
 use clap::{Parser, ValueEnum};
 use ed25519_dalek::SecretKey;
 use fleet_shared::SecretData;
-use hmac::Mac as _;
+use hmac::{KeyInit as _, Mac as _};
 use rand::{
 	Rng as _,
 	distr::{Alphanumeric, Distribution, SampleString, Uniform},
@@ -338,8 +338,8 @@
 					);
 
 					type HmacSha256 = hmac::Hmac<sha2::Sha256>;
-					let mut mac = <HmacSha256 as hmac::Mac>::new_from_slice(&salted)
-						.expect("HMAC accepts any key length");
+					let mut mac =
+						HmacSha256::new_from_slice(&salted).expect("HMAC accepts any key length");
 					mac.update(b"Client Key");
 					let client_key = mac.finalize().into_bytes();
 
@@ -347,8 +347,8 @@
 					hasher.update(client_key);
 					let stored_key = hasher.finalize();
 
-					let mut mac = <HmacSha256 as hmac::Mac>::new_from_slice(&salted)
-						.expect("HMAC accepts any key length");
+					let mut mac =
+						HmacSha256::new_from_slice(&salted).expect("HMAC accepts any key length");
 					mac.update(b"Server Key");
 					let server_key = mac.finalize().into_bytes();
 
modifiedcmds/remowt-plugin-fleet/Cargo.tomldiffbeforeafterboth
--- a/cmds/remowt-plugin-fleet/Cargo.toml
+++ b/cmds/remowt-plugin-fleet/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-plugin-fleet"
 description = "Remowt plugin exposing fleet's Nix endpoint to a running agent"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 
 [dependencies]
 remowt-fleet.workspace = true
modifiedcrates/fleet-base/src/deploy.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/deploy.rs
+++ b/crates/fleet-base/src/deploy.rs
@@ -11,7 +11,8 @@
 use tokio::time::sleep;
 use tracing::{Instrument as _, error, info, info_span, warn};
 
-use crate::host::{Config, ConfigHost, DeployKind, Generation, GenerationStorage};
+use crate::host::{ConfigHost, DeployKind};
+use crate::pins::{Generation, GenerationStorage};
 
 #[derive(ValueEnum, Clone, Copy)]
 pub enum DeployAction {
@@ -260,13 +261,12 @@
 			{
 				// It is ok, if there was no reboot - then timer might not be running.
 			}
-			if action.should_schedule_rollback_run() {
-				if let Err(e) = elevated_systemd
+			if action.should_schedule_rollback_run()
+				&& let Err(e) = elevated_systemd
 					.stop("rollback-watchdog-run.timer".to_owned())
 					.await
-				{
-					error!("failed to disarm rollback run: {e}");
-				}
+			{
+				error!("failed to disarm rollback run: {e}");
 			}
 		} else if let Err(_e) = elevated_fs
 			.rm_file(Utf8PathBuf::from("/etc/fleet_rollback_marker"))
@@ -280,7 +280,6 @@
 }
 
 pub async fn upload_task(
-	config: &Config,
 	host: &ConfigHost,
 	location: GenerationStorage,
 	generation: Utf8PathBuf,
modifiedcrates/fleet-base/src/fleetdata.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/fleetdata.rs
+++ b/crates/fleet-base/src/fleetdata.rs
@@ -6,6 +6,7 @@
 	},
 	fmt,
 	io::{self, Cursor},
+	str::FromStr,
 	sync::RwLock,
 };
 
@@ -92,8 +93,9 @@
 	#[serde(skip_serializing)]
 	host_secrets: BTreeMap<SecretOwner, BTreeMap<String, FleetSecretDistribution>>,
 }
-impl FleetData {
-	pub fn from_str(s: &str) -> anyhow::Result<Self> {
+impl FromStr for FleetData {
+	type Err = anyhow::Error;
+	fn from_str(s: &str) -> anyhow::Result<Self> {
 		let mut data: Self = nixlike::parse_str(s)?;
 		if !data.host_secrets.is_empty() {
 			info!("migrating host secrets into shared secrets structure");
@@ -294,15 +296,16 @@
 	/// Drop expired distributions
 	fn prune_expired(&mut self, now: DateTime<Utc>) {
 		for ele in self.distributions_mut() {
-			if let Some(expires_at) = ele.secret.expires_at {
-				if expires_at < now {
-					ele.prune(format!("expired during check at {now}"));
-				}
+			if let Some(expires_at) = ele.secret.expires_at
+				&& expires_at < now
+			{
+				ele.prune(format!("expired during check at {now}"));
 			}
 		}
 	}
 	/// Perform all pruning relevant to shared secrets
 	/// Also see expected_owner_removed
+	#[allow(clippy::too_many_arguments)]
 	pub fn prune_shared(
 		&mut self,
 		expected_owners: &BTreeSet<SecretOwner>,
@@ -323,14 +326,15 @@
 		let mut to_add = expected_owners.difference(&current_owners);
 		if to_add.next().is_some() && unique && regenerate_on_owner_added {
 			for dist in self.distributions_mut() {
-				dist.prune(format!(
+				dist.prune(
 					"owners missing, can't add new distribution, regeneration preferred"
-				));
+						.to_string(),
+				);
 			}
 			return;
 		}
 
-		for to_remove in current_owners.difference(&expected_owners) {
+		for to_remove in current_owners.difference(expected_owners) {
 			self.entry(to_remove.clone()).remove(
 				regenerate_on_owner_removed,
 				"owner was removed from expected owners list, regenerate_on_owner_removed is set"
@@ -362,9 +366,7 @@
 	) -> Option<usize> {
 		self.distributions()
 			.enumerate()
-			.max_by(|(_, a), (_, b)| {
-				compare_dists(&a, &b, prefer_identities, include_pruned_owners)
-			})
+			.max_by(|(_, a), (_, b)| compare_dists(a, b, prefer_identities, include_pruned_owners))
 			.map(|(p, _)| p)
 	}
 	/// Secret wants to be the same on all hosts, leave only one unpruned version of it
@@ -410,10 +412,10 @@
 		filter_owner: Option<&SecretOwner>,
 	) {
 		'dist: for ele in self.distributions_mut() {
-			if let Some(filter_owner) = filter_owner {
-				if !ele.owners.contains(filter_owner) {
-					continue;
-				}
+			if let Some(filter_owner) = filter_owner
+				&& !ele.owners.contains(filter_owner)
+			{
+				continue;
 				// Note: secret still can have multiple owners even if it is host-owned
 				// in this case we expect that all owners using the same generator, so we can prune distribution for all of them
 			}
@@ -442,10 +444,10 @@
 		filter_owner: Option<&SecretOwner>,
 	) {
 		for ele in self.distributions_mut() {
-			if let Some(filter_owner) = filter_owner {
-				if !ele.owners.contains(filter_owner) {
-					continue;
-				}
+			if let Some(filter_owner) = filter_owner
+				&& !ele.owners.contains(filter_owner)
+			{
+				continue;
 				// Note: secret still can have multiple owners even if it is host-owned
 				// in this case we expect that all owners using the same generator, so we can prune distribution for all of them
 			}
@@ -519,7 +521,7 @@
 	}
 }
 
-struct OccupiedDistEntry<'d> {
+pub struct OccupiedDistEntry<'d> {
 	distributions: &'d mut FleetSecretDistributions,
 	idx: usize,
 	owners: BTreeSet<SecretOwner>,
@@ -537,16 +539,16 @@
 			owners: self.owners,
 		}
 	}
-	fn set(self, secret: FleetSecretData, reason: String) -> Self {
+	pub fn set(self, secret: FleetSecretData, reason: String) -> Self {
 		self.remove(false, reason).set(secret)
 	}
 }
-struct VacantDistEntry<'d> {
+pub struct VacantDistEntry<'d> {
 	distributions: &'d mut FleetSecretDistributions,
 	owners: BTreeSet<SecretOwner>,
 }
 impl<'d> VacantDistEntry<'d> {
-	fn set(self, secret: FleetSecretData) -> OccupiedDistEntry<'d> {
+	pub fn set(self, secret: FleetSecretData) -> OccupiedDistEntry<'d> {
 		let Self {
 			distributions,
 			owners,
@@ -568,18 +570,18 @@
 	}
 }
 
-enum DistEntry<'d> {
+pub enum DistEntry<'d> {
 	Vacant(VacantDistEntry<'d>),
 	Occupied(OccupiedDistEntry<'d>),
 }
 impl DistEntry<'_> {
-	fn remove(self, whole_dist: bool, reason: String) -> Self {
+	pub fn remove(self, whole_dist: bool, reason: String) -> Self {
 		match self {
 			DistEntry::Vacant(_) => self,
 			DistEntry::Occupied(o) => Self::Vacant(o.remove(whole_dist, reason)),
 		}
 	}
-	fn set(self, secret: FleetSecretData, reason: String) -> Self {
+	pub fn set(self, secret: FleetSecretData, reason: String) -> Self {
 		Self::Occupied(match self {
 			DistEntry::Vacant(e) => e.set(secret),
 			DistEntry::Occupied(e) => e.set(secret, reason),
@@ -683,7 +685,7 @@
 }
 
 impl FleetSecrets {
-	pub fn keys(&self) -> btree_map::Keys<String, FleetSecretDistributions> {
+	pub fn keys(&self) -> btree_map::Keys<'_, String, FleetSecretDistributions> {
 		self.0.keys()
 	}
 
@@ -713,9 +715,7 @@
 	}
 
 	pub fn get_or_create(&mut self, secret: &str) -> &mut FleetSecretDistributions {
-		self.0
-			.entry(secret.to_owned())
-			.or_insert(FleetSecretDistributions::default())
+		self.0.entry(secret.to_owned()).or_default()
 	}
 
 	pub fn contains(&self, secret: &str) -> bool {
modifiedcrates/fleet-base/src/host.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/host.rs
+++ b/crates/fleet-base/src/host.rs
@@ -13,18 +13,17 @@
 use camino::{Utf8Path, Utf8PathBuf};
 use chrono::{DateTime, Utc};
 use fleet_shared::SecretData;
-use nix_eval::{Store, Value, eval_store, nix_go, nix_go_json, util::assert_warn};
+use nix_eval::{Store, Value, drv::DrvGraph, eval_store, nix_go, nix_go_json, util::assert_warn};
 use remowt_client::{AgentBundle, Remowt};
 use remowt_endpoints::fs::FsClient;
-use remowt_link_shared::Address;
+use remowt_fleet::NixClient;
+use remowt_link_shared::BifConfig;
 use remowt_ui_prompt::auto::AutoPrompter;
 use remowt_ui_prompt::bifrost::PromptEndpoints;
 use remowt_ui_prompt::{PrependSourcePrompter, Source};
-use tabled::Tabled;
 use tempfile::NamedTempFile;
-use time::UtcDateTime;
-use tokio::task::spawn_blocking;
-use tracing::warn;
+use tokio::{sync::OnceCell, task::spawn_blocking};
+use tracing::{info, warn};
 
 use crate::fleetdata::{
 	FleetData, FleetSecretData, FleetSecretDistribution, FleetSecretPart, SecretOwner,
@@ -101,7 +100,7 @@
 	groups: OnceLock<Vec<String>>,
 
 	// TODO: Both of those values are taken from host opts, there should be a cleaner way to specify it
-	deploy_kind: OnceLock<DeployKind>,
+	deploy_kind: OnceCell<DeployKind>,
 	session_destination: OnceLock<String>,
 	legacy_ssh_store: OnceLock<bool>,
 
@@ -114,7 +113,7 @@
 	pub local: bool,
 	pub remowt: OnceLock<Remowt>,
 	nix_store: OnceLock<Arc<Store>>,
-	nix_plugin: tokio::sync::OnceCell<()>,
+	nix_plugin: OnceCell<()>,
 }
 
 const NIX_PLUGIN_ID: u16 = 2;
@@ -130,75 +129,16 @@
 
 fn agent_bundle() -> Result<AgentBundle> {
 	AgentBundle::from_dir(agents_dir()?)
-}
-
-#[derive(Debug, Clone, Copy)]
-pub enum GenerationStorage {
-	Deployer,
-	Machine,
-	Pusher,
-}
-impl GenerationStorage {
-	fn prefix(&self) -> &'static str {
-		match self {
-			GenerationStorage::Deployer => "deployer.",
-			GenerationStorage::Machine => "",
-			GenerationStorage::Pusher => "pusher.",
-		}
-	}
 }
 
-#[derive(Tabled, Debug)]
-pub struct Generation {
-	#[tabled(rename = "ID", format("{}", self.rollback_id()))]
-	pub id: u32,
-	#[tabled(rename = "Current")]
-	pub current: bool,
-	#[tabled(rename = "Created at")]
-	pub datetime: UtcDateTime,
-	#[tabled(format = "{:?}")]
-	pub store_path: Utf8PathBuf,
-	#[tabled(skip)]
-	pub location: GenerationStorage,
-}
-impl Generation {
-	pub fn rollback_id(&self) -> String {
-		format!("{}{}", self.location.prefix(), self.id)
-	}
+enum RemoteDerivationMode {
+	CopySigned,
+	Copy,
+	Attic,
+	Cachix,
 }
 
 impl ConfigHost {
-	pub async fn list_generations(&self, profile: &str) -> Result<Vec<Generation>> {
-		let plugin_id = self.ensure_nix_plugin().await?;
-		let nix = self
-			.remowt()
-			.await?
-			.plugin_endpoints::<remowt_fleet::NixClient<_>>(plugin_id);
-		let raw = nix
-			.list_generations(profile.to_owned())
-			.await
-			.map_err(|e| anyhow!("{e:?}"))?
-			.map_err(|e| anyhow!("{e}"))?;
-		raw.into_iter()
-			.map(|g| {
-				let id: u32 =
-					g.id.try_into()
-						.with_context(|| format!("generation id {} doesn't fit in u32", g.id))?;
-				let datetime = UtcDateTime::from_unix_timestamp(g.creation_time_unix)
-					.with_context(|| {
-						format!("invalid generation timestamp {}", g.creation_time_unix)
-					})?;
-				Ok(Generation {
-					id,
-					current: g.current,
-					datetime,
-					store_path: g.store_path,
-					location: GenerationStorage::Machine,
-				})
-			})
-			.collect()
-	}
-
 	pub fn set_session_destination(&self, dest: String) {
 		self.session_destination
 			.set(dest)
@@ -215,34 +155,31 @@
 			.expect("legacy ssh store is already set")
 	}
 	pub async fn deploy_kind(&self) -> Result<DeployKind> {
-		if let Some(kind) = self.deploy_kind.get() {
-			return Ok(*kind);
-		}
-		let remowt = self.remowt().await?;
-		let fs = remowt.endpoints::<FsClient<_>>();
-		let is_fleet_managed = match fs.file_exists(Utf8PathBuf::from("/etc/FLEET_HOST")).await {
-			Ok(v) => v,
-			Err(e) => {
-				bail!("failed to query remote system kind: {e}");
+		self.deploy_kind.get_or_try_init(|| async {
+			let remowt = self.remowt().await?;
+			let fs = remowt.endpoints::<FsClient<_>>();
+			let is_fleet_managed = match fs.file_exists(Utf8PathBuf::from("/etc/FLEET_HOST")).await {
+				Ok(v) => v,
+				Err(e) => {
+					bail!("failed to query remote system kind: {e}");
+				}
+			};
+			if !is_fleet_managed {
+				bail!(
+					"{}",
+					indoc::indoc! {"
+					host is not marked as managed by fleet
+					if you're not trying to lustrate/install system from scratch,
+					you should either
+						1. manually create /etc/FLEET_HOST file on the target host,
+						2. use ?deploy_kind=fleet host argument if you're upgrading from older version of fleet
+						3. use ?deploy_kind=upgrade_to_fleet if you're upgrading from plain nixos to fleet-managed nixos
+					for installation use ?deploy_kind=nixos_install / ?deploy_kind=nixos_lustrate 
+				"}
+				);
 			}
-		};
-		if !is_fleet_managed {
-			bail!(
-				"{}",
-				indoc::indoc! {"
-				host is not marked as managed by fleet
-				if you're not trying to lustrate/install system from scratch,
-				you should either
-					1. manually create /etc/FLEET_HOST file on the target host,
-					2. use ?deploy_kind=fleet host argument if you're upgrading from older version of fleet
-					3. use ?deploy_kind=upgrade_to_fleet if you're upgrading from plain nixos to fleet-managed nixos
-				for installation use ?deploy_kind=nixos_install / ?deploy_kind=nixos_lustrate 
-			"}
-			);
-		}
-		// TOCTOU is possible
-		let _ = self.deploy_kind.set(DeployKind::Fleet);
-		Ok(*self.deploy_kind.get().expect("deploy kind is just set"))
+			Ok(DeployKind::Fleet)
+		}).await.copied()
 	}
 	async fn connection(&self) -> Result<Remowt> {
 		if let Some(conn) = self.remowt.get() {
@@ -285,6 +222,11 @@
 		self.connection().await
 	}
 
+	pub async fn nix_client(&self) -> Result<NixClient<BifConfig>> {
+		let remowt = self.remowt().await?;
+		let plugin_id = self.ensure_nix_plugin().await?;
+		Ok(remowt.plugin_endpoints(plugin_id))
+	}
 	pub fn ensure_nix_plugin(&self) -> Pin<Box<dyn Future<Output = Result<u16>> + Send + '_>> {
 		Box::pin(async {
 			self.nix_plugin
@@ -305,12 +247,6 @@
 						.run0_load_plugin_path(NIX_PLUGIN_ID, bin.as_str())
 						.await
 						.context("failed to load the fleet nix plugin")?;
-					self.remowt()
-						.await?
-						.rpc()
-						.wait_for_connection_to(Address::Plugin(NIX_PLUGIN_ID))
-						.await
-						.map_err(|_| anyhow!("failed to wait for plugin"))?;
 					anyhow::Ok(())
 				})
 				.await?;
@@ -407,6 +343,10 @@
 		}
 		let sign: Pin<Box<dyn Future<Output = Result<()>> + Send>> = {
 			let path = path.clone();
+			let graph = DrvGraph::resolve(&eval_store(), &path)
+				.context("failed to resolve graph to be uploaded")?;
+			info!("signing {} paths", graph.nodes.len());
+
 			Box::pin(async move {
 				let local = self.config.local_host();
 				let plugin_id = local.ensure_nix_plugin().await?;
@@ -564,8 +504,8 @@
 					local: true,
 					remowt: OnceLock::new(),
 					nix_store: OnceLock::new(),
-					nix_plugin: tokio::sync::OnceCell::new(),
-					deploy_kind: OnceLock::new(),
+					nix_plugin: OnceCell::new(),
+					deploy_kind: OnceCell::new(),
 					session_destination: OnceLock::new(),
 					legacy_ssh_store: OnceLock::new(),
 				})
@@ -607,8 +547,8 @@
 			local: self.localhost == name,
 			remowt: OnceLock::new(),
 			nix_store: OnceLock::new(),
-			nix_plugin: tokio::sync::OnceCell::new(),
-			deploy_kind: OnceLock::new(),
+			nix_plugin: OnceCell::new(),
+			deploy_kind: OnceCell::new(),
 			session_destination: OnceLock::new(),
 			legacy_ssh_store: OnceLock::new(),
 		})
modifiedcrates/fleet-base/src/lib.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/lib.rs
+++ b/crates/fleet-base/src/lib.rs
@@ -3,4 +3,5 @@
 pub mod host;
 mod keys;
 pub mod opts;
+pub mod pins;
 pub mod primops;
addedcrates/fleet-base/src/pins.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/fleet-base/src/pins.rs
@@ -0,0 +1,69 @@
+use anyhow::{Context as _, Result, anyhow};
+use camino::Utf8PathBuf;
+use tabled::Tabled;
+use time::UtcDateTime;
+
+use crate::host::ConfigHost;
+
+#[derive(Debug, Clone, Copy)]
+pub enum GenerationStorage {
+	Deployer,
+	Machine,
+	Pusher,
+}
+impl GenerationStorage {
+	fn prefix(&self) -> &'static str {
+		match self {
+			GenerationStorage::Deployer => "deployer.",
+			GenerationStorage::Machine => "",
+			GenerationStorage::Pusher => "pusher.",
+		}
+	}
+}
+
+#[derive(Tabled, Debug)]
+pub struct Generation {
+	#[tabled(rename = "ID", format("{}", self.rollback_id()))]
+	pub id: u32,
+	#[tabled(rename = "Current")]
+	pub current: bool,
+	#[tabled(rename = "Created at")]
+	pub datetime: UtcDateTime,
+	#[tabled(format = "{:?}")]
+	pub store_path: Utf8PathBuf,
+	#[tabled(skip)]
+	pub location: GenerationStorage,
+}
+impl Generation {
+	pub fn rollback_id(&self) -> String {
+		format!("{}{}", self.location.prefix(), self.id)
+	}
+}
+impl ConfigHost {
+	pub async fn list_generations(&self, profile: &str) -> Result<Vec<Generation>> {
+		let nix = self.nix_client().await?;
+		let raw = nix
+			.list_generations(profile.to_owned())
+			.await
+			.map_err(|e| anyhow!("{e:?}"))?
+			.map_err(|e| anyhow!("{e}"))?;
+		raw.into_iter()
+			.map(|g| {
+				let id: u32 =
+					g.id.try_into()
+						.with_context(|| format!("generation id {} doesn't fit in u32", g.id))?;
+				let datetime = UtcDateTime::from_unix_timestamp(g.creation_time_unix)
+					.with_context(|| {
+						format!("invalid generation timestamp {}", g.creation_time_unix)
+					})?;
+				Ok(Generation {
+					id,
+					current: g.current,
+					datetime,
+					store_path: g.store_path,
+					location: GenerationStorage::Machine,
+				})
+			})
+			.collect()
+	}
+}
modifiedcrates/nixlike/fuzz/Cargo.tomldiffbeforeafterboth
--- a/crates/nixlike/fuzz/Cargo.toml
+++ b/crates/nixlike/fuzz/Cargo.toml
@@ -4,7 +4,7 @@
 version = "0.0.0"
 authors = ["Automatically generated"]
 publish = false
-edition = "2024"
+edition.workspace = true
 
 [package.metadata]
 cargo-fuzz = true
modifiedcrates/remowt-fleet/Cargo.tomldiffbeforeafterboth
--- a/crates/remowt-fleet/Cargo.toml
+++ b/crates/remowt-fleet/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-fleet"
 description = "Remowt endpoints for fleet"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 
 [dependencies]
 bifrostlink.workspace = true
@@ -18,3 +18,4 @@
 tokio = { workspace = true, features = ["io-util", "net", "process", "rt"] }
 tracing.workspace = true
 uuid.workspace = true
+remowt-link-shared.workspace = true
modifiedcrates/remowt-fleet/src/lib.rsdiffbeforeafterboth
--- a/crates/remowt-fleet/src/lib.rs
+++ b/crates/remowt-fleet/src/lib.rs
@@ -7,6 +7,7 @@
 use nix_eval::eval_store;
 use remowt_client::Remowt;
 use remowt_endpoints::nix_daemon::NixDaemonClient;
+use remowt_link_shared::iroh_tunnel::TunnelAddr;
 use serde::{Deserialize, Serialize};
 use tokio::net::UnixListener;
 use tokio::task::spawn_blocking;
@@ -98,8 +99,10 @@
 				continue;
 			}
 		};
-		let sock_str = remote_sock.as_str().to_owned();
-		match nix.serve_store(store.clone(), sock_str).await {
+		match nix
+			.serve_store(store.clone(), TunnelAddr::Unix(remote_sock))
+			.await
+		{
 			Ok(Ok(())) => {}
 			Ok(Err(e)) => {
 				error!("nix bridge: {e}");
modifiedflake.lockdiffbeforeafterboth
--- a/flake.lock
+++ b/flake.lock
@@ -171,35 +171,6 @@
         "type": "github"
       }
     },
-    "remowt-agents": {
-      "inputs": {
-        "crane": [
-          "crane"
-        ],
-        "flake-parts": [
-          "flake-parts"
-        ],
-        "nixpkgs": [
-          "nixpkgs"
-        ],
-        "rust-overlay": "rust-overlay",
-        "shelly": [
-          "shelly"
-        ]
-      },
-      "locked": {
-        "lastModified": 1781491763,
-        "ref": "refs/heads/trunk",
-        "rev": "8b18e8b236d428ed8fbf5818272d17f5f538c13c",
-        "revCount": 40,
-        "type": "git",
-        "url": "https://gerrit.delta.rocks/remowt"
-      },
-      "original": {
-        "type": "git",
-        "url": "https://gerrit.delta.rocks/remowt"
-      }
-    },
     "root": {
       "inputs": {
         "crane": "crane",
@@ -207,33 +178,12 @@
         "fleet-tf": "fleet-tf",
         "nix": "nix",
         "nixpkgs": "nixpkgs",
-        "remowt-agents": "remowt-agents",
-        "rust-overlay": "rust-overlay_2",
+        "rust-overlay": "rust-overlay",
         "shelly": "shelly",
         "treefmt-nix": "treefmt-nix"
       }
     },
     "rust-overlay": {
-      "inputs": {
-        "nixpkgs": [
-          "remowt-agents",
-          "nixpkgs"
-        ]
-      },
-      "locked": {
-        "lastModified": 1769309768,
-        "owner": "oxalica",
-        "repo": "rust-overlay",
-        "rev": "140c9dc582cb73ada2d63a2180524fcaa744fad5",
-        "type": "github"
-      },
-      "original": {
-        "owner": "oxalica",
-        "repo": "rust-overlay",
-        "type": "github"
-      }
-    },
-    "rust-overlay_2": {
       "inputs": {
         "nixpkgs": [
           "nixpkgs"
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -23,13 +23,6 @@
       url = "github:numtide/treefmt-nix";
       inputs.nixpkgs.follows = "nixpkgs";
     };
-    remowt-agents = {
-      url = "git+https://gerrit.delta.rocks/remowt";
-      inputs.nixpkgs.follows = "nixpkgs";
-      inputs.flake-parts.follows = "flake-parts";
-      inputs.crane.follows = "crane";
-      inputs.shelly.follows = "shelly";
-    };
     # DeterminateSystem's nix fork is controversial, but I don't mind it,
     # and it has lazy-trees support which is useful for fleet.
     nix = {
modifiedpkgs/default.nixdiffbeforeafterboth
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -3,9 +3,17 @@
   craneLib,
   inputs,
 }:
+let
+  remowt-agents-bundle = callPackage ./remowt-agents-bundle.nix { inherit craneLib; };
+in
 {
   fleet = callPackage ./fleet.nix { inherit craneLib inputs; };
-  remowt-plugin-fleet = callPackage ./remowt-plugin-fleet.nix { inherit craneLib inputs; };
   fleet-install-secrets = callPackage ./fleet-install-secrets.nix { inherit craneLib; };
   fleet-generator-helper = callPackage ./fleet-generator-helper.nix { inherit craneLib; };
+
+  inherit remowt-agents-bundle;
+  remowt-plugin-fleet = callPackage ./remowt-plugin-fleet.nix {
+    inherit craneLib inputs remowt-agents-bundle;
+  };
+  remowt-ssh = callPackage ./remowt-ssh.nix { inherit craneLib remowt-agents-bundle; };
 }
modifiedpkgs/fleet.nixdiffbeforeafterboth
--- a/pkgs/fleet.nix
+++ b/pkgs/fleet.nix
@@ -3,6 +3,7 @@
   craneLib,
   installShellFiles,
   inputs,
+  remowt-agents-bundle,
 
   stdenv,
   pkg-config,
@@ -26,7 +27,7 @@
 
   cargoExtraArgs = "--locked -p ${pname}";
 
-  REMOWT_AGENTS_DIR = "${inputs.remowt-agents.packages.${system}.remowt-agents}";
+  REMOWT_AGENTS_DIR = "${remowt-agents-bundle}";
   # TODO: built-in fleet prompter should be a prodash widget, or it should require
   # tty remowt prompter running on host machine idk.
   ROFI = "${rofi}/bin/rofi";
addedpkgs/remowt-agents-bundle.nixdiffbeforeafterboth
--- /dev/null
+++ b/pkgs/remowt-agents-bundle.nix
@@ -0,0 +1,73 @@
+{
+  craneLib,
+  lib,
+  pkgs,
+  runCommandLocal,
+}:
+let
+  crateName = "remowt-agent";
+
+  buildFor =
+    {
+      target,
+      crossPkgs,
+    }:
+    let
+      cc = crossPkgs.stdenv.cc;
+      ccBin = "${cc}/bin/${cc.targetPrefix}";
+      ut = builtins.replaceStrings [ "-" ] [ "_" ] target;
+      linkerEnv = "CARGO_TARGET_${lib.toUpper ut}_LINKER";
+    in
+    craneLib.buildPackage (
+      {
+        src = craneLib.cleanCargoSource ../.;
+        pname = "${crateName}-${target}";
+
+        cargoExtraArgs = "--locked -p ${crateName}";
+
+        CARGO_BUILD_TARGET = target;
+        CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
+
+        depsBuildBuild = [ cc ];
+        doCheck = false;
+      }
+      // {
+        ${linkerEnv} = "${ccBin}cc";
+        "CC_${ut}" = "${ccBin}cc";
+        "CXX_${ut}" = "${ccBin}c++";
+        "AR_${ut}" = "${ccBin}ar";
+      }
+    );
+  x86_64 = buildFor {
+    target = "x86_64-unknown-linux-musl";
+    crossPkgs = pkgs;
+  };
+  aarch64 = buildFor {
+    target = "aarch64-unknown-linux-musl";
+    crossPkgs = pkgs.pkgsCross.aarch64-multiplatform-musl;
+  };
+  armv7l = buildFor {
+    target = "armv7-unknown-linux-musleabihf";
+    crossPkgs = pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsMusl;
+  };
+in
+runCommandLocal "remowt-agents-bundle"
+  {
+    passthru = {
+      perArch = {
+        inherit x86_64 aarch64 armv7l;
+      };
+    };
+  }
+  ''
+    mkdir -p $out
+    cp ${x86_64}/bin/remowt-agent  $out/remowt-agent-x86_64
+    cp ${aarch64}/bin/remowt-agent $out/remowt-agent-aarch64
+    cp ${armv7l}/bin/remowt-agent  $out/remowt-agent-armv7l
+    chmod +w $out/remowt-agent-*
+
+    for arch in x86_64 aarch64 armv7l; do
+      hash=$(sha256sum "$out/remowt-agent-$arch" | cut -d' ' -f1)
+      printf '%s %s\n' "$arch" "$hash" >> $out/hashes
+    done
+  ''
addedpkgs/remowt-ssh.nixdiffbeforeafterboth
--- /dev/null
+++ b/pkgs/remowt-ssh.nix
@@ -0,0 +1,17 @@
+{
+  craneLib,
+  remowt-agents-bundle,
+  rofi,
+}:
+let
+  pname = "remowt-ssh";
+in
+craneLib.buildPackage {
+  inherit pname;
+  src = craneLib.cleanCargoSource ../.;
+
+  cargoExtraArgs = "--locked -p ${pname}";
+
+  REMOWT_AGENTS_DIR = "${remowt-agents-bundle}";
+  ROFI = "${rofi}/bin/rofi";
+}
modifiedremowt/cmds/remowt-agent/Cargo.tomldiffbeforeafterboth
--- a/remowt/cmds/remowt-agent/Cargo.toml
+++ b/remowt/cmds/remowt-agent/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-agent"
 description = "remowt on-host agent serving fs/pty/systemd endpoints over bifrostlink"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/cmds/remowt-agent/src/askpass.rsdiffbeforeafterboth
--- a/remowt/cmds/remowt-agent/src/askpass.rs
+++ b/remowt/cmds/remowt-agent/src/askpass.rs
@@ -1,47 +1,22 @@
 use std::borrow::Cow;
 use std::io::Write as _;
 
-use anyhow::Context as _;
-use remowt_ui_prompt::dbus::{DbusPrompterInterface, DbusPrompterProxy, BUS_NAME, PROMPTER_PATH};
+use bifrostlink::declarative::RemoteEndpoints as _;
+use remowt_link_shared::{gateway, Address, BifConfig};
+use remowt_ui_prompt::bifrost::PromptEndpointsClient;
 use remowt_ui_prompt::{Prompter, Source};
-use tracing::debug;
-use zbus::Connection;
-
-pub async fn serve<P>(conn: &Connection, prompter: P) -> anyhow::Result<()>
-where
-	P: Prompter + 'static,
-{
-	conn.object_server()
-		.at(PROMPTER_PATH, DbusPrompterInterface(prompter))
-		.await?;
-	match conn.request_name(BUS_NAME).await {
-		Ok(()) => {}
-		Err(zbus::Error::NameTaken) => {
-			debug!("{BUS_NAME} already owned, chaining to upstream");
-		}
-		Err(e) => return Err(e.into()),
-	}
-	Ok(())
-}
 
 pub async fn ask(prompt: &str, description: String) -> anyhow::Result<()> {
-	let conn = Connection::session()
-		.await
-		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
-	let proxy = DbusPrompterProxy::builder(&conn)
-		.destination(BUS_NAME)?
-		.path(PROMPTER_PATH)?
-		.build()
-		.await?;
-
-	let password = proxy
-		.prompt_text(
-			false,
-			prompt,
-			&description,
-			&[Source(Cow::Borrowed("remowt-askpass"))],
-		)
-		.await?;
+	let rpc = gateway::connect(&gateway::socket_path()?).await?;
+	let prompter = PromptEndpointsClient::<BifConfig>::wrap(rpc.remote(Address::User));
+	let password = Prompter::prompt_text(
+		&prompter,
+		false,
+		prompt,
+		&description,
+		&[Source(Cow::Borrowed("remowt-askpass"))],
+	)
+	.await?;
 
 	let mut out = std::io::stdout().lock();
 	out.write_all(password.as_bytes())?;
deletedremowt/cmds/remowt-agent/src/bus.rsdiffbeforeafterboth
--- a/remowt/cmds/remowt-agent/src/bus.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-use std::process::Stdio;
-
-use anyhow::Context as _;
-use futures::StreamExt as _;
-use tokio::process::{Child, Command};
-use tokio_util::codec::{FramedRead, LinesCodec};
-use zbus::Connection;
-
-pub struct PrivateBus {
-	pub address: String,
-	pub conn: Connection,
-	_child: Child,
-}
-
-pub async fn spawn() -> anyhow::Result<PrivateBus> {
-	let mut child = Command::new("dbus-daemon")
-		.args(["--session", "--nofork", "--print-address"])
-		.stdout(Stdio::piped())
-		.kill_on_drop(true)
-		.spawn()
-		.context("spawning dbus-daemon for the private bus")?;
-
-	let stdout = child.stdout.take().expect("piped");
-	let address = FramedRead::new(stdout, LinesCodec::new())
-		.next()
-		.await
-		.context("dbus-daemon exited before printing its address")?
-		.context("reading dbus-daemon address")?;
-
-	let conn = zbus::connection::Builder::address(address.as_str())?
-		.build()
-		.await
-		.context("connecting to the private bus")?;
-
-	Ok(PrivateBus {
-		address,
-		conn,
-		_child: child,
-	})
-}
modifiedremowt/cmds/remowt-agent/src/editor.rsdiffbeforeafterboth
--- a/remowt/cmds/remowt-agent/src/editor.rs
+++ b/remowt/cmds/remowt-agent/src/editor.rs
@@ -3,87 +3,23 @@
 use std::time::Duration;
 use std::{fs, io};
 
-use anyhow::{bail, Context as _};
+use anyhow::{anyhow, bail, Context as _};
+use bifrostlink::declarative::RemoteEndpoints as _;
 use nix::libc;
 use remowt_link_shared::editor::EditorEndpointsClient;
+use remowt_link_shared::{gateway, Address, BifConfig};
 use tokio::process::Command;
-use zbus::{fdo, interface, proxy, Connection};
-
-use remowt_link_shared::BifConfig;
-
-const BUS_NAME: &str = "lach.RemowtEditor";
-const SERVICE_PATH: &str = "/lach/Editor";
-
-pub struct EditorService {
-	editor: EditorEndpointsClient<BifConfig>,
-}
 
-#[interface(name = "lach.RemowtEditor")]
-impl EditorService {
-	/// Attach the User's GUI to the nvim server at `socket_path` (on the remote),
-	/// blocking until the user is done.
-	async fn edit(&self, socket_path: String) -> fdo::Result<()> {
-		self.editor
-			.open_editor(socket_path)
-			.await
-			.map_err(|e| fdo::Error::Failed(format!("requesting editor on the User: {e}")))?
-			.map_err(|e| fdo::Error::Failed(format!("editor failed: {e}")))?;
-		Ok(())
-	}
-
-	async fn forward_tcp(&self, addr: String) -> fdo::Result<u16> {
-		let local = self
-			.editor
-			.expose_tcp(addr)
-			.await
-			.map_err(|e| fdo::Error::Failed(format!("requesting tcp forward on the User: {e}")))?
-			.map_err(|e| fdo::Error::Failed(format!("tcp forward failed: {e}")))?;
-		Ok(local)
-	}
-
-	async fn forward_udp(&self, addr: String) -> fdo::Result<u16> {
-		let local = self
-			.editor
-			.expose_udp(addr)
-			.await
-			.map_err(|e| fdo::Error::Failed(format!("requesting udp forward on the User: {e}")))?
-			.map_err(|e| fdo::Error::Failed(format!("udp forward failed: {e}")))?;
-		Ok(local)
-	}
-}
-
-pub async fn serve(
-	conn: &Connection,
-	editor: EditorEndpointsClient<BifConfig>,
-) -> anyhow::Result<()> {
-	conn.object_server()
-		.at(SERVICE_PATH, EditorService { editor })
-		.await?;
-	conn.request_name(BUS_NAME).await?;
-	Ok(())
-}
-
-#[proxy(interface = "lach.RemowtEditor")]
-trait RemowtEditor {
-	async fn edit(&self, socket_path: &str) -> fdo::Result<()>;
-	async fn forward_tcp(&self, addr: &str) -> fdo::Result<u16>;
-	async fn forward_udp(&self, addr: &str) -> fdo::Result<u16>;
-}
-
 pub async fn forward(udp: bool, addr: String) -> anyhow::Result<()> {
-	let conn = Connection::session()
-		.await
-		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
-	let proxy = RemowtEditorProxy::builder(&conn)
-		.destination(BUS_NAME)?
-		.path(SERVICE_PATH)?
-		.build()
-		.await?;
+	let rpc = gateway::connect(&gateway::socket_path()?).await?;
+	let editor = EditorEndpointsClient::<BifConfig>::wrap(rpc.remote(Address::User));
 	let local = if udp {
-		proxy.forward_udp(&addr).await?
+		editor.expose_udp(addr).await
 	} else {
-		proxy.forward_tcp(&addr).await?
-	};
+		editor.expose_tcp(addr).await
+	}
+	.map_err(|e| anyhow!("requesting forward on the User: {e}"))?
+	.map_err(|e| anyhow!("forward failed: {e}"))?;
 	println!("{local}");
 	Ok(())
 }
@@ -125,15 +61,13 @@
 		.await
 		.context("nvim did not start its server")?;
 
-	let conn = Connection::session()
+	let rpc = gateway::connect(&gateway::socket_path()?).await?;
+	let editor = EditorEndpointsClient::<BifConfig>::wrap(rpc.remote(Address::User));
+	let result = editor
+		.open_editor(sock_str)
 		.await
-		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
-	let proxy = RemowtEditorProxy::builder(&conn)
-		.destination(BUS_NAME)?
-		.path(SERVICE_PATH)?
-		.build()
-		.await?;
-	let result = proxy.edit(&sock_str).await;
+		.map_err(|e| anyhow!("requesting editor on the User: {e}"))
+		.and_then(|r| r.map_err(|e| anyhow!("editor failed: {e}")));
 
 	if tokio::time::timeout(Duration::from_secs(2), child.wait())
 		.await
@@ -143,8 +77,7 @@
 	}
 	let _ = fs::remove_file(&sock);
 
-	result?;
-	Ok(())
+	result
 }
 
 async fn wait_for_socket(path: &Path) -> anyhow::Result<()> {
modifiedremowt/cmds/remowt-agent/src/main.rsdiffbeforeafterboth
--- a/remowt/cmds/remowt-agent/src/main.rs
+++ b/remowt/cmds/remowt-agent/src/main.rs
@@ -7,8 +7,8 @@
 use std::path::PathBuf;
 use std::sync::{Arc, Mutex, OnceLock};
 
+use bifrostlink::Rpc;
 use bifrostlink::declarative::RemoteEndpoints;
-use bifrostlink::Rpc;
 use bifrostlink_ports::stdio::from_stdio;
 use bifrostlink_ports::unix_socket::from_socket;
 use clap::Parser;
@@ -17,9 +17,9 @@
 	subprocess::Subprocess, systemd::Systemd,
 };
 use remowt_link_shared::iroh_tunnel::TunnelDialer;
-use remowt_link_shared::{editor::EditorEndpointsClient, Address, BifConfig};
-use remowt_polkit_shared::{emphasize, Identity, PidDisplay};
-use remowt_ui_prompt::bifrost::PromptEndpointsClient;
+use remowt_link_shared::{Address, BifConfig, gateway};
+use remowt_polkit_shared::{Identity, PidDisplay, emphasize};
+use remowt_ui_prompt::bifrost::{PromptEndpointsClient, serve_prompts};
 use remowt_ui_prompt::rofi::RofiPrompter;
 use remowt_ui_prompt::{PrependSourcePrompter, Prompter, Source};
 use tokio::fs;
@@ -29,13 +29,12 @@
 use tracing::{debug, trace};
 use zbus::fdo;
 use zbus::zvariant::{OwnedValue, Str};
-use zbus::{interface, Connection};
+use zbus::{Connection, interface};
 use zbus_polkit::policykit1::Subject;
 
 use self::helper::{Helper, SocketHelper, SuidHelper};
 
 pub mod askpass;
-pub mod bus;
 pub mod editor;
 pub mod helper;
 
@@ -132,19 +131,18 @@
 					0 => {
 						return Err(fdo::Error::AuthFailed(
 							"no identity to authenticate as".to_owned(),
-						))
+						));
 					}
 					1 => 0,
-					_ => {
-						prompter
-							.prompt_enum(
-								"Identity",
-								"Select identity to use for polkit authorization",
-								&identity_displays,
-								&[],
-							)
-							.await?
-					}
+					_ => prompter
+						.prompt_enum(
+							"Identity",
+							"Select identity to use for polkit authorization",
+							&identity_displays,
+							&[],
+						)
+						.await
+						.map_err(prompt_err)?,
 				};
 				debug!("identity chosen");
 
@@ -198,6 +196,15 @@
 	}
 }
 
+fn prompt_err(value: remowt_ui_prompt::Error) -> fdo::Error {
+	use remowt_ui_prompt::Error;
+	match value {
+		Error::Cancel => fdo::Error::NoReply("input was cancelled".to_owned()),
+		Error::Remote(e) => fdo::Error::NoReply(format!("remote error occured: {e}")),
+		Error::InputError(e) => fdo::Error::Failed(e),
+	}
+}
+
 const OBJ_PATH: &str = "/org/freedesktop/PolicyKit1/AuthenticationAgent";
 
 #[derive(Parser)]
@@ -268,10 +275,12 @@
 	};
 	register_auth_agent(&system_conn, Agent::new(helper, RofiPrompter)).await?;
 
-	let session_conn = Connection::session().await?;
-	askpass::serve(&session_conn, RofiPrompter).await?;
+	let mut rpc = Rpc::<BifConfig>::new(Address::User);
+	serve_prompts(&mut rpc, RofiPrompter);
+
+	gateway::serve(rpc.clone(), &gateway::local_socket()?).await?;
 
-	let _keep_alive = (system_conn, session_conn);
+	let _keep_alive = (system_conn, rpc);
 	pending().await
 }
 async fn main_real_agent(
@@ -298,13 +307,9 @@
 	remowt_plugin::host::serve(&mut rpc);
 
 	let user_prompter = PromptEndpointsClient::wrap(rpc.remote(Address::User));
-	let editor_client = EditorEndpointsClient::wrap(rpc.remote(Address::User));
-
-	let bus = bus::spawn().await?;
-	askpass::serve(&bus.conn, user_prompter.clone()).await?;
-	editor::serve(&bus.conn, editor_client).await?;
 
 	let helpers = tempfile::Builder::new().prefix("remowt-path.").tempdir()?;
+	let gateway_socket = helpers.path().join(gateway::SOCKET_NAME);
 	let exe = std::env::current_exe()?;
 	let askpass_helper = helpers.path().join("remowt-askpass");
 	let editor_helper = helpers.path().join("remowt-editor");
@@ -342,7 +347,7 @@
 		std::env::set_var("SSH_ASKPASS_REQUIRE", "force");
 		std::env::set_var("EDITOR", &editor_helper);
 		std::env::set_var("VISUAL", &editor_helper);
-		std::env::set_var("DBUS_SESSION_BUS_ADDRESS", &bus.address);
+		std::env::set_var(gateway::SOCKET_ENV, &gateway_socket);
 	}
 
 	let port = match path {
@@ -351,10 +356,9 @@
 	};
 	rpc.add_direct(Address::User, port, bifrostlink::Rtt(0));
 
+	gateway::serve(rpc.clone(), &gateway_socket).await?;
+
 	let polkit_conn = if !privileged && !local {
-		// The unprivileged agent doubles as a polkit authentication agent so
-		// `run0` (e.g. our own elevation) routes its prompt to the User over
-		// bifrost instead of failing on a tty-less session.
 		let conn = Connection::system().await?;
 		let helper = SocketHelper {
 			fallback: SuidHelper,
@@ -365,7 +369,7 @@
 		None
 	};
 
-	let _keep_alive = (bus, helpers, polkit_conn);
+	let _keep_alive = (helpers, polkit_conn);
 	pending().await
 }
 
modifiedremowt/cmds/remowt-ssh/Cargo.tomldiffbeforeafterboth
--- a/remowt/cmds/remowt-ssh/Cargo.toml
+++ b/remowt/cmds/remowt-ssh/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-ssh"
 description = "SSH transport client for connecting to a remowt agent"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/cmds/remowt-ssh/src/main.rsdiffbeforeafterboth
--- a/remowt/cmds/remowt-ssh/src/main.rs
+++ b/remowt/cmds/remowt-ssh/src/main.rs
@@ -75,14 +75,8 @@
 			description: "".to_owned(),
 		},
 	);
-	if let Some(sess) = conn.ssh() {
-		serve_editor(
-			&mut rpc,
-			SshEditor {
-				sess,
-				conn: conn.clone(),
-			},
-		);
+	if conn.ssh().is_some() {
+		serve_editor(&mut rpc, SshEditor { conn: conn.clone() });
 	}
 
 	debug!("entering shell");
modifiedremowt/crates/polkit-shared/Cargo.tomldiffbeforeafterboth
--- a/remowt/crates/polkit-shared/Cargo.toml
+++ b/remowt/crates/polkit-shared/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-polkit-shared"
 description = "Shared polkit/PAM types for remowt"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/crates/remowt-client/Cargo.tomldiffbeforeafterboth
--- a/remowt/crates/remowt-client/Cargo.toml
+++ b/remowt/crates/remowt-client/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-client"
 description = "russh-based client connection to a remowt agent"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/crates/remowt-client/src/editor.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-client/src/editor.rs
+++ b/remowt/crates/remowt-client/src/editor.rs
@@ -6,14 +6,12 @@
 use remowt_endpoints::forward::ForwardClient;
 use remowt_link_shared::editor::{EditorBackend, Error};
 use remowt_link_shared::BifConfig;
-use russh::client::Handle;
 use tokio::net::{TcpListener, UdpSocket, UnixListener};
 use tracing::error;
 
-use crate::{Remowt, SshHandler};
+use crate::Remowt;
 
 pub struct SshEditor {
-	pub sess: Arc<Handle<SshHandler>>,
 	pub conn: Remowt,
 }
 impl EditorBackend for SshEditor {
@@ -22,21 +20,41 @@
 		let _ = std::fs::remove_file(&local);
 		let listener = UnixListener::bind(&local).map_err(|e| Error::Failed(e.to_string()))?;
 
-		let sess = self.sess.clone();
+		let conn = self.conn.clone();
 		let forward = tokio::spawn(async move {
 			loop {
 				let Ok((mut stream, _)) = listener.accept().await else {
 					break;
 				};
-				let sess = sess.clone();
+				let conn = conn.clone();
 				let remote = socket_path.clone();
 				tokio::spawn(async move {
-					match sess.channel_open_direct_streamlocal(remote).await {
-						Ok(ch) => {
-							let mut remote = ch.into_stream();
+					// Rides the iroh fast tunnel when established, else an
+					// ssh-forwarded unix socket.
+					let (forwarded, tunnel) = match conn.bind_fast_tunnel("editor", false).await {
+						Ok(v) => v,
+						Err(e) => {
+							error!("editor: bind tunnel failed: {e}");
+							return;
+						}
+					};
+					let fclient: ForwardClient<BifConfig> = conn.endpoints();
+					match fclient.connect_unix(tunnel, remote).await {
+						Ok(Ok(())) => {}
+						Ok(Err(e)) => {
+							error!("editor: agent connect_unix failed: {e}");
+							return;
+						}
+						Err(e) => {
+							error!("editor: connect_unix rpc failed: {e}");
+							return;
+						}
+					}
+					match forwarded.accept().await {
+						Ok(mut remote) => {
 							let _ = tokio::io::copy_bidirectional(&mut stream, &mut remote).await;
 						}
-						Err(e) => error!("opening direct-streamlocal to nvim failed: {e}"),
+						Err(e) => error!("editor: accept tunnel failed: {e}"),
 					}
 				});
 			}
modifiedremowt/crates/remowt-client/src/lib.rsdiffbeforeafterboth
before · remowt/crates/remowt-client/src/lib.rs
1use std::collections::HashMap;2use std::env;3use std::path::PathBuf;4use std::sync::atomic::AtomicU64;5use std::sync::{Arc, Mutex};67use anyhow::{anyhow, bail, ensure, Context as _, Result};8use bifrostlink::declarative::RemoteEndpoints;9use bifrostlink::{Remote, Rpc, Rtt};10use camino::{Utf8Path, Utf8PathBuf};11use remowt_link_shared::iroh_tunnel::{DatagramRouter, IrohBiStream, TunnelAddr};12use remowt_link_shared::plugin::PluginEndpointsClient;13use remowt_link_shared::port::child_port;14use remowt_link_shared::{Address, BifConfig};15use russh::client::{connect, Config, Handle, Handler, Msg, Session};16use russh::keys::agent::client::AgentClient;17use russh::keys::agent::AgentIdentity;18use russh::keys::check_known_hosts;19use russh::keys::ssh_key::PublicKey;20use russh::Channel;21use tempfile::TempDir;22use tokio::io::AsyncRead;23use tokio::net::UnixListener;24use tokio::sync::oneshot;25use tokio::task::JoinHandle;26use tokio::{27	fs,28	io::{AsyncBufReadExt as _, AsyncReadExt as _, AsyncWriteExt as _, BufReader},29};30use tracing::{debug, info, warn};31use uuid::Uuid;3233pub mod editor;34mod forwarded;35mod shell;36mod ssh_exec;37mod subprocess;3839use self::ssh_exec::SshExecChild;40pub use self::subprocess::{RemowtChild, SpawnOptions, StderrMode, StdioMode};41pub use forwarded::{RemowtListener, RemowtStream};42pub use shell::{RemowtShell, RemowtShellResizer};4344type Subs = Arc<Mutex<HashMap<Utf8PathBuf, oneshot::Sender<Channel<Msg>>>>>;4546fn sh_quote(s: impl AsRef<str>) -> String {47	format!("'{}'", s.as_ref().replace('\'', "'\\''"))48}4950const ESCALATORS: [(&str, &[&str]); 2] = [("run0", &["--background=", "--pipe"]), ("sudo", &[])];5152pub struct AgentBundle {53	dir: PathBuf,54	hashes: HashMap<String, String>,55}5657impl AgentBundle {58	pub fn from_dir(dir: impl Into<PathBuf>) -> Result<Self> {59		let dir = dir.into();60		let hashes_path = dir.join("hashes");61		let raw = std::fs::read_to_string(&hashes_path)62			.with_context(|| format!("reading agent hashes at {}", hashes_path.display()))?;63		let mut hashes = HashMap::new();64		for line in raw.lines() {65			let line = line.trim();66			if line.is_empty() {67				continue;68			}69			let (arch, hash) = line70				.split_once(char::is_whitespace)71				.ok_or_else(|| anyhow!("malformed hashes line: {line:?}"))?;72			hashes.insert(arch.to_owned(), hash.trim().to_owned());73		}74		ensure!(75			!hashes.is_empty(),76			"agent bundle {} has no hashes",77			dir.display()78		);79		Ok(Self { dir, hashes })80	}8182	fn binary(&self, arch: &str) -> PathBuf {83		self.dir.join(format!("remowt-agent-{arch}"))84	}8586	fn local_binary(&self) -> Result<PathBuf> {87		let arch = env::consts::ARCH;88		let path = self.binary(arch);89		ensure!(90			path.is_file(),91			"no local remowt-agent build for arch {arch} in bundle {}",92			self.dir.display()93		);94		Ok(path)95	}96}9798async fn run(sess: &Handle<SshHandler>, cmd: &str) -> Result<(Option<u32>, Vec<u8>)> {99	let ch = sess.channel_open_session().await?;100	ch.exec(true, cmd).await?;101102	let mut child = SshExecChild::from_exec(ch);103	drop(child.stdin);104	drain_to_tracing(child.stderr, cmd.to_owned(), true);105106	let mut out = Vec::new();107	child.stdout.read_to_end(&mut out).await?;108	let code = child.exit.await.ok().flatten();109	Ok((code, out))110}111112async fn run_string_ok(sess: &Handle<SshHandler>, cmd: &str) -> Result<String> {113	let (code, mut out) = run(sess, cmd).await?;114	ensure!(115		code == Some(0),116		"remote command failed (exit {code:?}): {cmd}"117	);118	if !out.is_empty() {119		ensure!(120			out.ends_with(b"\n"),121			"remote command was not newline-terminated: {cmd}: {out:?}"122		);123		out.pop();124	}125	String::from_utf8(out).context("expected utf8 output for command")126}127128async fn deploy_agent(sess: &Handle<SshHandler>, bundle: &AgentBundle) -> Result<Utf8PathBuf> {129	debug!("uname -a");130	let arch = run_string_ok(sess, "uname -m").await?;131	let hash = bundle132		.hashes133		.get(&arch)134		.ok_or_else(|| anyhow!("no remowt-agent build for remote arch {arch:?}"))?;135136	debug!("get dir");137	let cache = run_string_ok(sess, "echo \"$XDG_CACHE_HOME\"").await?;138	let dir = if cache.is_empty() {139		let home = run_string_ok(sess, "echo \"$HOME\"").await?;140		ensure!(141			!home.is_empty(),142			"remote $HOME and $XDG_CACHE_HOME both empty"143		);144		Utf8PathBuf::from(home).join(".cache/remowt")145	} else {146		Utf8PathBuf::from(cache).join("remowt")147	};148	let path = dir.join(hash);149150	debug!("presence");151	let (present, _) = run(sess, &format!("test -x {}", sh_quote(&path))).await?;152	if present != Some(0) {153		let bin = bundle.binary(&arch);154		debug!("read");155		let bytes = fs::read(&bin)156			.await157			.with_context(|| format!("reading agent binary {}", bin.display()))?;158		debug!("upload");159		upload_agent(sess, &dir, &path, bytes).await?;160	}161	Ok(path)162}163164async fn upload_agent(165	sess: &Handle<SshHandler>,166	dir: &Utf8Path,167	path: &Utf8Path,168	bytes: Vec<u8>,169) -> Result<()> {170	debug!("mkdirp");171	run_string_ok(sess, &format!("mkdir -p {}", sh_quote(dir))).await?;172173	let tmp = dir.join(format!("tmp.{}", Uuid::new_v4()));174	let ch = sess.channel_open_session().await?;175	debug!("cat");176	ch.exec(true, format!("cat > {}", sh_quote(&tmp))).await?;177178	let mut child = SshExecChild::from_exec(ch);179	child180		.stdin181		.write_all(&bytes)182		.await183		.context("sending agent binary")?;184	child185		.stdin186		.shutdown()187		.await188		.context("sending agent binary")?;189	let code = child.wait().await;190	ensure!(code == Some(0), "agent upload failed (exit {code:?})");191192	debug!("chmod");193	run_string_ok(sess, &format!("chmod 0755 {}", sh_quote(&tmp))).await?;194	run_string_ok(195		sess,196		&format!("mv -f {} {}", sh_quote(&tmp), sh_quote(path)),197	)198	.await?;199	Ok(())200}201202pub struct SshHandler {203	host: String,204	port: u16,205	subs: Subs,206}207impl Handler for SshHandler {208	type Error = russh::Error;209	async fn check_server_key(210		&mut self,211		server_public_key: &PublicKey,212	) -> Result<bool, Self::Error> {213		Ok(check_known_hosts(&self.host, self.port, server_public_key)?)214	}215	async fn server_channel_open_forwarded_streamlocal(216		&mut self,217		channel: Channel<Msg>,218		socket_path: &str,219		_session: &mut Session,220	) -> Result<(), Self::Error> {221		let Some(ch) = self222			.subs223			.lock()224			.expect("lock")225			.remove(&Utf8PathBuf::from(socket_path))226		else {227			return Err(russh::Error::WrongChannel);228		};229		let _ = ch.send(channel);230		Ok(())231	}232}233234enum Transport {235	Ssh {236		sess: Arc<Handle<SshHandler>>,237		subs: Subs,238		runtime_dir: Utf8PathBuf,239		agent_path: Utf8PathBuf,240	},241	Local {242		agent_path: PathBuf,243		runtime_dir: Utf8PathBuf,244	},245}246247struct RemowtInner {248	transport: Transport,249	rpc: Rpc<BifConfig>,250	elevated: tokio::sync::OnceCell<()>,251	#[allow(dead_code)]252	children: Mutex<Vec<tokio::process::Child>>,253	_runtime_tmp: Option<TempDir>,254	user: String,255	iroh: IrohState,256}257258#[derive(Default)]259struct IrohState {260	conn: tokio::sync::OnceCell<iroh::endpoint::Connection>,261	#[allow(dead_code)]262	endpoint: Mutex<Option<iroh::Endpoint>>,263	subs: Arc<Mutex<HashMap<u64, oneshot::Sender<RemowtStream>>>>,264	next_token: AtomicU64,265	router: Mutex<Option<Arc<DatagramRouter>>>,266}267268#[derive(Clone)]269pub struct Remowt(Arc<RemowtInner>);270271pub type RemowtRemote = Remote<BifConfig>;272273impl Remowt {274	/// Connect to the remote host over ssh, detect the architecture and deploy the required275	/// agent binary.276	pub async fn connect(host: &str, bundle: &AgentBundle, remowt_user: String) -> Result<Self> {277		let conf = russh_config::parse_home(host)?;278		let port = conf.host_config.port.or(conf.port).unwrap_or(22);279		let hostname = conf280			.host_config281			.hostname282			.clone()283			.unwrap_or_else(|| conf.host_name.clone());284		let user = conf285			.user286			.clone()287			.unwrap_or_else(|| env::var("USER").unwrap_or_else(|_| "root".to_owned()));288289		let subs: Subs = Arc::new(Mutex::new(HashMap::new()));290		let mut sess = connect(291			Arc::new(Config::default()),292			(hostname.clone(), port),293			SshHandler {294				host: hostname,295				port,296				subs: subs.clone(),297			},298		)299		.await?;300301		let mut agent = AgentClient::connect_env().await?;302		let rsa_hash = sess.best_supported_rsa_hash().await?.flatten();303		let mut authenticated = false;304		for ident in agent.request_identities().await? {305			let AgentIdentity::PublicKey { key, .. } = ident else {306				continue;307			};308			if sess309				.authenticate_publickey_with(user.clone(), key, rsa_hash, &mut agent)310				.await?311				.success()312			{313				authenticated = true;314				break;315			}316		}317		ensure!(authenticated, "ssh authentication failed");318319		let sess = Arc::new(sess);320321		debug!("deploying agent");322		let agent_path = deploy_agent(&sess, bundle).await?;323324		debug!("runtime dir");325		let runtime_dir = remote_runtime_dir(&sess).await?;326327		let rpc = Rpc::<BifConfig>::new(Address::User);328329		let cmd_chan = sess.channel_open_session().await?;330		debug!("starting agent");331		cmd_chan332			.exec(true, format!("{} real-agent", sh_quote(&agent_path)))333			.await?;334335		let child = SshExecChild::from_exec(cmd_chan);336		drain_to_tracing(child.stderr, "agent".to_owned(), true);337		rpc.add_direct(338			Address::Agent,339			child_port(child.stdout, child.stdin),340			Rtt(0),341		);342343		let remowt = Self(Arc::new(RemowtInner {344			transport: Transport::Ssh {345				sess,346				subs,347				runtime_dir,348				agent_path,349			},350			rpc,351			elevated: tokio::sync::OnceCell::new(),352			children: Mutex::new(Vec::new()),353			_runtime_tmp: None,354			user: remowt_user,355			iroh: IrohState::default(),356		}));357		remowt.setup_iroh().await;358		Ok(remowt)359	}360361	/// "Connect" to the local machine's agent, by starting the agent binary locally.362	pub async fn connect_local(bundle: &AgentBundle, user: String) -> Result<Self> {363		let agent_path = bundle.local_binary()?;364		let mut child = tokio::process::Command::new(&agent_path)365			.arg("real-agent")366			.arg("--local")367			.stdin(std::process::Stdio::piped())368			.stdout(std::process::Stdio::piped())369			.kill_on_drop(true)370			.spawn()371			.with_context(|| format!("spawning agent binary {}", agent_path.display()))?;372		let stdin = child.stdin.take().expect("stdin piped");373		let stdout = child.stdout.take().expect("stdout piped");374375		let rpc = Rpc::<BifConfig>::new(Address::User);376		rpc.add_direct(Address::Agent, child_port(stdout, stdin), Rtt(0));377378		let (runtime_dir, runtime_tmp) = local_runtime_dir()?;379380		Ok(Self(Arc::new(RemowtInner {381			transport: Transport::Local {382				agent_path,383				runtime_dir,384			},385			rpc,386			elevated: tokio::sync::OnceCell::new(),387			children: Mutex::new(vec![child]),388			_runtime_tmp: runtime_tmp,389			user,390			iroh: IrohState::default(),391		})))392	}393394	/// Get the handle to the underlying russh session handle.395	pub fn ssh(&self) -> Option<Arc<Handle<SshHandler>>> {396		match &self.0.transport {397			Transport::Ssh { sess, .. } => Some(sess.clone()),398			Transport::Local { .. } => None,399		}400	}401402	pub fn rpc(&self) -> Rpc<BifConfig> {403		self.0.rpc.clone()404	}405406	pub async fn load_plugin(&self, id: u16, name: &str) -> Result<()> {407		let client: PluginEndpointsClient<BifConfig> = self.endpoints();408		client409			.load_plugin(id, name.to_owned())410			.await?411			.map_err(|e| anyhow!("agent failed to load plugin: {e}"))412	}413	pub async fn run0_load_plugin_path(&self, id: u16, path: &str) -> Result<()> {414		self.ensure_escalated().await?;415		let client: PluginEndpointsClient<BifConfig> =416			PluginEndpointsClient::wrap(self.0.rpc.remote(Address::AgentPrivileged));417		client418			.load_plugin_path(id, path.to_owned())419			.await?420			.map_err(|e| anyhow!("privileged agent failed to load plugin: {e}"))421	}422	pub fn plugin_endpoints<R: RemoteEndpoints<BifConfig>>(&self, id: u16) -> R {423		R::wrap(self.0.rpc.remote(Address::Plugin(id)))424	}425426	pub fn endpoints<R: RemoteEndpoints<BifConfig>>(&self) -> R {427		R::wrap(self.0.rpc.remote(Address::Agent))428	}429	pub async fn run0_endpoints<R: RemoteEndpoints<BifConfig>>(&self) -> Result<R> {430		self.ensure_escalated().await?;431		Ok(R::wrap(self.0.rpc.remote(Address::AgentPrivileged)))432	}433434	async fn ensure_escalated(&self) -> Result<()> {435		self.0436			.elevated437			.get_or_try_init(|| async {438				let (agent_path, local) = match &self.0.transport {439					Transport::Ssh { agent_path, .. } => (agent_path.as_str().to_owned(), false),440					Transport::Local { agent_path, .. } => (441						agent_path442							.to_str()443							.ok_or_else(|| anyhow!("local agent path is not utf-8"))?444							.to_owned(),445						true,446					),447				};448449				let (tool, flags) = self.detect_escalation().await?;450				let mut args: Vec<String> = Vec::new();451				args.push("-w".to_owned());452				args.push(tool.to_owned());453				args.extend(flags.iter().copied().map(str::to_owned));454				if tool == "run0" {455					args.push(format!(456						"--unit={}-{}.service",457						self.0.user,458						Uuid::new_v4().simple()459					));460				}461				args.push(agent_path);462				args.push("real-agent".to_owned());463				args.push("--privileged".to_owned());464				if local {465					args.push("--local".to_owned());466				}467468				let child = self469					.spawn(SpawnOptions {470						program: "setsid".to_owned(),471						args,472						stdin: StdioMode::Pipe,473						stdout: StdioMode::Pipe,474						stderr: StderrMode::Inherit,475						..Default::default()476					})477					.await478					.context("spawning privileged agent")?;479480				let stdin = child481					.stdin482					.ok_or_else(|| anyhow!("privileged agent stdin missing"))?;483				let stdout = child484					.stdout485					.ok_or_else(|| anyhow!("privileged agent stdout missing"))?;486487				let port = child_port(stdout, stdin);488				self.0489					.rpc490					.add_direct(Address::AgentPrivileged, port, Rtt(0));491				anyhow::Ok(())492			})493			.await?;494		Ok(())495	}496497	async fn detect_escalation(&self) -> Result<(&'static str, &'static [&'static str])> {498		for (tool, flags) in ESCALATORS {499			let probe = self500				.spawn(SpawnOptions {501					program: (*tool).to_owned(),502					args: vec!["--version".to_owned()],503					stdout: StdioMode::Null,504					stderr: StderrMode::Null,505					..Default::default()506				})507				.await;508			if let Ok(child) = probe {509				let _ = child.wait().await;510				return Ok((tool, flags));511			}512		}513		bail!("no escalation tool found")514	}515516	/// XDG_RUNTIME_DIR on the remote machine.517	pub fn runtime_dir(&self) -> Utf8PathBuf {518		match &self.0.transport {519			Transport::Ssh { runtime_dir, .. } => runtime_dir.clone(),520			Transport::Local { runtime_dir, .. } => runtime_dir.clone(),521		}522	}523524	/// Bind unix listener socket on the remote machine with auto-generated path, returning the path.525	pub async fn bind_runtime_unix(&self, hint: &str) -> Result<(RemowtListener, Utf8PathBuf)> {526		let sock = self527			.runtime_dir()528			.join(format!("remowt-{hint}-{}.sock", Uuid::new_v4()));529		let listener = self.bind_unix(&sock).await?;530		Ok((listener, sock))531	}532533	/// Bind unix listener socket on the remote machine on the specified path.534	pub async fn bind_unix(&self, path: &Utf8Path) -> Result<RemowtListener> {535		match &self.0.transport {536			Transport::Ssh { sess, subs, .. } => {537				let (tx, rx) = oneshot::channel();538				subs.lock().expect("lock").insert(path.to_owned(), tx);539				sess.streamlocal_forward(path.to_owned()).await?;540				Ok(RemowtListener::Ssh(rx))541			}542			Transport::Local { .. } => {543				let _ = std::fs::remove_file(path);544				Ok(RemowtListener::Local(545					UnixListener::bind(path)?,546					path.to_owned(),547				))548			}549		}550	}551552	/// Bind a data tunnel, preferring the iroh fast path when it is up. Escalated tunnels553	/// (the privileged agent, a separate process with no iroh connection of its own) and the554	/// local transport always use the ssh/unix path.555	pub async fn bind_fast_tunnel(556		&self,557		hint: &str,558		escalated: bool,559	) -> Result<(RemowtListener, TunnelAddr)> {560		if !escalated && self.0.iroh.conn.get().is_some() {561			let token = self562				.0563				.iroh564				.next_token565				.fetch_add(1, std::sync::atomic::Ordering::Relaxed);566			let (tx, rx) = oneshot::channel();567			self.0.iroh.subs.lock().expect("lock").insert(token, tx);568			return Ok((RemowtListener::Iroh(rx), TunnelAddr::Iroh { token }));569		}570		let (listener, path) = self.bind_runtime_unix(hint).await?;571		Ok((listener, TunnelAddr::Unix(path)))572	}573574	async fn setup_iroh(&self) {575		if std::env::var_os("REMOWT_NO_IROH").is_some() {576			debug!("REMOWT_NO_IROH set, skipping iroh fast tunnel");577			return;578		}579		if !matches!(self.0.transport, Transport::Ssh { .. }) {580			return;581		}582		if let Err(e) = self.try_setup_iroh().await {583			warn!("iroh fast tunnel unavailable, using ssh: {e}");584		}585	}586587	async fn try_setup_iroh(&self) -> Result<()> {588		use remowt_endpoints::iroh_tunnel::IrohTunnelClient;589		use remowt_link_shared::iroh_tunnel::{build_endpoint, ssh_custom_addr, REMOWT_ALPN};590591		let (listener, sock) = self.bind_runtime_unix("iroh-xport").await?;592		let secret = iroh::SecretKey::generate();593		let client_id = secret.public();594595		let client: IrohTunnelClient<BifConfig> =596			IrohTunnelClient::wrap(self.0.rpc.remote(Address::Agent));597		let (accepted, agent_id) = tokio::join!(listener.accept(), client.setup(client_id, sock));598		let stream = accepted?;599		let agent_id = agent_id?.map_err(|e| anyhow!("agent iroh setup failed: {e}"))?;600601		let ep = build_endpoint(secret, stream, agent_id, false).await?;602		let addr = iroh::EndpointAddr::from_parts(603			agent_id,604			[iroh::TransportAddr::Custom(ssh_custom_addr(agent_id))],605		);606		let conn = ep.connect(addr, REMOWT_ALPN).await?;607		ensure!(conn.remote_id() == agent_id, "iroh peer identity mismatch");608		info!("iroh fast tunnel established");609610		let subs = self.0.iroh.subs.clone();611		let accept_conn = conn.clone();612		tokio::spawn(async move {613			loop {614				match accept_conn.accept_bi().await {615					Ok((send, mut recv)) => {616						let subs = subs.clone();617						tokio::spawn(async move {618							let mut buf = [0u8; 8];619							if tokio::io::AsyncReadExt::read_exact(&mut recv, &mut buf)620								.await621								.is_err()622							{623								return;624							}625							let token = u64::from_be_bytes(buf);626							let tx = subs.lock().expect("lock").remove(&token);627							if let Some(tx) = tx {628								let _ = tx.send(RemowtStream::Iroh(IrohBiStream::new(send, recv)));629							}630						});631					}632					Err(e) => {633						debug!("iroh accept loop ended: {e}");634						break;635					}636				}637			}638		});639640		let log_conn = conn.clone();641		tokio::spawn(async move {642			tokio::time::sleep(std::time::Duration::from_secs(2)).await;643			for p in log_conn.paths().iter() {644				if p.is_selected() {645					info!(rtt = ?p.rtt(), "iroh selected path: {}", p.remote_addr());646				}647			}648		});649650		*self.0.iroh.router.lock().expect("lock") = Some(DatagramRouter::spawn(conn.clone()));651		*self.0.iroh.endpoint.lock().expect("lock") = Some(ep);652		let _ = self.0.iroh.conn.set(conn);653		Ok(())654	}655656	pub fn datagram_router(&self) -> Option<Arc<DatagramRouter>> {657		self.0.iroh.router.lock().expect("lock").clone()658	}659}660661pub(crate) fn drain_to_tracing(662	stream: impl AsyncRead + Unpin + 'static + Send,663	context: String,664	stderr: bool,665) -> JoinHandle<()> {666	tokio::spawn(async move {667		let mut reader = BufReader::new(stream);668		let mut buf = Vec::with_capacity(4096);669		loop {670			buf.clear();671			match reader.read_until(b'\n', &mut buf).await {672				Ok(0) => break,673				Ok(_) => {674					let line = String::from_utf8_lossy(buf.strip_suffix(b"\n").unwrap_or(&buf));675					if stderr {676						warn!(context = %context, "{line}");677					} else {678						info!(context = %context, "{line}");679					}680				}681				Err(e) => {682					warn!(context = %context, "child stdio read failed: {e}");683					break;684				}685			}686		}687	})688}689690fn local_runtime_dir() -> Result<(Utf8PathBuf, Option<TempDir>)> {691	if let Ok(dir) = env::var("XDG_RUNTIME_DIR") {692		if !dir.is_empty() {693			return Ok((Utf8PathBuf::from(dir), None));694		}695	}696	let tmp = tempfile::Builder::new()697		.prefix("remowt.")698		.rand_bytes(12)699		.tempdir()?;700	let dir = Utf8PathBuf::from_path_buf(tmp.path().to_owned())701		.map_err(|p| anyhow!("temp dir {} is not utf-8", p.display()))?;702	Ok((dir, Some(tmp)))703}704705async fn remote_runtime_dir(sess: &Handle<SshHandler>) -> Result<Utf8PathBuf> {706	let dir = run_string_ok(sess, "echo \"$XDG_RUNTIME_DIR\"").await?;707	let dir = dir.trim();708	if dir.is_empty() {709		let tmp = run_string_ok(sess, "mktemp -d remowt.XXXXXXXXXXXX --tmpdir").await?;710		Ok(Utf8PathBuf::from(tmp))711	} else {712		Ok(Utf8PathBuf::from(dir))713	}714}
modifiedremowt/crates/remowt-endpoints/Cargo.tomldiffbeforeafterboth
--- a/remowt/crates/remowt-endpoints/Cargo.toml
+++ b/remowt/crates/remowt-endpoints/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-endpoints"
 description = "Nix daemon proxy"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/crates/remowt-endpoints/src/forward.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-endpoints/src/forward.rs
+++ b/remowt/crates/remowt-endpoints/src/forward.rs
@@ -3,12 +3,12 @@
 use std::sync::atomic::{AtomicU64, Ordering};
 use std::sync::{Arc, Mutex};
 
+use bifrostlink::Config;
 use bifrostlink::declarative::endpoints;
-use bifrostlink::Config;
 use remowt_link_shared::iroh_tunnel::{TunnelAddr, TunnelDialer};
 use serde::{Deserialize, Serialize};
 use std::result::Result;
-use tokio::net::{TcpStream, UdpSocket};
+use tokio::net::{TcpStream, UdpSocket, UnixStream};
 use tracing::warn;
 
 #[derive(Serialize, Deserialize, Debug, thiserror::Error)]
@@ -107,6 +107,24 @@
 
 		Ok(session)
 	}
+
+	#[endpoints(id = 3)]
+	async fn connect_unix(&self, tunnel: TunnelAddr, path: String) -> Result<(), Error> {
+		let stream = self
+			.dialer
+			.connect_tunnel(&tunnel)
+			.await
+			.map_err(|e| Error::Tunnel(e.to_string()))?;
+		let unix = UnixStream::connect(&path)
+			.await
+			.map_err(|e| Error::Connect(path, e.to_string()))?;
+		tokio::spawn(async move {
+			let mut stream = stream;
+			let mut unix = unix;
+			let _ = tokio::io::copy_bidirectional(&mut stream, &mut unix).await;
+		});
+		Ok(())
+	}
 }
 
 fn unspecified_for(target: &SocketAddr) -> SocketAddr {
modifiedremowt/crates/remowt-link-shared/Cargo.tomldiffbeforeafterboth
--- a/remowt/crates/remowt-link-shared/Cargo.toml
+++ b/remowt/crates/remowt-link-shared/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-link-shared"
 description = "Shared bifrostlink endpoint wiring for remowt"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
@@ -13,13 +13,13 @@
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
 thiserror.workspace = true
-tokio = { workspace = true, features = ["fs", "io-util", "macros", "net", "sync", "rt"] }
+tokio = { workspace = true, features = ["fs", "io-util", "macros", "net", "rt", "sync"] }
 tokio-util = { workspace = true, features = ["codec"] }
 tracing.workspace = true
-remowt-ui-prompt.workspace = true
+uuid = { workspace = true, features = ["v4"] }
 
+futures.workspace = true
 iroh.workspace = true
 iroh-base.workspace = true
-noq-udp.workspace = true
 n0-watcher.workspace = true
-futures.workspace = true
+noq-udp.workspace = true
modifiedremowt/crates/remowt-link-shared/src/lib.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-link-shared/src/lib.rs
+++ b/remowt/crates/remowt-link-shared/src/lib.rs
@@ -7,6 +7,7 @@
 use serde::{Deserialize, Serialize};
 
 pub mod editor;
+pub mod gateway;
 pub mod iroh_tunnel;
 pub mod port;
 
@@ -16,6 +17,7 @@
 	Agent,
 	AgentPrivileged,
 	Plugin(u16),
+	Ephemeral(uuid::Uuid),
 }
 impl AddressT for Address {}
 
@@ -27,9 +29,6 @@
 	ListenerDead,
 	#[error("response: {0}")]
 	Response(String),
-
-	#[error(transparent)]
-	Ui(#[from] remowt_ui_prompt::Error),
 }
 
 impl From<ListenerForYourRequestHasBeenDeadError> for Error {
@@ -38,8 +37,8 @@
 	}
 }
 impl From<serde_json::Error> for Error {
-	fn from(_value: serde_json::Error) -> Self {
-		Self::ListenerDead
+	fn from(e: serde_json::Error) -> Self {
+		Self::Response(format!("{e}"))
 	}
 }
 impl From<Error> for ResponseError {
modifiedremowt/crates/remowt-link-shared/src/plugin.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-link-shared/src/plugin.rs
+++ b/remowt/crates/remowt-link-shared/src/plugin.rs
@@ -10,6 +10,8 @@
 	BadName,
 	#[error("spawning plugin failed: {0}")]
 	Spawn(String),
+	#[error("failed to wait for connection, plugin process has died?")]
+	ConnectionWaitError,
 	#[error("agent is shutting down")]
 	Gone,
 }
modifiedremowt/crates/remowt-plugin/Cargo.tomldiffbeforeafterboth
--- a/remowt/crates/remowt-plugin/Cargo.toml
+++ b/remowt/crates/remowt-plugin/Cargo.toml
@@ -2,7 +2,7 @@
 name = "remowt-plugin"
 description = "Plugin host and protocol for remowt agents"
 version.workspace = true
-edition = "2021"
+edition.workspace = true
 license.workspace = true
 
 [dependencies]
modifiedremowt/crates/remowt-plugin/src/host.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-plugin/src/host.rs
+++ b/remowt/crates/remowt-plugin/src/host.rs
@@ -8,6 +8,7 @@
 use remowt_link_shared::plugin::{Error, PluginEndpoints, PluginHost};
 use remowt_link_shared::port::child_port;
 use remowt_link_shared::{Address, BifConfig};
+use tokio::select;
 
 pub fn serve(rpc: &mut Rpc<BifConfig>) {
 	let host = Host {
@@ -25,7 +26,7 @@
 }
 
 impl Host {
-	fn spawn(&self, id: u16, path: impl AsRef<OsStr>) -> Result<(), Error> {
+	async fn spawn(&self, id: u16, path: impl AsRef<OsStr>) -> Result<(), Error> {
 		let rpc = self.rpc.clone().upgrade().ok_or(Error::Gone)?;
 
 		let mut child = Command::new(path)
@@ -40,8 +41,20 @@
 		let stdout = child.stdout.take().expect("stdout piped");
 
 		let addr = Address::Plugin(id);
-		rpc.add_direct(addr, child_port(stdout, stdin), Rtt(0));
+		rpc.add_direct(addr.clone(), child_port(stdout, stdin), Rtt(0));
+
+		select! {
+			e = rpc.wait_for_connection_to(addr) => {
+				if e.is_err() {
+					return Err(Error::ConnectionWaitError)
+				}
+			},
+			_ = child.wait() => {
+				return Err(Error::ConnectionWaitError)
+			}
+		};
 		self.children.lock().expect("not poisoned").push(child);
+
 		Ok(())
 	}
 }
@@ -58,13 +71,13 @@
 		let dir = exe
 			.parent()
 			.ok_or_else(|| Error::Spawn("primary agent has no parent directory".to_owned()))?;
-		self.spawn(id, dir.join(&name))
+		self.spawn(id, dir.join(&name)).await
 	}
 
 	async fn load_plugin_path(&self, id: u16, path: String) -> Result<(), Error> {
 		if path.is_empty() || path.contains('\0') {
 			return Err(Error::BadName);
 		}
-		self.spawn(id, path)
+		self.spawn(id, path).await
 	}
 }
modifiedremowt/crates/remowt-ui-prompt/src/bifrost.rsdiffbeforeafterboth
--- a/remowt/crates/remowt-ui-prompt/src/bifrost.rs
+++ b/remowt/crates/remowt-ui-prompt/src/bifrost.rs
@@ -103,7 +103,6 @@
 where
 	P: Prompter + Send + Sync + 'static,
 	C: Config,
-	C::Error: From<Error>,
 {
 	PromptEndpoints(prompt).register_endpoints(rpc);
 }
modifiedrust-toolchain.tomldiffbeforeafterboth
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,3 +1,8 @@
 [toolchain]
 channel = "stable"
 components = ["rustfmt", "clippy", "rust-analyzer", "rust-src"]
+targets = [
+	"x86_64-unknown-linux-musl",
+	"aarch64-unknown-linux-musl",
+	"armv7-unknown-linux-musleabihf",
+]