Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

feat(client): rename to client.toml, some logging cleanup

+29 -21
+24 -16
client/src/main.rs
··· 1 1 use crate::sower::*; 2 2 3 + use anyhow::Result; 3 4 use clap::Parser; 4 5 use clap::Subcommand; 5 6 use serde::Deserialize; ··· 167 168 } 168 169 169 170 #[tokio::main] 170 - async fn main() -> Result<(), Box<dyn std::error::Error>> { 171 + async fn main() -> Result<()> { 171 172 tracing_subscriber::fmt::init(); 172 173 173 174 let cli = Cli::parse(); 174 175 176 + // config loading priority: 177 + // 1. --config 178 + // 2. SOWER_CLIENT_CONFIG_FILE env 179 + // 3. /etc/sower/client.toml for root, $XDG_CONFIG_HOME/sower/client.toml for other users 175 180 let config_file = match cli.config { 176 181 Some(path) => path, 177 182 None => match std::env::var("SOWER_CLIENT_CONFIG_FILE") { 178 183 Ok(f) => PathBuf::from(f), 179 184 Err(_) => match std::env::var("USER") { 180 185 Ok(user) => match user.as_ref() { 181 - "root" => PathBuf::from("/etc/sower/config.toml"), 186 + "root" => PathBuf::from("/etc/sower/client.toml"), 182 187 _ => xdg::BaseDirectories::with_prefix("sower") 183 188 .expect("cannot locate XDG directories") 184 - .get_config_file("config.toml"), 189 + .get_config_file("client.toml"), 185 190 }, 186 - Err(_) => PathBuf::from("/etc/sower/config.toml"), 191 + Err(_) => PathBuf::from("/etc/sower/client.toml"), 187 192 }, 188 193 }, 189 194 }; 190 195 191 - dbg!(&config_file); 192 - 193 196 let config = match Path::try_exists(&config_file) { 194 197 Ok(true) => { 198 + debug!("loading config: {:?}", &config_file); 199 + 195 200 let config_string = fs::read_to_string(config_file)?; 196 201 toml::from_str(&config_string).expect("failed to parse config file") 197 202 } 198 - _ => Config { 199 - bootstrap_token: None, 200 - bootstrap_token_file: None, 201 - reboot: None, 202 - mode: None, 203 - name: None, 204 - seed_type: None, 205 - url: None, 206 - }, 203 + _ => { 204 + info!("skipping config, file not found: {:?}", config_file); 205 + Config { 206 + bootstrap_token: None, 207 + bootstrap_token_file: None, 208 + reboot: None, 209 + mode: None, 210 + name: None, 211 + seed_type: None, 212 + url: None, 213 + } 214 + } 207 215 }; 208 216 209 217 // env overrides config ··· 221 229 .bootstrap_token(); 222 230 223 231 let tree = Tree::new(&config).await?; 232 + debug!("tree: {:?}", &tree); 224 233 225 234 match &cli.action { 226 235 Actions::Daemon {} => { ··· 229 238 } 230 239 231 240 Actions::Seed { action } => { 232 - dbg!("{}", &tree); 233 241 let seed = tree 234 242 .seeds 235 243 .expect("No seeds loaded into tree")
+3 -3
client/src/sower.rs
··· 11 11 use std::path::Path; 12 12 use std::process::Command; 13 13 use strum::{Display, VariantNames}; 14 - use tracing::{debug, info}; 14 + use tracing::{debug, error, info}; 15 15 16 16 #[derive(Clone, Debug, Deserialize, Serialize)] 17 17 pub struct Seed { ··· 175 175 match result.json::<Seed>().await { 176 176 Ok(seed) => Some(seed), 177 177 Err(err) => { 178 - dbg!(err); 178 + error!("failed to get seed: {}", err); 179 179 None 180 180 } 181 181 } 182 182 } 183 183 Err(err) => { 184 - debug!("Err: {}", err); 184 + error!("failed to get seed: {}", err); 185 185 None 186 186 } 187 187 }
+2 -2
nix/nixos-client.nix
··· 57 57 }; 58 58 59 59 config = lib.mkIf cfg.enable { 60 - environment.etc."sower/config.toml".source = lib.mkIf (cfg.settings != null) ( 61 - toml.generate "sower-config.toml" ( 60 + environment.etc."sower/client.toml".source = lib.mkIf (cfg.settings != null) ( 61 + toml.generate "sower-client.toml" ( 62 62 cfg.settings // (lib.optionalAttrs cfg.autoreboot { reboot = true; }) 63 63 ) 64 64 );