tool: remove unhelpful wrappers and lightly refactor
This commit is contained in:
parent
0c38cbfa6a
commit
3da3049bef
|
@ -26,14 +26,14 @@ pub struct ExtendedBootJson {
|
||||||
/// contains most of the information necessary to install the generation onto the EFI System
|
/// 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
|
/// Partition. The only information missing is the version number which is encoded in the file name
|
||||||
/// of the generation link.
|
/// of the generation link.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Generation {
|
pub struct Generation {
|
||||||
/// Profile symlink index
|
/// Profile symlink index
|
||||||
version: u64,
|
pub version: u64,
|
||||||
/// Build time
|
/// Build time
|
||||||
build_time: Option<Date>,
|
pub build_time: Option<Date>,
|
||||||
/// Top-level specialisation name
|
/// Top-level specialisation name
|
||||||
specialisation_name: Option<SpecialisationName>,
|
pub specialisation_name: Option<SpecialisationName>,
|
||||||
/// Top-level extended boot specification
|
/// Top-level extended boot specification
|
||||||
pub spec: ExtendedBootJson,
|
pub spec: ExtendedBootJson,
|
||||||
}
|
}
|
||||||
|
@ -57,19 +57,14 @@ impl Generation {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn specialise(&self, name: &SpecialisationName, bootspec: &BootSpec) -> Result<Self> {
|
pub fn specialise(&self, name: &SpecialisationName, bootspec: &BootSpec) -> Self {
|
||||||
Ok(Self {
|
Self {
|
||||||
version: self.version,
|
|
||||||
build_time: self.build_time,
|
|
||||||
specialisation_name: Some(name.clone()),
|
specialisation_name: Some(name.clone()),
|
||||||
spec: ExtendedBootJson {
|
spec: ExtendedBootJson {
|
||||||
bootspec: bootspec.clone(),
|
bootspec: bootspec.clone(),
|
||||||
},
|
},
|
||||||
})
|
..self.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_specialised(&self) -> Option<SpecialisationName> {
|
|
||||||
self.specialisation_name.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describe the generation in a single line.
|
/// Describe the generation in a single line.
|
||||||
|
@ -84,14 +79,17 @@ impl Generation {
|
||||||
.build_time
|
.build_time
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.unwrap_or_else(|| String::from("Unknown"));
|
.unwrap_or_else(|| String::from("Unknown"));
|
||||||
if self.is_specialised().is_some() {
|
|
||||||
format!(
|
format!(
|
||||||
"Generation {}-specialised, Built on {}",
|
"Generation {}{}, {}",
|
||||||
self.version, build_time
|
self.version,
|
||||||
)
|
if let Some(specialization) = &self.specialisation_name {
|
||||||
} else {
|
format!("-{specialization}")
|
||||||
format!("Generation {}, Built on {}", self.version, build_time)
|
} else {
|
||||||
}
|
"".to_string()
|
||||||
|
},
|
||||||
|
build_time
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ impl Installer {
|
||||||
self.install_generation(&generation)
|
self.install_generation(&generation)
|
||||||
.context("Failed to install generation.")?;
|
.context("Failed to install generation.")?;
|
||||||
for (name, bootspec) in &generation.spec.bootspec.specialisations {
|
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)
|
self.install_generation(&specialised_generation)
|
||||||
.context("Failed to install specialisation.")?;
|
.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(
|
let stub_input_hash = Base32Unpadded::encode_string(&Sha256::digest(
|
||||||
serde_json::to_string(&stub_inputs).unwrap(),
|
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!(
|
Ok(PathBuf::from(format!(
|
||||||
"nixos-generation-{}-specialisation-{}-{}.efi",
|
"nixos-generation-{}-specialisation-{}-{}.efi",
|
||||||
generation, specialisation_name, stub_input_hash
|
generation, specialisation_name, stub_input_hash
|
||||||
|
|
Loading…
Reference in New Issue