diff --git a/Cargo.lock b/Cargo.lock index 0e8f06b8f..b41c47094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6157,6 +6157,7 @@ dependencies = [ "termwiz", "uds_windows", "url", + "wezterm-client", "wezterm-term", "winapi", ] diff --git a/config/src/config.rs b/config/src/config.rs index 885f7416e..2a8685f9c 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -789,6 +789,9 @@ pub struct Config { #[dynamic(default)] pub default_domain: Option, + #[dynamic(default)] + pub default_mux_server_domain: Option, + #[dynamic(default)] pub default_workspace: Option, diff --git a/docs/changelog.md b/docs/changelog.md index 4a394ab27..1ab1cbac9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -58,6 +58,9 @@ As features stabilize some brief notes about them will accumulate here. * [exit_behavior_messaging](config/lua/config/exit_behavior_messaging.md) option to control output when holding a pane open after a process completes. #3423 +* [default_mux_server_domain](config/lua/config/default_mux_server_domain.md) for the + (almost!) equivalent to [default_domain](config/lua/config/default_domain.md) in + the context of the mux server. #### Fixed @@ -126,6 +129,9 @@ As features stabilize some brief notes about them will accumulate here. `exit_behavior="CloseOnCleanExit"` if the command fails to spawn, and a more detailed error message is shown explaining what failed. #3928 #3950 * macOS: middle mouse button dragging. Thanks to @JacobMalloy! #3908 +* Attempting to spawn a non-local domain via the mux server would fail with + invalid domain because none of the additional domains from your config were + registered with the mux server. #3907 #### Updated * Bundled harfbuzz to 8.0.0 diff --git a/docs/config/lua/config/default_domain.md b/docs/config/lua/config/default_domain.md index 53ef1e5fc..f7e150bf3 100644 --- a/docs/config/lua/config/default_domain.md +++ b/docs/config/lua/config/default_domain.md @@ -6,6 +6,10 @@ tags: {{since('20220319-142410-0fcdea07')}} +!!! note + This option only applies to the GUI. For the equivalent option in + the standalone mux server, see [default_mux_server_domain](default_mux_server_domain.md) + When starting the GUI (not using the `serial` or `connect` subcommands), by default wezterm will set the built-in `"local"` domain as the default multiplexing domain. The `"local"` domain represents processes that are spawned directly on the local system. diff --git a/docs/config/lua/config/default_mux_server_domain.md b/docs/config/lua/config/default_mux_server_domain.md new file mode 100644 index 000000000..0626b6eae --- /dev/null +++ b/docs/config/lua/config/default_mux_server_domain.md @@ -0,0 +1,25 @@ +--- +tags: + - multiplexing +--- +# `default_mux_server_domain = "local"` + +{{since('nightly')}} + +!!! note + This option only applies to the standalone mux server. For the equivalent option in + the GUI, see [default_domain](default_domain.md) + +When starting the mux server, by default wezterm will set the built-in +`"local"` domain as the default multiplexing domain. + +The `"local"` domain represents processes that are spawned directly on the +local system. + +This option allows you to change the default domain to some other domain, such +as an [ExecDomain](../ExecDomain.md). + +It is *not* possible to configure a client multiplexing domain such as a TLS, +SSH or Unix domain as the default for the multiplexer server. That is +prohibited in order to prevent recursion when a client connects to the server. + diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 011591816..fefea78ca 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -11,7 +11,6 @@ use config::keyassignment::{SpawnCommand, SpawnTabDomain}; use config::{ConfigHandle, SerialDomain, SshDomain, SshMultiplexing}; use mux::activity::Activity; use mux::domain::{Domain, LocalDomain}; -use mux::ssh::RemoteSshDomain; use mux::Mux; use mux_lua::MuxDomain; use portable_pty::cmdbuilder::CommandBuilder; @@ -27,9 +26,10 @@ use termwiz::cell::{CellAttributes, UnicodeVersion}; use termwiz::surface::{Line, SEQ_ZERO}; use unicode_normalization::UnicodeNormalization; use wezterm_bidi::Direction; -use wezterm_client::domain::{ClientDomain, ClientDomainConfig}; +use wezterm_client::domain::ClientDomain; use wezterm_font::shaper::PresentationWidth; use wezterm_gui_subcommands::*; +use wezterm_mux_server_impl::update_mux_domains; use wezterm_toast_notification::*; mod colorease; @@ -244,24 +244,6 @@ fn run_serial(config: config::ConfigHandle, opts: SerialCommand) -> anyhow::Resu gui.run_forever() } -fn client_domains(config: &config::ConfigHandle) -> Vec { - let mut domains = vec![]; - for unix_dom in &config.unix_domains { - domains.push(ClientDomainConfig::Unix(unix_dom.clone())); - } - - for ssh_dom in config.ssh_domains().into_iter() { - if ssh_dom.multiplexing == SshMultiplexing::WezTerm { - domains.push(ClientDomainConfig::Ssh(ssh_dom.clone())); - } - } - - for tls_client in &config.tls_clients { - domains.push(ClientDomainConfig::Tls(tls_client.clone())); - } - domains -} - fn have_panes_in_domain_and_ws(domain: &Arc, workspace: &Option) -> bool { let mux = Mux::get(); let have_panes_in_domain = mux @@ -348,67 +330,6 @@ async fn spawn_tab_in_domain_if_mux_is_empty( Ok(()) } -fn update_mux_domains(config: &ConfigHandle) -> anyhow::Result<()> { - let mux = Mux::get(); - - for client_config in client_domains(&config) { - if mux.get_domain_by_name(client_config.name()).is_some() { - continue; - } - - let domain: Arc = Arc::new(ClientDomain::new(client_config)); - mux.add_domain(&domain); - } - - for ssh_dom in config.ssh_domains().into_iter() { - if ssh_dom.multiplexing != SshMultiplexing::None { - continue; - } - - if mux.get_domain_by_name(&ssh_dom.name).is_some() { - continue; - } - - let domain: Arc = Arc::new(RemoteSshDomain::with_ssh_domain(&ssh_dom)?); - mux.add_domain(&domain); - } - - for wsl_dom in config.wsl_domains() { - if mux.get_domain_by_name(&wsl_dom.name).is_some() { - continue; - } - - let domain: Arc = Arc::new(LocalDomain::new_wsl(wsl_dom.clone())?); - mux.add_domain(&domain); - } - - for exec_dom in &config.exec_domains { - if mux.get_domain_by_name(&exec_dom.name).is_some() { - continue; - } - - let domain: Arc = Arc::new(LocalDomain::new_exec_domain(exec_dom.clone())?); - mux.add_domain(&domain); - } - - for serial in &config.serial_ports { - if mux.get_domain_by_name(&serial.name).is_some() { - continue; - } - - let domain: Arc = Arc::new(LocalDomain::new_serial_domain(serial.clone())?); - mux.add_domain(&domain); - } - - if let Some(name) = &config.default_domain { - if let Some(dom) = mux.get_domain_by_name(name) { - mux.set_default_domain(&dom); - } - } - - Ok(()) -} - async fn connect_to_auto_connect_domains() -> anyhow::Result<()> { let mux = Mux::get(); let domains = mux.iter_domains(); diff --git a/wezterm-mux-server-impl/Cargo.toml b/wezterm-mux-server-impl/Cargo.toml index ce74c02fb..4b6719505 100644 --- a/wezterm-mux-server-impl/Cargo.toml +++ b/wezterm-mux-server-impl/Cargo.toml @@ -22,6 +22,7 @@ rangeset = { path = "../rangeset" } rcgen = "0.9" smol = "1.2" url = "2" +wezterm-client = { path = "../wezterm-client" } wezterm-term = { path = "../term", features=["use_serde"] } termwiz = { path = "../termwiz", features=["use_serde"] } diff --git a/wezterm-mux-server-impl/src/lib.rs b/wezterm-mux-server-impl/src/lib.rs index 06b1ee29f..c36a87963 100644 --- a/wezterm-mux-server-impl/src/lib.rs +++ b/wezterm-mux-server-impl/src/lib.rs @@ -1,3 +1,10 @@ +use config::{ConfigHandle, SshMultiplexing}; +use mux::domain::{Domain, LocalDomain}; +use mux::ssh::RemoteSshDomain; +use mux::Mux; +use std::sync::Arc; +use wezterm_client::domain::{ClientDomain, ClientDomainConfig}; + #[cfg(unix)] use std::os::unix::net::{UnixListener, UnixStream}; #[cfg(windows)] @@ -8,6 +15,104 @@ pub mod local; pub mod pki; pub mod sessionhandler; +fn client_domains(config: &config::ConfigHandle) -> Vec { + let mut domains = vec![]; + for unix_dom in &config.unix_domains { + domains.push(ClientDomainConfig::Unix(unix_dom.clone())); + } + + for ssh_dom in config.ssh_domains().into_iter() { + if ssh_dom.multiplexing == SshMultiplexing::WezTerm { + domains.push(ClientDomainConfig::Ssh(ssh_dom.clone())); + } + } + + for tls_client in &config.tls_clients { + domains.push(ClientDomainConfig::Tls(tls_client.clone())); + } + domains +} + +pub fn update_mux_domains(config: &ConfigHandle) -> anyhow::Result<()> { + update_mux_domains_impl(config, false) +} + +pub fn update_mux_domains_for_server(config: &ConfigHandle) -> anyhow::Result<()> { + update_mux_domains_impl(config, true) +} + +fn update_mux_domains_impl(config: &ConfigHandle, is_standalone_mux: bool) -> anyhow::Result<()> { + let mux = Mux::get(); + + for client_config in client_domains(&config) { + if mux.get_domain_by_name(client_config.name()).is_some() { + continue; + } + + let domain: Arc = Arc::new(ClientDomain::new(client_config)); + mux.add_domain(&domain); + } + + for ssh_dom in config.ssh_domains().into_iter() { + if ssh_dom.multiplexing != SshMultiplexing::None { + continue; + } + + if mux.get_domain_by_name(&ssh_dom.name).is_some() { + continue; + } + + let domain: Arc = Arc::new(RemoteSshDomain::with_ssh_domain(&ssh_dom)?); + mux.add_domain(&domain); + } + + for wsl_dom in config.wsl_domains() { + if mux.get_domain_by_name(&wsl_dom.name).is_some() { + continue; + } + + let domain: Arc = Arc::new(LocalDomain::new_wsl(wsl_dom.clone())?); + mux.add_domain(&domain); + } + + for exec_dom in &config.exec_domains { + if mux.get_domain_by_name(&exec_dom.name).is_some() { + continue; + } + + let domain: Arc = Arc::new(LocalDomain::new_exec_domain(exec_dom.clone())?); + mux.add_domain(&domain); + } + + for serial in &config.serial_ports { + if mux.get_domain_by_name(&serial.name).is_some() { + continue; + } + + let domain: Arc = Arc::new(LocalDomain::new_serial_domain(serial.clone())?); + mux.add_domain(&domain); + } + + if is_standalone_mux { + if let Some(name) = &config.default_mux_server_domain { + if let Some(dom) = mux.get_domain_by_name(name) { + if dom.is::() { + anyhow::bail!("default_mux_server_domain cannot be set to a client domain!"); + } + mux.set_default_domain(&dom); + } + } + } else { + if let Some(name) = &config.default_domain { + if let Some(dom) = mux.get_domain_by_name(name) { + mux.set_default_domain(&dom); + } + } + } + + Ok(()) +} + lazy_static::lazy_static! { pub static ref PKI: pki::Pki = pki::Pki::init().expect("failed to initialize PKI"); } diff --git a/wezterm-mux-server/src/main.rs b/wezterm-mux-server/src/main.rs index b54667770..56dcfe9f2 100644 --- a/wezterm-mux-server/src/main.rs +++ b/wezterm-mux-server/src/main.rs @@ -10,6 +10,7 @@ use std::rc::Rc; use std::sync::Arc; use std::thread; use wezterm_gui_subcommands::*; +use wezterm_mux_server_impl::update_mux_domains_for_server; mod daemonize; @@ -256,6 +257,18 @@ async fn trigger_mux_startup(lua: Option>) -> anyhow::Result<()> { async fn async_run(cmd: Option) -> anyhow::Result<()> { let mux = Mux::get(); + let config = config::configuration(); + + update_mux_domains_for_server(&config)?; + let _config_subscription = config::subscribe_to_config_reload(move || { + promise::spawn::spawn_into_main_thread(async move { + if let Err(err) = update_mux_domains_for_server(&config::configuration()) { + log::error!("Error updating mux domains: {:#}", err); + } + }) + .detach(); + true + }); let domain = mux.default_domain(); @@ -276,7 +289,6 @@ async fn async_run(cmd: Option) -> anyhow::Result<()> { let window_id = mux.new_empty_window(workspace, position); domain.attach(Some(*window_id)).await?; - let config = config::configuration(); let _tab = mux .default_domain() .spawn(config.initial_size(0), cmd, None, *window_id)