Skip to content

Commit

Permalink
Conditionally run nvd only if the system hostname and target hostname…
Browse files Browse the repository at this point in the history
…s match.
  • Loading branch information
cdo256 committed Jan 13, 2025
1 parent a0261e2 commit 805fa5f
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/nixos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ impl OsRebuildArgs {
update(&self.common.installable, self.update_args.update_input)?;
}

let hostname = match &self.hostname {
let system_hostname = hostname::get()
.context("Failed to get hostname")?
.to_str()
.unwrap()
.to_owned();

let target_hostname = match &self.hostname {
Some(h) => h.to_owned(),
None => hostname::get()
.context("Failed to get hostname")?
.to_str()
.unwrap()
.to_owned(),
None => {
tracing::warn!("Guessing system is {system_hostname} for a VM image. If this isn't intended, use --hostname to change.");
system_hostname.clone()
}
};

let out_path: Box<dyn crate::util::MaybeTempPath> = match self.common.out_link {
Expand All @@ -91,9 +96,9 @@ impl OsRebuildArgs {
debug!(?out_path);

let toplevel = toplevel_for(
hostname,
&target_hostname,
self.common.installable.clone(),
final_attr.unwrap_or(String::from("toplevel"))
final_attr.unwrap_or(String::from("toplevel")),
);

let message = match variant {
Expand Down Expand Up @@ -126,14 +131,18 @@ impl OsRebuildArgs {

target_profile.try_exists().context("Doesn't exist")?;

Command::new("nvd")
.arg("diff")
.arg(CURRENT_PROFILE)
.arg(&target_profile)
.message("Comparing changes")
.run()?;
if target_hostname == system_hostname {
Command::new("nvd")
.arg("diff")
.arg(CURRENT_PROFILE)
.arg(&target_profile)
.message("Comparing changes")
.run()?;
} else {
debug!("Not running nvd as the target hostname is different from the system hostname.")
}

if self.common.dry || matches!(variant, Build) {
if self.common.dry || matches!(variant, Build | BuildVm) {
return Ok(());
}

Expand Down

0 comments on commit 805fa5f

Please sign in to comment.