tool: remove unhelpful wrappers and lightly refactor

This commit is contained in:
Julian Stecklina 2023-10-20 11:29:00 +02:00
parent 0c38cbfa6a
commit 3da3049bef
2 changed files with 21 additions and 23 deletions

View File

@ -26,14 +26,14 @@ pub struct ExtendedBootJson {
/// contains most of the information necessary to install the generation onto the EFI System
/// Partition. The only information missing is the version number which is encoded in the file name
/// of the generation link.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Generation {
/// Profile symlink index
version: u64,
pub version: u64,
/// Build time
build_time: Option<Date>,
pub build_time: Option<Date>,
/// Top-level specialisation name
specialisation_name: Option<SpecialisationName>,
pub specialisation_name: Option<SpecialisationName>,
/// Top-level extended boot specification
pub spec: ExtendedBootJson,
}
@ -57,19 +57,14 @@ impl Generation {
})
}
pub fn specialise(&self, name: &SpecialisationName, bootspec: &BootSpec) -> Result<Self> {
Ok(Self {
version: self.version,
build_time: self.build_time,
pub fn specialise(&self, name: &SpecialisationName, bootspec: &BootSpec) -> Self {
Self {
specialisation_name: Some(name.clone()),
spec: ExtendedBootJson {
bootspec: bootspec.clone(),
},
})
..self.clone()
}
pub fn is_specialised(&self) -> Option<SpecialisationName> {
self.specialisation_name.clone()
}
/// Describe the generation in a single line.
@ -84,14 +79,17 @@ impl Generation {
.build_time
.map(|x| x.to_string())
.unwrap_or_else(|| String::from("Unknown"));
if self.is_specialised().is_some() {
format!(
"Generation {}-specialised, Built on {}",
self.version, build_time
)
"Generation {}{}, {}",
self.version,
if let Some(specialization) = &self.specialisation_name {
format!("-{specialization}")
} else {
format!("Generation {}, Built on {}", self.version, build_time)
}
"".to_string()
},
build_time
)
}
}

View File

@ -163,7 +163,7 @@ impl Installer {
self.install_generation(&generation)
.context("Failed to install generation.")?;
for (name, bootspec) in &generation.spec.bootspec.specialisations {
let specialised_generation = generation.specialise(name, bootspec)?;
let specialised_generation = generation.specialise(name, bootspec);
self.install_generation(&specialised_generation)
.context("Failed to install specialisation.")?;
}
@ -374,7 +374,7 @@ fn stub_name(generation: &Generation, public_key: &Path) -> Result<PathBuf> {
let stub_input_hash = Base32Unpadded::encode_string(&Sha256::digest(
serde_json::to_string(&stub_inputs).unwrap(),
));
if let Some(specialisation_name) = generation.is_specialised() {
if let Some(specialisation_name) = &generation.specialisation_name {
Ok(PathBuf::from(format!(
"nixos-generation-{}-specialisation-{}-{}.efi",
generation, specialisation_name, stub_input_hash