Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

client: initialize sower at the top level

+45 -40
+36 -30
client/src/main.rs
··· 234 234 .bootstrap_token_file(cli.bootstrap_token_file) 235 235 .bootstrap_token(); 236 236 237 - let tree = Tree::new(&config).await?; 238 - debug!("tree: {:?}", &tree); 237 + let sower = Sower::new(&config)?; 239 238 240 239 match &cli.action { 241 240 Actions::Daemon {} => { 242 - let mut daemon = Daemon::new(&config).await; 241 + let mut daemon = Daemon::new(&config, &sower).await; 243 242 daemon.run().await.unwrap() 244 243 } 245 244 246 245 Actions::Seed { action } => { 247 - let seed = tree 248 - .seeds 249 - .expect("No seeds loaded into tree") 250 - .desired 251 - .expect("Could not find desired seed"); 246 + let seed = sower 247 + .find_seed( 248 + config.name.expect("name is required"), 249 + config.seed_type.expect("seed type is required"), 250 + ) 251 + .await 252 + .expect("failed to find seed"); 252 253 253 254 match action { 254 255 SeedCommands::Activate { mode, .. } => { ··· 262 263 } 263 264 } 264 265 265 - Actions::Tree { action } => match action { 266 - TreeCommands::Info {} => info!("{:?}", tree), 266 + Actions::Tree { action } => { 267 + let tree = Tree::new(&config, &sower).await?; 268 + debug!("tree: {:?}", &tree); 267 269 268 - TreeCommands::Reboot { yes } => { 269 - tree.info(); 270 - tree.reboot(*yes) 271 - } 270 + match action { 271 + TreeCommands::Info {} => info!("{:?}", tree), 272 272 273 - TreeCommands::Upgrade { mode, reboot, yes } => { 274 - debug!("{:?}", tree); 273 + TreeCommands::Reboot { yes } => { 274 + tree.info(); 275 + tree.reboot(*yes) 276 + } 275 277 276 - let mode = mode.clone().or(config.mode); 277 - let desired = tree.seeds.clone().unwrap().desired; 278 - match desired { 279 - Some(desired) => { 280 - info!("Activating seed {:?}", &desired); 281 - desired 282 - .realize() 283 - .expect("failed to realize") 284 - .activate(mode) 285 - .expect("failed to activate"); 278 + TreeCommands::Upgrade { mode, reboot, yes } => { 279 + debug!("{:?}", tree); 280 + 281 + let mode = mode.clone().or(config.mode); 282 + let desired = tree.seeds.clone().unwrap().desired; 283 + match desired { 284 + Some(desired) => { 285 + info!("Activating seed {:?}", &desired); 286 + desired 287 + .realize() 288 + .expect("failed to realize") 289 + .activate(mode) 290 + .expect("failed to activate"); 286 291 287 - if config.reboot.unwrap_or(false) || *reboot { 288 - tree.reboot(*yes); 292 + if config.reboot.unwrap_or(false) || *reboot { 293 + tree.reboot(*yes); 294 + } 289 295 } 296 + None => panic!("No desired seed found"), 290 297 } 291 - None => panic!("No desired seed found"), 292 298 } 293 299 } 294 - }, 300 + } 295 301 } 296 302 297 303 Ok(())
+3 -3
client/src/sower.rs
··· 38 38 } 39 39 } 40 40 41 + // TODO turn activation into a trait, with default implementation 41 42 fn activate_home_manager(&self) -> Result<&Self, String> { 42 43 match run_command(format!("{}/activate", &self.out_path).as_ref(), vec![]) { 43 44 true => Ok(self), ··· 207 208 } 208 209 209 210 impl Tree { 210 - pub async fn new(config: &Config) -> Result<Tree> { 211 + pub async fn new(config: &Config, sower: &Sower) -> Result<Tree> { 211 212 let name = 212 213 config 213 214 .name ··· 220 221 SeedType::HomeManager => env::var("USER").expect("can not detect username"), 221 222 }); 222 223 let seed_type = config.seed_type.unwrap(); 223 - let sower = Sower::new(config)?; 224 224 225 225 let mut tree = Tree { 226 226 name: name.clone(), ··· 326 326 return false; 327 327 }; 328 328 329 - let profile = fs::canonicalize(profile_path).expect("unstable to read current link"); 329 + let profile = fs::canonicalize(profile_path).expect("unable to read profile link"); 330 330 let current = fs::canonicalize(current_path).expect("unable to read current link"); 331 331 let booted = fs::canonicalize(booted_path).expect("unable to read booted link"); 332 332
+6 -7
client/src/sower/daemon.rs
··· 1 - use super::{Config, Tree}; 1 + use super::{Config, Sower, Tree}; 2 2 3 3 use std::sync::Arc; 4 4 use std::time::Duration; ··· 27 27 } 28 28 29 29 impl Daemon { 30 - pub async fn new(config: &Config) -> Self { 31 - let tree = Tree::new(config).await.expect("Failed to load tree"); 30 + pub async fn new(config: &Config, sower: &Sower) -> Self { 31 + let tree = Tree::new(config, sower).await.expect("Failed to load tree"); 32 32 33 33 info!("Connecting to sower"); 34 34 let url = Url::parse_with_params( ··· 95 95 } 96 96 }; 97 97 98 - self.tree.server_id = tree_id.clone(); 98 + self.tree.server_id.clone_from(&tree_id); 99 99 100 100 Self::run_private_channel(self.socket.clone(), tree_id.unwrap()).await 101 101 ··· 171 171 172 172 info!("Listening for private events"); 173 173 loop { 174 - match events.event().await { 175 - event => debug!("{:?}", event), 176 - } 174 + let event = events.event().await; 175 + debug!("{:?}", event) 177 176 } 178 177 } 179 178 }