diff --git a/rust/tool/src/generation.rs b/rust/tool/src/generation.rs index 9a9df58..bffddef 100644 --- a/rust/tool/src/generation.rs +++ b/rust/tool/src/generation.rs @@ -80,22 +80,12 @@ impl Generation { /// /// This is currently implemented by poking around the filesystem to find the necessary data. /// Ideally, the needed data should be included in the bootspec. - pub fn describe(&self) -> Result { - let toplevel = &self.spec.bootspec.toplevel.0; - - let nixos_version = fs::read_to_string(toplevel.join("nixos-version")) - .unwrap_or_else(|_| String::from("Unknown")); - let kernel_version = - read_kernel_version(toplevel).context("Failed to read kernel version.")?; + pub fn describe(&self) -> String { let build_time = self .build_time .map(|x| x.to_string()) .unwrap_or_else(|| String::from("Unknown")); - - Ok(format!( - "Generation {} NixOS {}, Linux Kernel {}, Built on {}", - self.version, nixos_version, kernel_version, build_time - )) + format!("Generation {}, Built on {}", self.version, build_time) } } @@ -105,25 +95,6 @@ impl fmt::Display for Generation { } } -/// Read the kernel version from the name of a directory inside the toplevel directory. -/// -/// The path looks something like this: $toplevel/kernel-modules/lib/modules/6.1.1 -fn read_kernel_version(toplevel: &Path) -> Result { - let path = fs::read_dir(toplevel.join("kernel-modules/lib/modules"))? - .into_iter() - .next() - .transpose()? - .map(|x| x.path()) - .with_context(|| format!("Failed to read directory {:?}.", toplevel))?; - - let file_name = path - .file_name() - .and_then(|x| x.to_str()) - .context("Failed to convert path to filename string.")?; - - Ok(String::from(file_name)) -} - fn read_build_time(path: &Path) -> Result { let build_time = time::OffsetDateTime::from_unix_timestamp(fs::metadata(path)?.mtime())?.date(); Ok(build_time) diff --git a/rust/tool/src/os_release.rs b/rust/tool/src/os_release.rs index 4993e4b..1d05917 100644 --- a/rust/tool/src/os_release.rs +++ b/rust/tool/src/os_release.rs @@ -27,12 +27,7 @@ impl OsRelease { // it is fine to use a dummy value. map.insert("ID".into(), String::from("lanza")); map.insert("PRETTY_NAME".into(), generation.spec.bootspec.label.clone()); - map.insert( - "VERSION_ID".into(), - generation - .describe() - .context("Failed to describe generation.")?, - ); + map.insert("VERSION_ID".into(), generation.describe()); Ok(Self(map)) } diff --git a/rust/tool/tests/os_release.rs b/rust/tool/tests/os_release.rs index 95c6348..5203723 100644 --- a/rust/tool/tests/os_release.rs +++ b/rust/tool/tests/os_release.rs @@ -30,7 +30,7 @@ fn generate_expected_os_release() -> Result<()> { let expected = expect![[r#" ID=lanza PRETTY_NAME=LanzaOS - VERSION_ID=Generation 1 NixOS 23.05, Linux Kernel 6.1.1, Built on 1970-01-01 + VERSION_ID=Generation 1, Built on 1970-01-01 "#]]; expected.assert_eq(&String::from_utf8(os_release_section)?);