diff --git a/rust/tool/shared/src/generation.rs b/rust/tool/shared/src/generation.rs index 7cd57d5..192d900 100644 --- a/rust/tool/shared/src/generation.rs +++ b/rust/tool/shared/src/generation.rs @@ -67,7 +67,16 @@ impl Generation { } } - /// Describe the generation in a single line. + /// A helper for describe functions below. + fn describe_specialisation(&self) -> String { + if let Some(specialization) = &self.specialisation_name { + format!("-{specialization}") + } else { + "".to_string() + } + } + + /// Describe the generation in a single line for humans. /// /// Emulates how NixOS's current systemd-boot-builder.py describes generations so that the user /// interface remains similar. @@ -83,14 +92,15 @@ impl Generation { format!( "Generation {}{}, {}", self.version, - if let Some(specialization) = &self.specialisation_name { - format!("-{specialization}") - } else { - "".to_string() - }, + self.describe_specialisation(), build_time ) } + + /// A unique short identifier. + pub fn version_tag(&self) -> String { + format!("{}{}", self.version, self.describe_specialisation(),) + } } impl fmt::Display for Generation { diff --git a/rust/tool/shared/src/os_release.rs b/rust/tool/shared/src/os_release.rs index cdee3dc..9872bff 100644 --- a/rust/tool/shared/src/os_release.rs +++ b/rust/tool/shared/src/os_release.rs @@ -26,10 +26,21 @@ impl OsRelease { // Because the ID field here does not have the same meaning as in a real os-release file, // it is fine to use a dummy value. map.insert("ID".into(), String::from("lanza")); + + // systemd-boot will only show VERSION_ID when PRETTY_NAME is not unique. This is + // confusing to users. Make sure that our PRETTY_NAME is unique, so we get a consistent + // user experience. + // + // See #220. map.insert( "PRETTY_NAME".into(), - generation.spec.bootspec.bootspec.label.clone(), + format!( + "{} ({})", + generation.spec.bootspec.bootspec.label, + generation.describe() + ), ); + map.insert("VERSION_ID".into(), generation.describe()); Ok(Self(map)) diff --git a/rust/tool/systemd/tests/os_release.rs b/rust/tool/systemd/tests/os_release.rs index eb1f627..50c1986 100644 --- a/rust/tool/systemd/tests/os_release.rs +++ b/rust/tool/systemd/tests/os_release.rs @@ -27,8 +27,8 @@ fn generate_expected_os_release() -> Result<()> { let expected = expect![[r#" ID=lanza - PRETTY_NAME=LanzaOS - VERSION_ID=Generation 1, Built on 1970-01-01 + PRETTY_NAME=LanzaOS (Generation 1, 1970-01-01) + VERSION_ID=Generation 1, 1970-01-01 "#]]; expected.assert_eq(&String::from_utf8(os_release_section)?);