ALPHA: wire is a tool to deploy nixos systems wire.althaea.zone/
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

stop drilling clobber_lock

+54 -105
-2
wire/cli/src/apply.rs
··· 53 53 location: HiveLocation, 54 54 args: ApplyArgs, 55 55 mut modifiers: SubCommandModifiers, 56 - clobber_lock: Arc<Mutex<()>>, 57 56 ) -> Result<()> { 58 57 let header_span = Span::current(); 59 58 let location = Arc::new(location); ··· 108 107 hive_location: location.clone(), 109 108 modifiers, 110 109 reboot: args.reboot, 111 - clobber_lock: clobber_lock.clone(), 112 110 should_apply_locally, 113 111 }; 114 112
+5 -5
wire/cli/src/main.rs
··· 13 13 use clap::CommandFactory; 14 14 use clap::Parser; 15 15 use clap_complete::generate; 16 + use lib::STDIN_CLOBBER_LOCK; 16 17 use lib::hive::Hive; 17 18 use lib::hive::get_hive_location; 18 19 use miette::IntoDiagnostic; ··· 35 36 async fn main() -> Result<()> { 36 37 #[cfg(feature = "dhat-heap")] 37 38 let _profiler = dhat::Profiler::new_heap(); 38 - let clobber_lock = Arc::new(Mutex::new(())); 39 39 40 40 let args = Cli::parse(); 41 41 42 42 let modifiers = args.to_subcommand_modifiers(); 43 - setup_logging(args.verbose, clobber_lock.clone()); 43 + setup_logging(args.verbose); 44 44 45 45 #[cfg(debug_assertions)] 46 46 if args.markdown_help { ··· 56 56 57 57 match args.command { 58 58 cli::Commands::Apply(apply_args) => { 59 - let mut hive = Hive::new_from_path(&location, modifiers, clobber_lock.clone()).await?; 60 - apply::apply(&mut hive, location, apply_args, modifiers, clobber_lock).await?; 59 + let mut hive = Hive::new_from_path(&location, modifiers).await?; 60 + apply::apply(&mut hive, location, apply_args, modifiers).await?; 61 61 } 62 62 cli::Commands::Inspect { online: _, json } => println!("{}", { 63 - let hive = Hive::new_from_path(&location, modifiers, clobber_lock).await?; 63 + let hive = Hive::new_from_path(&location, modifiers).await?; 64 64 if json { 65 65 serde_json::to_string(&hive).into_diagnostic()? 66 66 } else {
+5 -6
wire/cli/src/tracing_setup.rs
··· 8 8 }; 9 9 10 10 use clap_verbosity_flag::{Verbosity, WarnLevel}; 11 + use lib::STDIN_CLOBBER_LOCK; 11 12 use tracing_log::AsTrace; 12 13 use tracing_subscriber::{Layer, Registry, layer::SubscriberExt, util::SubscriberInitExt}; 13 14 14 15 struct NonClobberingWriter { 15 - clobber_lock: Arc<Mutex<()>>, 16 16 queue: VecDeque<Vec<u8>>, 17 17 stderr: Stderr, 18 18 } 19 19 20 20 impl NonClobberingWriter { 21 - fn new(clobber_lock: Arc<Mutex<()>>) -> Self { 21 + fn new() -> Self { 22 22 NonClobberingWriter { 23 - clobber_lock, 24 23 queue: VecDeque::with_capacity(100), 25 24 stderr: stderr(), 26 25 } ··· 39 38 40 39 impl Write for NonClobberingWriter { 41 40 fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { 42 - match self.clobber_lock.clone().try_lock() { 41 + match STDIN_CLOBBER_LOCK.clone().try_lock() { 43 42 Ok(_) => { 44 43 self.dump_previous().map(|()| 0)?; 45 44 ··· 63 62 } 64 63 } 65 64 66 - pub fn setup_logging(verbosity: Verbosity<WarnLevel>, clobber_lock: Arc<Mutex<()>>) { 65 + pub fn setup_logging(verbosity: Verbosity<WarnLevel>) { 67 66 let filter = verbosity.log_level_filter().as_trace(); 68 67 let registry = tracing_subscriber::registry(); 69 68 70 69 let layer = tracing_subscriber::fmt::layer::<Registry>() 71 70 .without_time() 72 71 .with_target(false) 73 - .with_writer(move || NonClobberingWriter::new(clobber_lock.clone())) 72 + .with_writer(move || NonClobberingWriter::new()) 74 73 .with_filter(filter); 75 74 76 75 registry.with(layer).init();
+2 -8
wire/lib/src/commands/common.rs
··· 31 31 ); 32 32 33 33 let child = run_command_with_env( 34 - &CommandArguments::new( 35 - command_string, 36 - context.modifiers, 37 - context.clobber_lock.clone(), 38 - ) 39 - .nix(), 34 + &CommandArguments::new(command_string, context.modifiers).nix(), 40 35 HashMap::from([( 41 36 "NIX_SSHOPTS".into(), 42 37 context ··· 65 60 location: &HiveLocation, 66 61 goal: &EvalGoal<'_>, 67 62 modifiers: SubCommandModifiers, 68 - clobber_lock: Arc<Mutex<()>>, 69 63 ) -> Result<String, HiveLibError> { 70 64 let attribute = match location { 71 65 HiveLocation::Flake(uri) => { ··· 100 94 }, 101 95 ); 102 96 103 - let child = run_command(&CommandArguments::new(command_string, modifiers, clobber_lock).nix())?; 97 + let child = run_command(&CommandArguments::new(command_string, modifiers).nix())?; 104 98 105 99 child 106 100 .wait_till_success()
+2 -2
wire/lib/src/commands/interactive.rs
··· 22 22 use tracing::instrument; 23 23 use tracing::{Span, debug, error, info, trace, warn}; 24 24 25 - use crate::SubCommandModifiers; 26 25 use crate::commands::CommandArguments; 27 26 use crate::commands::interactive_logbuffer::LogBuffer; 28 27 use crate::errors::CommandError; 28 + use crate::{STDIN_CLOBBER_LOCK, SubCommandModifiers}; 29 29 use crate::{ 30 30 commands::{ChildOutputMode, WireCommandChip}, 31 31 errors::HiveLibError, ··· 114 114 command.env(key, value); 115 115 } 116 116 117 - let clobber_guard = arguments.clobber_lock.lock().unwrap(); 117 + let clobber_guard = STDIN_CLOBBER_LOCK.lock().unwrap(); 118 118 let _guard = StdinTermiosAttrGuard::new().map_err(HiveLibError::CommandError)?; 119 119 let child = pty_pair 120 120 .slave
+1 -7
wire/lib/src/commands/mod.rs
··· 48 48 command_string: S, 49 49 keep_stdin_open: bool, 50 50 elevated: bool, 51 - clobber_lock: Arc<Mutex<()>>, 52 51 log_stdout: bool, 53 52 } 54 53 ··· 61 60 }); 62 61 63 62 impl<'a, S: AsRef<str>> CommandArguments<'a, S> { 64 - pub(crate) fn new( 65 - command_string: S, 66 - modifiers: SubCommandModifiers, 67 - clobber_lock: Arc<Mutex<()>>, 68 - ) -> Self { 63 + pub(crate) fn new(command_string: S, modifiers: SubCommandModifiers) -> Self { 69 64 Self { 70 65 command_string, 71 66 keep_stdin_open: false, ··· 74 69 target: None, 75 70 output_mode: ChildOutputMode::Raw, 76 71 modifiers, 77 - clobber_lock, 78 72 } 79 73 } 80 74
+13 -27
wire/lib/src/hive/mod.rs
··· 51 51 pub async fn new_from_path( 52 52 location: &HiveLocation, 53 53 modifiers: SubCommandModifiers, 54 - clobber_lock: Arc<Mutex<()>>, 55 54 ) -> Result<Hive, HiveLibError> { 56 55 info!("evaluating hive {location:?}"); 57 56 58 - let output = 59 - evaluate_hive_attribute(location, &EvalGoal::Inspect, modifiers, clobber_lock).await?; 57 + let output = evaluate_hive_attribute(location, &EvalGoal::Inspect, modifiers).await?; 60 58 61 59 let hive: Hive = serde_json::from_str(&output).map_err(|err| { 62 60 HiveLibError::HiveInitializationError(HiveInitializationError::ParseEvaluateError(err)) ··· 135 133 get_test_path, 136 134 hive::steps::keys::{Key, Source, UploadKeyAt}, 137 135 location, 138 - test_support::{get_clobber_lock, make_flake_sandbox}, 136 + test_support::make_flake_sandbox, 139 137 }; 140 138 141 139 use super::*; ··· 154 152 async fn test_hive_file() { 155 153 let location = location!(get_test_path!()); 156 154 157 - let hive = Hive::new_from_path( 158 - &location, 159 - SubCommandModifiers::default(), 160 - get_clobber_lock(), 161 - ) 162 - .await 163 - .unwrap(); 155 + let hive = Hive::new_from_path(&location, SubCommandModifiers::default()) 156 + .await 157 + .unwrap(); 164 158 165 159 let node = Node { 166 160 target: node::Target::from_host("192.168.122.96"), ··· 184 178 async fn non_trivial_hive() { 185 179 let location = location!(get_test_path!()); 186 180 187 - let hive = Hive::new_from_path( 188 - &location, 189 - SubCommandModifiers::default(), 190 - get_clobber_lock(), 191 - ) 192 - .await 193 - .unwrap(); 181 + let hive = Hive::new_from_path(&location, SubCommandModifiers::default()) 182 + .await 183 + .unwrap(); 194 184 195 185 let node = Node { 196 186 target: node::Target::from_host("name"), ··· 226 216 let tmp_dir = make_flake_sandbox(&get_test_path!()).unwrap(); 227 217 228 218 let location = get_hive_location(tmp_dir.path().display().to_string()).unwrap(); 229 - let hive = Hive::new_from_path( 230 - &location, 231 - SubCommandModifiers::default(), 232 - get_clobber_lock(), 233 - ) 234 - .await 235 - .unwrap(); 219 + let hive = Hive::new_from_path(&location, SubCommandModifiers::default()) 220 + .await 221 + .unwrap(); 236 222 237 223 let mut nodes = HashMap::new(); 238 224 ··· 257 243 let location = location!(get_test_path!()); 258 244 259 245 assert_matches!( 260 - Hive::new_from_path(&location, SubCommandModifiers::default(), get_clobber_lock()).await, 246 + Hive::new_from_path(&location, SubCommandModifiers::default()).await, 261 247 Err(HiveLibError::NixEvalError { 262 248 source: CommandError::CommandFailed { 263 249 logs, ··· 274 260 let location = location!(get_test_path!()); 275 261 276 262 assert_matches!( 277 - Hive::new_from_path(&location, SubCommandModifiers::default(), get_clobber_lock()).await, 263 + Hive::new_from_path(&location, SubCommandModifiers::default()).await, 278 264 Err(HiveLibError::NixEvalError { 279 265 source: CommandError::CommandFailed { 280 266 logs,
+11 -30
wire/lib/src/hive/node.rs
··· 139 139 name: &'a Name, 140 140 node: &'a mut Node, 141 141 ) -> Self { 142 - use crate::test_support::get_clobber_lock; 143 - 144 142 Context { 145 143 name, 146 144 node, ··· 151 149 goal: Goal::SwitchToConfiguration(SwitchToConfigurationGoal::Switch), 152 150 reboot: false, 153 151 should_apply_locally: false, 154 - clobber_lock: get_clobber_lock(), 155 152 } 156 153 } 157 154 } ··· 220 217 } 221 218 } 222 219 223 - pub async fn ping( 224 - &self, 225 - modifiers: SubCommandModifiers, 226 - clobber_lock: Arc<std::sync::Mutex<()>>, 227 - ) -> Result<(), HiveLibError> { 220 + pub async fn ping(&self, modifiers: SubCommandModifiers) -> Result<(), HiveLibError> { 228 221 let host = self.target.get_preferred_host()?; 229 222 230 223 let command_string = format!( ··· 233 226 self.target.user, host 234 227 ); 235 228 let output = run_command_with_env( 236 - &CommandArguments::new(command_string, modifiers, clobber_lock) 229 + &CommandArguments::new(command_string, modifiers) 237 230 .nix() 238 231 .log_stdout(), 239 232 HashMap::from([( ··· 313 306 pub goal: Goal, 314 307 pub reboot: bool, 315 308 pub should_apply_locally: bool, 316 - pub clobber_lock: Arc<std::sync::Mutex<()>>, 317 309 } 318 310 319 311 #[enum_dispatch(ExecuteStep)] ··· 383 375 hive_location: Arc<HiveLocation>, 384 376 name: Name, 385 377 modifiers: SubCommandModifiers, 386 - clobber_lock: Arc<std::sync::Mutex<()>>, 387 378 ) { 388 - let output = evaluate_hive_attribute( 389 - &hive_location, 390 - &EvalGoal::GetTopLevel(&name), 391 - modifiers, 392 - clobber_lock.clone(), 393 - ) 394 - .await 395 - .map(|output| { 396 - serde_json::from_str::<Derivation>(&output).expect("failed to parse derivation") 397 - }); 379 + let output = 380 + evaluate_hive_attribute(&hive_location, &EvalGoal::GetTopLevel(&name), modifiers) 381 + .await 382 + .map(|output| { 383 + serde_json::from_str::<Derivation>(&output).expect("failed to parse derivation") 384 + }); 398 385 399 386 debug!(output = ?output, done = true); 400 387 ··· 413 400 self.context.hive_location.clone(), 414 401 self.context.name.clone(), 415 402 self.context.modifiers, 416 - self.context.clobber_lock.clone(), 417 403 ) 418 404 .in_current_span(), 419 405 ); ··· 452 438 function_name, get_test_path, 453 439 hive::{Hive, get_hive_location}, 454 440 location, 455 - test_support::get_clobber_lock, 456 441 }; 457 442 use std::path::PathBuf; 458 443 use std::{collections::HashMap, env}; ··· 471 456 let mut path = get_test_path!(); 472 457 473 458 let location = get_hive_location(path.display().to_string()).unwrap(); 474 - let hive = Hive::new_from_path( 475 - &location, 476 - SubCommandModifiers::default(), 477 - get_clobber_lock(), 478 - ) 479 - .await 480 - .unwrap(); 459 + let hive = Hive::new_from_path(&location, SubCommandModifiers::default()) 460 + .await 461 + .unwrap(); 481 462 482 463 let node = Node::default(); 483 464
+5 -5
wire/lib/src/hive/steps/activate.rs
··· 23 23 24 24 pub async fn wait_for_ping(ctx: &Context<'_>) -> Result<(), HiveLibError> { 25 25 let host = ctx.node.target.get_preferred_host()?; 26 - let mut result = ctx.node.ping(ctx.modifiers, ctx.clobber_lock.clone()).await; 26 + let mut result = ctx.node.ping(ctx.modifiers).await; 27 27 28 28 for num in 0..2 { 29 29 warn!("Trying to ping {host} (attempt {}/3)", num + 1); 30 30 31 - result = ctx.node.ping(ctx.modifiers, ctx.clobber_lock.clone()).await; 31 + result = ctx.node.ping(ctx.modifiers).await; 32 32 33 33 if result.is_ok() { 34 34 info!("Regained connection to {} via {host}", ctx.name); ··· 50 50 let command_string = format!("nix-env -p /nix/var/nix/profiles/system/ --set {built_path}"); 51 51 52 52 let child = run_command( 53 - &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 53 + &CommandArguments::new(command_string, ctx.modifiers) 54 54 .nix() 55 55 .on_target(if ctx.should_apply_locally { 56 56 None ··· 105 105 ); 106 106 107 107 let child = run_command( 108 - &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 108 + &CommandArguments::new(command_string, ctx.modifiers) 109 109 .on_target(if ctx.should_apply_locally { 110 110 None 111 111 } else { ··· 132 132 warn!("Rebooting {name}!", name = ctx.name); 133 133 134 134 let reboot = run_command( 135 - &CommandArguments::new("reboot now", ctx.modifiers, ctx.clobber_lock.clone()) 135 + &CommandArguments::new("reboot now", ctx.modifiers) 136 136 .log_stdout() 137 137 .on_target(Some(&ctx.node.target)) 138 138 .elevated(),
+1 -1
wire/lib/src/hive/steps/build.rs
··· 35 35 ); 36 36 37 37 let status = run_command_with_env( 38 - &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 38 + &CommandArguments::new(command_string, ctx.modifiers) 39 39 .on_target(if ctx.node.build_remotely { 40 40 Some(&ctx.node.target) 41 41 } else {
+1 -1
wire/lib/src/hive/steps/keys.rs
··· 232 232 let command_string = format!("{agent_directory}/bin/key_agent"); 233 233 234 234 let mut child = run_command( 235 - &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 235 + &CommandArguments::new(command_string, ctx.modifiers) 236 236 .on_target(if ctx.should_apply_locally { 237 237 None 238 238 } else {
+1 -6
wire/lib/src/hive/steps/ping.rs
··· 33 33 host = ctx.node.target.get_preferred_host()?.to_string() 34 34 ); 35 35 36 - if ctx 37 - .node 38 - .ping(ctx.modifiers, ctx.clobber_lock.clone()) 39 - .await 40 - .is_ok() 41 - { 36 + if ctx.node.ping(ctx.modifiers).await.is_ok() { 42 37 event!( 43 38 Level::INFO, 44 39 status = "success",
+7 -1
wire/lib/src/lib.rs
··· 10 10 #![feature(assert_matches)] 11 11 #![feature(iter_intersperse)] 12 12 13 - use std::io::IsTerminal; 13 + use std::{ 14 + io::IsTerminal, 15 + sync::{Arc, LazyLock, Mutex}, 16 + }; 14 17 15 18 use crate::{errors::HiveLibError, hive::node::Name}; 16 19 ··· 46 49 Inspect, 47 50 GetTopLevel(&'a Name), 48 51 } 52 + 53 + pub static STDIN_CLOBBER_LOCK: LazyLock<Arc<Mutex<()>>> = 54 + LazyLock::new(|| Arc::new(Mutex::new(())));
-4
wire/lib/src/test_support.rs
··· 66 66 67 67 Ok(tmp_dir) 68 68 } 69 - 70 - pub fn get_clobber_lock() -> Arc<Mutex<()>> { 71 - Arc::new(Mutex::new(())) 72 - }