Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

refactor command running into a function

+28 -25
+28 -25
cli/src/sower.rs
··· 58 58 let mode = mode.clone().unwrap_or(ActivationMode::DryActivate); 59 59 60 60 // nixos profile needs to be manually set to ensure correct switching 61 - let command = &mut Command::new("nix-env"); 62 - let result = command.args([ 63 - "--set", 64 - "--profile", 65 - "/nix/var/nix/profiles/system", 66 - &self.out_path, 67 - ]); 68 - 69 - let output = result.output().expect("failed to get output"); 70 - 71 - let _exit_code = result.status().expect("failed to set system profile"); 72 - 73 - io::stdout().write_all(&output.stdout).unwrap(); 74 - io::stderr().write_all(&output.stderr).unwrap(); 61 + run_command( 62 + "nix-env".to_string(), 63 + vec![ 64 + "--set".to_string(), 65 + "--profile".to_string(), 66 + "/nix/var/nix/profiles/system".to_string(), 67 + self.out_path.clone(), 68 + ], 69 + ); 75 70 76 71 // activate 72 + let switch_result = run_command( 73 + format!("{}/bin/switch-to-configuration", &self.out_path), 74 + vec![mode.to_string()], 75 + ); 77 76 78 - let command = &mut Command::new(format!("{}/bin/switch-to-configuration", &self.out_path)); 79 - let result = command.args([mode.to_string()]); 80 - 81 - let output = result.output().expect("failed to get output"); 82 - 83 - let _exit_code = result.status().expect("failed to set system profile"); 84 - 85 - io::stdout().write_all(&output.stdout).unwrap(); 86 - io::stderr().write_all(&output.stderr).unwrap(); 87 - 88 - match output.status.success() { 77 + match switch_result { 89 78 true => Ok(self), 90 79 false => Err(format!("failed to realize: {}", &self.out_path)), 91 80 } ··· 176 165 println!("Rebooting") 177 166 } 178 167 } 168 + 169 + fn run_command(command: String, args: Vec<String>) -> bool { 170 + let command = &mut Command::new(command); 171 + let result = command.args(args); 172 + 173 + let output = result.output().expect("failed to get output"); 174 + 175 + let _exit_code = result.status().expect("failed to set system profile"); 176 + 177 + io::stdout().write_all(&output.stdout).unwrap(); 178 + io::stderr().write_all(&output.stderr).unwrap(); 179 + 180 + output.status.success() 181 + }