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.

deduplicate should_apply_locally

+67 -85
+9 -6
wire/cli/src/apply.rs
··· 3 3 4 4 use futures::{FutureExt, StreamExt}; 5 5 use itertools::{Either, Itertools}; 6 - use lib::hive::node::{Context, GoalExecutor, Name, StepState}; 6 + use lib::hive::node::{Context, GoalExecutor, Name, StepState, should_apply_locally}; 7 7 use lib::hive::{Hive, HiveLocation}; 8 8 use lib::{SubCommandModifiers, errors::HiveLibError}; 9 9 use miette::{Diagnostic, IntoDiagnostic, Result}; ··· 94 94 || names.contains(name) 95 95 || node.tags.iter().any(|tag| tags.contains(tag)) 96 96 }) 97 - .map(|node| { 98 - info!("Resolved {:?} to include {}", args.on, node.0); 97 + .map(|(name, node)| { 98 + info!("Resolved {:?} to include {}", args.on, name); 99 + 100 + let should_apply_locally = should_apply_locally(node.allow_local_deployment, &name.0); 99 101 100 102 let context = Context { 101 - node: node.1, 102 - name: node.0, 103 + node, 104 + name, 103 105 goal: args.goal.clone().try_into().unwrap(), 104 106 state: StepState::default(), 105 107 no_keys: args.no_keys, ··· 107 109 modifiers, 108 110 reboot: args.reboot, 109 111 clobber_lock: clobber_lock.clone(), 112 + should_apply_locally, 110 113 }; 111 114 112 115 GoalExecutor::new(context) 113 116 .execute() 114 - .map(move |result| (node.0, result)) 117 + .map(move |result| (name, result)) 115 118 }) 116 119 .peekable(); 117 120
+20 -13
wire/lib/src/commands/common.rs
··· 14 14 errors::HiveLibError, 15 15 hive::{ 16 16 HiveLocation, 17 - node::{Name, Node, Push}, 17 + node::{Context, Push}, 18 18 }, 19 19 }; 20 20 21 - pub async fn push( 22 - node: &Node, 23 - name: &Name, 24 - push: Push<'_>, 25 - modifiers: SubCommandModifiers, 26 - clobber_lock: Arc<Mutex<()>>, 27 - ) -> Result<(), HiveLibError> { 21 + pub async fn push(context: &Context<'_>, push: Push<'_>) -> Result<(), HiveLibError> { 28 22 let command_string = format!( 29 23 "nix --extra-experimental-features nix-command \ 30 24 copy --substitute-on-destination --to ssh://{user}@{host} {path}", 31 - user = node.target.user, 32 - host = node.target.get_preferred_host()?, 25 + user = context.node.target.user, 26 + host = context.node.target.get_preferred_host()?, 33 27 path = match push { 34 28 Push::Derivation(drv) => format!("{drv} --derivation"), 35 29 Push::Path(path) => path.clone(), ··· 37 31 ); 38 32 39 33 let child = run_command_with_env( 40 - &CommandArguments::new(command_string, modifiers, clobber_lock).nix(), 34 + &CommandArguments::new( 35 + command_string, 36 + context.modifiers, 37 + context.clobber_lock.clone(), 38 + ) 39 + .nix(), 41 40 HashMap::from([( 42 41 "NIX_SSHOPTS".into(), 43 - node.target.create_ssh_opts(modifiers, false)?, 42 + context 43 + .node 44 + .target 45 + .create_ssh_opts(context.modifiers, false)?, 44 46 )]), 45 47 )?; 46 48 ··· 48 50 .wait_till_success() 49 51 .await 50 52 .map_err(|error| HiveLibError::NixCopyError { 51 - name: name.clone(), 53 + name: context.name.clone(), 52 54 path: push.to_string(), 53 55 error: Box::new(error), 56 + help: if context.should_apply_locally { 57 + Some(format!("Remote push failed, but this node matches our local hostname ({0}). Perhaps you want to apply this node locally? Use `--always-build-local {0}` to override deployment.buildOnTarget", {context.name.to_string()})) 58 + } else { 59 + None 60 + } 54 61 })?; 55 62 56 63 Ok(())
+2
wire/lib/src/errors.rs
··· 315 315 path: String, 316 316 #[source] 317 317 error: Box<CommandError>, 318 + #[help] 319 + help: Option<String>, 318 320 }, 319 321 320 322 #[diagnostic(code(wire::Evaluate))]
+2
wire/lib/src/hive/node.rs
··· 150 150 state: StepState::default(), 151 151 goal: Goal::SwitchToConfiguration(SwitchToConfigurationGoal::Switch), 152 152 reboot: false, 153 + should_apply_locally: false, 153 154 clobber_lock: get_clobber_lock(), 154 155 } 155 156 } ··· 311 312 pub state: StepState, 312 313 pub goal: Goal, 313 314 pub reboot: bool, 315 + pub should_apply_locally: bool, 314 316 pub clobber_lock: Arc<std::sync::Mutex<()>>, 315 317 } 316 318
+13 -18
wire/lib/src/hive/steps/activate.rs
··· 9 9 HiveLibError, 10 10 commands::{CommandArguments, WireCommandChip, run_command}, 11 11 errors::{ActivationError, NetworkError}, 12 - hive::node::{Context, ExecuteStep, Goal, SwitchToConfigurationGoal, should_apply_locally}, 12 + hive::node::{Context, ExecuteStep, Goal, SwitchToConfigurationGoal}, 13 13 }; 14 14 15 15 #[derive(Debug, PartialEq)] ··· 52 52 let child = run_command( 53 53 &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 54 54 .nix() 55 - .on_target( 56 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) { 57 - None 58 - } else { 59 - Some(&ctx.node.target) 60 - }, 61 - ) 55 + .on_target(if ctx.should_apply_locally { 56 + None 57 + } else { 58 + Some(&ctx.node.target) 59 + }) 62 60 .elevated(), 63 61 )?; 64 62 ··· 108 106 109 107 let child = run_command( 110 108 &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 111 - .on_target( 112 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) 113 - { 114 - None 115 - } else { 116 - Some(&ctx.node.target) 117 - }, 118 - ) 109 + .on_target(if ctx.should_apply_locally { 110 + None 111 + } else { 112 + Some(&ctx.node.target) 113 + }) 119 114 .elevated() 120 115 .log_stdout(), 121 116 )?; ··· 128 123 return Ok(()); 129 124 } 130 125 131 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) { 126 + if ctx.should_apply_locally { 132 127 error!("Refusing to reboot local machine!"); 133 128 134 129 return Ok(()); ··· 177 172 // Bail if the command couldn't of broken the system 178 173 // and don't try to regain connection to localhost 179 174 if matches!(goal, SwitchToConfigurationGoal::DryActivate) 180 - || should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) 175 + || ctx.should_apply_locally 181 176 { 182 177 return Err(HiveLibError::ActivationError( 183 178 ActivationError::SwitchToConfigurationError(*goal, ctx.name.clone(), error),
+2 -2
wire/lib/src/hive/steps/cleanup.rs
··· 21 21 } 22 22 23 23 impl ExecuteStep for CleanUp { 24 - fn should_execute(&self, _ctx: &Context) -> bool { 25 - true 24 + fn should_execute(&self, ctx: &Context) -> bool { 25 + !ctx.should_apply_locally 26 26 } 27 27 28 28 async fn execute(&self, ctx: &mut Context<'_>) -> Result<(), HiveLibError> {
+8 -20
wire/lib/src/hive/steps/keys.rs
··· 26 26 use crate::commands::common::push; 27 27 use crate::commands::{CommandArguments, WireCommandChip, run_command}; 28 28 use crate::errors::KeyError; 29 - use crate::hive::node::{ 30 - Context, ExecuteStep, Goal, Push, SwitchToConfigurationGoal, should_apply_locally, 31 - }; 29 + use crate::hive::node::{Context, ExecuteStep, Goal, Push, SwitchToConfigurationGoal}; 32 30 33 31 #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash)] 34 32 #[serde(tag = "t", content = "c")] ··· 235 233 236 234 let mut child = run_command( 237 235 &CommandArguments::new(command_string, ctx.modifiers, ctx.clobber_lock.clone()) 238 - .on_target( 239 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) 240 - { 241 - None 242 - } else { 243 - Some(&ctx.node.target) 244 - }, 245 - ) 236 + .on_target(if ctx.should_apply_locally { 237 + None 238 + } else { 239 + Some(&ctx.node.target) 240 + }) 246 241 .elevated() 247 242 .keep_stdin_open() 248 243 .log_stdout(), ··· 302 297 ), 303 298 }; 304 299 305 - if !should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) { 306 - push( 307 - ctx.node, 308 - ctx.name, 309 - Push::Path(&agent_directory), 310 - ctx.modifiers, 311 - ctx.clobber_lock.clone(), 312 - ) 313 - .await?; 300 + if !ctx.should_apply_locally { 301 + push(ctx, Push::Path(&agent_directory)).await?; 314 302 } 315 303 316 304 ctx.state.key_agent_directory = Some(agent_directory);
+2 -2
wire/lib/src/hive/steps/ping.rs
··· 7 7 8 8 use crate::{ 9 9 HiveLibError, 10 - hive::node::{Context, ExecuteStep, should_apply_locally}, 10 + hive::node::{Context, ExecuteStep}, 11 11 }; 12 12 13 13 #[derive(Debug, PartialEq)] ··· 21 21 22 22 impl ExecuteStep for Ping { 23 23 fn should_execute(&self, ctx: &Context) -> bool { 24 - !should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) 24 + !ctx.should_apply_locally 25 25 } 26 26 27 27 #[instrument(skip_all, name = "ping")]
+9 -24
wire/lib/src/hive/steps/push.rs
··· 3 3 4 4 use std::fmt::Display; 5 5 6 - use tracing::{instrument, warn}; 6 + use tracing::instrument; 7 7 8 8 use crate::{ 9 9 HiveLibError, 10 10 commands::common::push, 11 - hive::node::{Context, ExecuteStep, Goal, should_apply_locally}, 11 + hive::node::{Context, ExecuteStep, Goal}, 12 12 }; 13 13 14 14 #[derive(Debug, PartialEq)] ··· 38 38 async fn execute(&self, ctx: &mut Context<'_>) -> Result<(), HiveLibError> { 39 39 let top_level = ctx.state.evaluation.as_ref().unwrap(); 40 40 41 - push( 42 - ctx.node, 43 - ctx.name, 44 - crate::hive::node::Push::Derivation(top_level), 45 - ctx.modifiers, 46 - ctx.clobber_lock.clone() 47 - ).await.inspect_err(|_| { 48 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.to_string()) { 49 - warn!("Remote push failed, but this node matches our local hostname ({0}). Perhaps you want to apply this node locally? Use `--always-build-local {0}` to override deployment.buildOnTarget", ctx.name.to_string()); 50 - } else { 51 - warn!("Use `--always-build-local {0}` to override deployment.buildOnTarget and force {0} to build locally", ctx.name.to_string()); 52 - } 53 - }) 41 + push(ctx, crate::hive::node::Push::Derivation(top_level)).await?; 42 + 43 + Ok(()) 54 44 } 55 45 } 56 46 ··· 66 56 return false; 67 57 } 68 58 69 - if should_apply_locally(ctx.node.allow_local_deployment, &ctx.name.0) { 59 + if ctx.should_apply_locally { 70 60 // skip step if we are applying locally 71 61 return false; 72 62 } ··· 78 68 async fn execute(&self, ctx: &mut Context<'_>) -> Result<(), HiveLibError> { 79 69 let built_path = ctx.state.build.as_ref().unwrap(); 80 70 81 - push( 82 - ctx.node, 83 - ctx.name, 84 - crate::hive::node::Push::Path(built_path), 85 - ctx.modifiers, 86 - ctx.clobber_lock.clone(), 87 - ) 88 - .await 71 + push(ctx, crate::hive::node::Push::Path(built_path)).await?; 72 + 73 + Ok(()) 89 74 } 90 75 }