Tidy more logs
This commit is contained in:
parent
257d82b3b4
commit
47018ad00c
|
@ -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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
path,
|
path,
|
||||||
|
@ -118,7 +123,12 @@ impl Actionable for CreateOrAppendFile {
|
||||||
Ok(())
|
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> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
path,
|
path,
|
||||||
|
|
|
@ -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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
name,
|
name,
|
||||||
|
@ -80,7 +84,11 @@ impl Actionable for CreateUser {
|
||||||
Ok(())
|
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> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -10,19 +10,19 @@ use crate::actions::{Action, ActionDescription, ActionState, Actionable};
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||||
pub struct FetchNix {
|
pub struct FetchNix {
|
||||||
url: Url,
|
url: Url,
|
||||||
destination: PathBuf,
|
dest: PathBuf,
|
||||||
action_state: ActionState,
|
action_state: ActionState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FetchNix {
|
impl FetchNix {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn plan(url: Url, destination: PathBuf) -> Result<Self, FetchNixError> {
|
pub async fn plan(url: Url, dest: PathBuf) -> Result<Self, FetchNixError> {
|
||||||
// TODO(@hoverbear): Check URL exists?
|
// TODO(@hoverbear): Check URL exists?
|
||||||
// TODO(@hoverbear): Check tempdir exists
|
// TODO(@hoverbear): Check tempdir exists
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
url,
|
url,
|
||||||
destination,
|
dest,
|
||||||
action_state: ActionState::Uncompleted,
|
action_state: ActionState::Uncompleted,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -34,23 +34,26 @@ impl Actionable for FetchNix {
|
||||||
fn description(&self) -> Vec<ActionDescription> {
|
fn description(&self) -> Vec<ActionDescription> {
|
||||||
let Self {
|
let Self {
|
||||||
url,
|
url,
|
||||||
destination,
|
dest,
|
||||||
action_state: _,
|
action_state: _,
|
||||||
} = &self;
|
} = &self;
|
||||||
vec![ActionDescription::new(
|
vec![ActionDescription::new(
|
||||||
format!("Fetch Nix from `{url}`"),
|
format!("Fetch Nix from `{url}`"),
|
||||||
vec![format!(
|
vec![format!(
|
||||||
"Unpack it to `{}` (moved later)",
|
"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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
url,
|
url,
|
||||||
destination,
|
dest,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = self;
|
||||||
if *action_state == ActionState::Completed {
|
if *action_state == ActionState::Completed {
|
||||||
|
@ -65,12 +68,12 @@ impl Actionable for FetchNix {
|
||||||
let bytes = res.bytes().await.map_err(Self::Error::Reqwest)?;
|
let bytes = res.bytes().await.map_err(Self::Error::Reqwest)?;
|
||||||
// TODO(@Hoverbear): Pick directory
|
// TODO(@Hoverbear): Pick directory
|
||||||
tracing::trace!("Unpacking tar.xz");
|
tracing::trace!("Unpacking tar.xz");
|
||||||
let destination_clone = destination.clone();
|
let dest_clone = dest.clone();
|
||||||
let handle: Result<(), Self::Error> = spawn_blocking(move || {
|
let handle: Result<(), Self::Error> = spawn_blocking(move || {
|
||||||
let decoder = xz2::read::XzDecoder::new(bytes.reader());
|
let decoder = xz2::read::XzDecoder::new(bytes.reader());
|
||||||
let mut archive = tar::Archive::new(decoder);
|
let mut archive = tar::Archive::new(decoder);
|
||||||
archive.unpack(&destination_clone).map_err(Self::Error::Unarchive)?;
|
archive.unpack(&dest_clone).map_err(Self::Error::Unarchive)?;
|
||||||
tracing::debug!(destination = %destination_clone.display(), "Downloaded & extracted Nix");
|
tracing::debug!(dest = %dest_clone.display(), "Downloaded & extracted Nix");
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -82,11 +85,14 @@ impl Actionable for FetchNix {
|
||||||
Ok(())
|
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> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
url: _,
|
url: _,
|
||||||
destination: _,
|
dest: _,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,20 @@ use serde::Serialize;
|
||||||
|
|
||||||
use crate::actions::{Action, ActionDescription, ActionState, Actionable};
|
use crate::actions::{Action, ActionDescription, ActionState, Actionable};
|
||||||
|
|
||||||
|
const DEST: &str = "/nix/store";
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||||
pub struct MoveUnpackedNix {
|
pub struct MoveUnpackedNix {
|
||||||
source: PathBuf,
|
src: PathBuf,
|
||||||
action_state: ActionState,
|
action_state: ActionState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MoveUnpackedNix {
|
impl MoveUnpackedNix {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn plan(source: PathBuf) -> Result<Self, MoveUnpackedNixError> {
|
pub async fn plan(src: PathBuf) -> Result<Self, MoveUnpackedNixError> {
|
||||||
// Note: Do NOT try to check for the source/dest since the installer creates those
|
// Note: Do NOT try to check for the src/dest since the installer creates those
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
source,
|
src,
|
||||||
action_state: ActionState::Uncompleted,
|
action_state: ActionState::Uncompleted,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -26,22 +28,25 @@ impl Actionable for MoveUnpackedNix {
|
||||||
type Error = MoveUnpackedNixError;
|
type Error = MoveUnpackedNixError;
|
||||||
fn description(&self) -> Vec<ActionDescription> {
|
fn description(&self) -> Vec<ActionDescription> {
|
||||||
let Self {
|
let Self {
|
||||||
source,
|
src,
|
||||||
action_state: _,
|
action_state: _,
|
||||||
} = &self;
|
} = &self;
|
||||||
vec![ActionDescription::new(
|
vec![ActionDescription::new(
|
||||||
format!("Move the downloaded Nix into `/nix`"),
|
format!("Move the downloaded Nix into `/nix`"),
|
||||||
vec![format!(
|
vec![format!(
|
||||||
"Nix is being downloaded to `{}` and should be in `nix`",
|
"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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
source,
|
src,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = self;
|
||||||
if *action_state == ActionState::Completed {
|
if *action_state == ActionState::Completed {
|
||||||
|
@ -52,7 +57,7 @@ impl Actionable for MoveUnpackedNix {
|
||||||
|
|
||||||
// TODO(@Hoverbear): I would like to make this less awful
|
// TODO(@Hoverbear): I would like to make this less awful
|
||||||
let found_nix_paths =
|
let found_nix_paths =
|
||||||
glob::glob(&format!("{}/nix-*", source.display()))?.collect::<Result<Vec<_>, _>>()?;
|
glob::glob(&format!("{}/nix-*", src.display()))?.collect::<Result<Vec<_>, _>>()?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
found_nix_paths.len(),
|
found_nix_paths.len(),
|
||||||
1,
|
1,
|
||||||
|
@ -61,7 +66,7 @@ impl Actionable for MoveUnpackedNix {
|
||||||
let found_nix_path = found_nix_paths.into_iter().next().unwrap();
|
let found_nix_path = found_nix_paths.into_iter().next().unwrap();
|
||||||
tracing::trace!("Renaming");
|
tracing::trace!("Renaming");
|
||||||
let src = found_nix_path.join("store");
|
let src = found_nix_path.join("store");
|
||||||
let dest = Path::new("/nix/store");
|
let dest = Path::new(DEST);
|
||||||
tokio::fs::rename(src.clone(), dest)
|
tokio::fs::rename(src.clone(), dest)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| MoveUnpackedNixError::Rename(src, dest.to_owned(), e))?;
|
.map_err(|e| MoveUnpackedNixError::Rename(src, dest.to_owned(), e))?;
|
||||||
|
@ -71,10 +76,13 @@ impl Actionable for MoveUnpackedNix {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all, fields(
|
||||||
|
src = %self.src.display(),
|
||||||
|
dest = DEST,
|
||||||
|
))]
|
||||||
async fn revert(&mut self) -> Result<(), Self::Error> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
source: _,
|
src: _,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = self;
|
||||||
if *action_state == ActionState::Uncompleted {
|
if *action_state == ActionState::Uncompleted {
|
||||||
|
|
|
@ -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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
channels,
|
channels,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = 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
|
// Find an `nix` package
|
||||||
let nix_pkg_glob = "/nix/store/*-nix-*";
|
let nix_pkg_glob = "/nix/store/*-nix-*";
|
||||||
|
@ -119,19 +125,29 @@ impl Actionable for SetupDefaultProfile {
|
||||||
.await
|
.await
|
||||||
.map_err(SetupDefaultProfileError::Command)?;
|
.map_err(SetupDefaultProfileError::Command)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tracing::trace!("Set up default profile");
|
||||||
*action_state = ActionState::Completed;
|
*action_state = ActionState::Completed;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all, fields(
|
||||||
|
channels = %self.channels.join(","),
|
||||||
|
))]
|
||||||
async fn revert(&mut self) -> Result<(), Self::Error> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
channels: _,
|
channels: _,
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = 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");
|
std::env::remove_var("NIX_SSL_CERT_FILE");
|
||||||
|
|
||||||
|
tracing::trace!("Unset default profile (mostly noop)");
|
||||||
*action_state = ActionState::Completed;
|
*action_state = ActionState::Completed;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self { unit, action_state } = self;
|
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
|
// TODO(@Hoverbear): Handle proxy vars
|
||||||
execute_command(
|
execute_command(
|
||||||
|
@ -59,19 +66,28 @@ impl Actionable for StartSystemdUnit {
|
||||||
.await
|
.await
|
||||||
.map_err(StartSystemdUnitError::Command)?;
|
.map_err(StartSystemdUnitError::Command)?;
|
||||||
|
|
||||||
|
tracing::trace!("Started systemd unit");
|
||||||
*action_state = ActionState::Completed;
|
*action_state = ActionState::Completed;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all, fields(
|
||||||
|
unit = %self.unit,
|
||||||
|
))]
|
||||||
async fn revert(&mut self) -> Result<(), Self::Error> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self { unit, action_state } = self;
|
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
|
// TODO(@Hoverbear): Handle proxy vars
|
||||||
execute_command(Command::new("systemctl").arg("stop").arg(format!("{unit}")))
|
execute_command(Command::new("systemctl").arg("stop").arg(format!("{unit}")))
|
||||||
.await
|
.await
|
||||||
.map_err(StartSystemdUnitError::Command)?;
|
.map_err(StartSystemdUnitError::Command)?;
|
||||||
|
|
||||||
|
tracing::trace!("Stopped systemd unit");
|
||||||
*action_state = ActionState::Completed;
|
*action_state = ActionState::Completed;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
create_users,
|
create_users,
|
||||||
|
@ -132,7 +138,14 @@ impl Actionable for CreateUsersAndGroup {
|
||||||
Ok(())
|
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> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
create_users,
|
create_users,
|
||||||
|
|
|
@ -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::<Vec<_>>().join(", "),
|
||||||
|
))]
|
||||||
async fn execute(&mut self) -> Result<(), Self::Error> {
|
async fn execute(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
create_file,
|
create_file,
|
||||||
|
@ -77,7 +79,9 @@ impl Actionable for PlaceChannelConfiguration {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all, fields(
|
||||||
|
channels = self.channels.iter().map(|(c, u)| format!("{c}={u}")).collect::<Vec<_>>().join(", "),
|
||||||
|
))]
|
||||||
async fn revert(&mut self) -> Result<(), Self::Error> {
|
async fn revert(&mut self) -> Result<(), Self::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
create_file,
|
create_file,
|
||||||
|
|
Loading…
Reference in a new issue