diff --git a/src/actions/base/create_or_append_file.rs b/src/actions/base/create_or_append_file.rs index c133e91..4cc7e02 100644 --- a/src/actions/base/create_or_append_file.rs +++ b/src/actions/base/create_or_append_file.rs @@ -66,7 +66,12 @@ impl Actionable for CreateOrAppendFile { )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + path = %self.path.display(), + user = self.user, + group = self.group, + mode = format!("{:#o}", self.mode), + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { path, @@ -118,7 +123,12 @@ impl Actionable for CreateOrAppendFile { Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + path = %self.path.display(), + user = self.user, + group = self.group, + mode = format!("{:#o}", self.mode), + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { path, diff --git a/src/actions/base/create_user.rs b/src/actions/base/create_user.rs index e20cbc0..caa03b9 100644 --- a/src/actions/base/create_user.rs +++ b/src/actions/base/create_user.rs @@ -39,7 +39,11 @@ impl Actionable for CreateUser { )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + user = self.name, + uid = self.uid, + gid = self.gid, + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { name, @@ -80,7 +84,11 @@ impl Actionable for CreateUser { Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + user = self.name, + uid = self.uid, + gid = self.gid, + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { name, diff --git a/src/actions/base/fetch_nix.rs b/src/actions/base/fetch_nix.rs index e915476..d6f0415 100644 --- a/src/actions/base/fetch_nix.rs +++ b/src/actions/base/fetch_nix.rs @@ -10,19 +10,19 @@ use crate::actions::{Action, ActionDescription, ActionState, Actionable}; #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] pub struct FetchNix { url: Url, - destination: PathBuf, + dest: PathBuf, action_state: ActionState, } impl FetchNix { #[tracing::instrument(skip_all)] - pub async fn plan(url: Url, destination: PathBuf) -> Result { + pub async fn plan(url: Url, dest: PathBuf) -> Result { // TODO(@hoverbear): Check URL exists? // TODO(@hoverbear): Check tempdir exists Ok(Self { url, - destination, + dest, action_state: ActionState::Uncompleted, }) } @@ -34,23 +34,26 @@ impl Actionable for FetchNix { fn description(&self) -> Vec { let Self { url, - destination, + dest, action_state: _, } = &self; vec![ActionDescription::new( format!("Fetch Nix from `{url}`"), vec![format!( "Unpack it to `{}` (moved later)", - destination.display() + dest.display() )], )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + url = %self.url, + dest = %self.dest.display(), + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { url, - destination, + dest, action_state, } = self; if *action_state == ActionState::Completed { @@ -65,12 +68,12 @@ impl Actionable for FetchNix { let bytes = res.bytes().await.map_err(Self::Error::Reqwest)?; // TODO(@Hoverbear): Pick directory tracing::trace!("Unpacking tar.xz"); - let destination_clone = destination.clone(); + let dest_clone = dest.clone(); let handle: Result<(), Self::Error> = spawn_blocking(move || { let decoder = xz2::read::XzDecoder::new(bytes.reader()); let mut archive = tar::Archive::new(decoder); - archive.unpack(&destination_clone).map_err(Self::Error::Unarchive)?; - tracing::debug!(destination = %destination_clone.display(), "Downloaded & extracted Nix"); + archive.unpack(&dest_clone).map_err(Self::Error::Unarchive)?; + tracing::debug!(dest = %dest_clone.display(), "Downloaded & extracted Nix"); Ok(()) }) .await?; @@ -82,11 +85,14 @@ impl Actionable for FetchNix { Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + url = %self.url, + dest = %self.dest.display(), + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { url: _, - destination: _, + dest: _, action_state, } = self; diff --git a/src/actions/base/move_unpacked_nix.rs b/src/actions/base/move_unpacked_nix.rs index f923810..7e9a0fe 100644 --- a/src/actions/base/move_unpacked_nix.rs +++ b/src/actions/base/move_unpacked_nix.rs @@ -4,18 +4,20 @@ use serde::Serialize; use crate::actions::{Action, ActionDescription, ActionState, Actionable}; +const DEST: &str = "/nix/store"; + #[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] pub struct MoveUnpackedNix { - source: PathBuf, + src: PathBuf, action_state: ActionState, } impl MoveUnpackedNix { #[tracing::instrument(skip_all)] - pub async fn plan(source: PathBuf) -> Result { - // Note: Do NOT try to check for the source/dest since the installer creates those + pub async fn plan(src: PathBuf) -> Result { + // Note: Do NOT try to check for the src/dest since the installer creates those Ok(Self { - source, + src, action_state: ActionState::Uncompleted, }) } @@ -26,22 +28,25 @@ impl Actionable for MoveUnpackedNix { type Error = MoveUnpackedNixError; fn description(&self) -> Vec { let Self { - source, + src, action_state: _, } = &self; vec![ActionDescription::new( format!("Move the downloaded Nix into `/nix`"), vec![format!( "Nix is being downloaded to `{}` and should be in `nix`", - source.display(), + src.display(), )], )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + src = %self.src.display(), + dest = DEST, + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { - source, + src, action_state, } = self; if *action_state == ActionState::Completed { @@ -52,7 +57,7 @@ impl Actionable for MoveUnpackedNix { // TODO(@Hoverbear): I would like to make this less awful let found_nix_paths = - glob::glob(&format!("{}/nix-*", source.display()))?.collect::, _>>()?; + glob::glob(&format!("{}/nix-*", src.display()))?.collect::, _>>()?; assert_eq!( found_nix_paths.len(), 1, @@ -61,7 +66,7 @@ impl Actionable for MoveUnpackedNix { let found_nix_path = found_nix_paths.into_iter().next().unwrap(); tracing::trace!("Renaming"); let src = found_nix_path.join("store"); - let dest = Path::new("/nix/store"); + let dest = Path::new(DEST); tokio::fs::rename(src.clone(), dest) .await .map_err(|e| MoveUnpackedNixError::Rename(src, dest.to_owned(), e))?; @@ -71,10 +76,13 @@ impl Actionable for MoveUnpackedNix { Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + src = %self.src.display(), + dest = DEST, + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { - source: _, + src: _, action_state, } = self; if *action_state == ActionState::Uncompleted { diff --git a/src/actions/base/setup_default_profile.rs b/src/actions/base/setup_default_profile.rs index 63573f7..038f92c 100644 --- a/src/actions/base/setup_default_profile.rs +++ b/src/actions/base/setup_default_profile.rs @@ -35,13 +35,19 @@ impl Actionable for SetupDefaultProfile { )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + channels = %self.channels.join(","), + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { channels, action_state, } = self; - tracing::info!("Setting up default profile"); + if *action_state == ActionState::Completed { + tracing::trace!("Already completed: Setting up default profile"); + return Ok(()); + } + tracing::debug!("Setting up default profile"); // Find an `nix` package let nix_pkg_glob = "/nix/store/*-nix-*"; @@ -119,19 +125,29 @@ impl Actionable for SetupDefaultProfile { .await .map_err(SetupDefaultProfileError::Command)?; } + + tracing::trace!("Set up default profile"); *action_state = ActionState::Completed; Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + channels = %self.channels.join(","), + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { channels: _, action_state, } = self; + if *action_state == ActionState::Uncompleted { + tracing::trace!("Already reverted: Unset default profile"); + return Ok(()); + } + tracing::debug!("Unsetting default profile (mostly noop)"); std::env::remove_var("NIX_SSL_CERT_FILE"); + tracing::trace!("Unset default profile (mostly noop)"); *action_state = ActionState::Completed; Ok(()) } diff --git a/src/actions/base/start_systemd_unit.rs b/src/actions/base/start_systemd_unit.rs index ad43c01..cbb027f 100644 --- a/src/actions/base/start_systemd_unit.rs +++ b/src/actions/base/start_systemd_unit.rs @@ -45,9 +45,16 @@ impl Actionable for StartSystemdUnit { } } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + unit = %self.unit, + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { unit, action_state } = self; + if *action_state == ActionState::Completed { + tracing::trace!("Already completed: Starting systemd unit"); + return Ok(()); + } + tracing::debug!("Starting systemd unit"); // TODO(@Hoverbear): Handle proxy vars execute_command( @@ -59,19 +66,28 @@ impl Actionable for StartSystemdUnit { .await .map_err(StartSystemdUnitError::Command)?; + tracing::trace!("Started systemd unit"); *action_state = ActionState::Completed; Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + unit = %self.unit, + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { unit, action_state } = self; + if *action_state == ActionState::Uncompleted { + tracing::trace!("Already reverted: Stopping systemd unit"); + return Ok(()); + } + tracing::debug!("Stopping systemd unit"); // TODO(@Hoverbear): Handle proxy vars execute_command(Command::new("systemctl").arg("stop").arg(format!("{unit}"))) .await .map_err(StartSystemdUnitError::Command)?; + tracing::trace!("Stopped systemd unit"); *action_state = ActionState::Completed; Ok(()) } diff --git a/src/actions/meta/create_users_and_group.rs b/src/actions/meta/create_users_and_group.rs index 7cc22c0..5498081 100644 --- a/src/actions/meta/create_users_and_group.rs +++ b/src/actions/meta/create_users_and_group.rs @@ -76,7 +76,13 @@ impl Actionable for CreateUsersAndGroup { ] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + daemon_user_count = self.daemon_user_count, + nix_build_group_name = self.nix_build_group_name, + nix_build_group_id = self.nix_build_group_id, + nix_build_user_prefix = self.nix_build_user_prefix, + nix_build_user_id_base = self.nix_build_user_id_base, + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { create_users, @@ -132,7 +138,14 @@ impl Actionable for CreateUsersAndGroup { Ok(()) } - #[tracing::instrument(skip_all)] + + #[tracing::instrument(skip_all, fields( + daemon_user_count = self.daemon_user_count, + nix_build_group_name = self.nix_build_group_name, + nix_build_group_id = self.nix_build_group_id, + nix_build_user_prefix = self.nix_build_user_prefix, + nix_build_user_id_base = self.nix_build_user_id_base, + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { create_users, diff --git a/src/actions/meta/place_channel_configuration.rs b/src/actions/meta/place_channel_configuration.rs index 095ed83..aa1d5ee 100644 --- a/src/actions/meta/place_channel_configuration.rs +++ b/src/actions/meta/place_channel_configuration.rs @@ -57,7 +57,9 @@ impl Actionable for PlaceChannelConfiguration { )] } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + channels = self.channels.iter().map(|(c, u)| format!("{c}={u}")).collect::>().join(", "), + ))] async fn execute(&mut self) -> Result<(), Self::Error> { let Self { create_file, @@ -77,7 +79,9 @@ impl Actionable for PlaceChannelConfiguration { Ok(()) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip_all, fields( + channels = self.channels.iter().map(|(c, u)| format!("{c}={u}")).collect::>().join(", "), + ))] async fn revert(&mut self) -> Result<(), Self::Error> { let Self { create_file,