diff --git a/integration-tests/test-repo/recipes/akmods.yml b/integration-tests/test-repo/recipes/akmods.yml index 68125de3..06078bd5 100644 --- a/integration-tests/test-repo/recipes/akmods.yml +++ b/integration-tests/test-repo/recipes/akmods.yml @@ -4,7 +4,7 @@ modules: # Tests installing rpms from a combo image stage - type: akmods base: surface - nvidia-version: 545 + nvidia: true # install: # - nvidia # - openrazer @@ -15,7 +15,7 @@ modules: # Tests pulling image for main nvidia - type: akmods - nvidia-version: 545 + nvidia: true # Test pulling image for base asus - type: akmods diff --git a/recipe/src/module.rs b/recipe/src/module.rs index 306a882b..04a9235c 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, process}; use anyhow::{bail, Result}; use indexmap::IndexMap; -use log::{error, trace}; +use log::{error, trace, warn}; use serde::{Deserialize, Serialize}; use serde_yaml::Value; use typed_builder::TypedBuilder; @@ -88,26 +88,50 @@ impl<'a> Module<'a> { }) } + #[must_use] pub fn generate_akmods_info(&'a self, os_version: &str) -> AkmodsInfo { + #[derive(Debug, Copy, Clone)] + enum NvidiaAkmods { + Nvidia(bool), + Version(u64), + } + trace!("generate_akmods_base({self:#?}, {os_version})"); let base = self .config .get("base") .map(|b| b.as_str().unwrap_or_default()); - let nvidia_version = self - .config - .get("nvidia-version") - .map(|v| v.as_u64().unwrap_or_default()); + let nvidia = self.config.get("nvidia-version").map_or_else( + || { + self.config + .get("nvidia") + .map_or_else(|| NvidiaAkmods::Nvidia(false), |v| NvidiaAkmods::Nvidia(v.as_bool().unwrap_or_default())) + }, + |v| { + warn!( + "The `nvidia-version` property is deprecated as upstream images may no longer exist, replace it with `nvidia: true`" + ); + NvidiaAkmods::Version(v.as_u64().unwrap_or_default()) + }, + ); AkmodsInfo::builder() - .images(match (base, nvidia_version) { - (Some(b), Some(nv)) if !b.is_empty() && nv > 0 => ( + .images(match (base, nvidia) { + (Some(b), NvidiaAkmods::Nvidia(nv)) if !b.is_empty() && nv => ( + format!("akmods:{b}-{os_version}"), + Some(format!("akmods-nvidia:{b}-{os_version}")), + ), + (Some(b), NvidiaAkmods::Version(nv)) if !b.is_empty() && nv > 0 => ( format!("akmods:{b}-{os_version}"), Some(format!("akmods-nvidia:{b}-{os_version}-{nv}")), ), (Some(b), _) if !b.is_empty() => (format!("akmods:{b}-{os_version}"), None), - (_, Some(nv)) if nv > 0 => ( + (_, NvidiaAkmods::Nvidia(nv)) if nv => ( + format!("akmods:main-{os_version}"), + Some(format!("akmods-nvidia:main-{os_version}")), + ), + (_, NvidiaAkmods::Version(nv)) if nv > 0 => ( format!("akmods:main-{os_version}"), Some(format!("akmods-nvidia:main-{os_version}-{nv}")), ), @@ -116,7 +140,11 @@ impl<'a> Module<'a> { .stage_name(format!( "{}{}", base.unwrap_or("main"), - nvidia_version.map_or_else(String::default, |nv| format!("-{nv}")) + match nvidia { + NvidiaAkmods::Nvidia(nv) if nv => "-nvidia".to_string(), + NvidiaAkmods::Version(nv) if nv > 0 => format!("-nvidia-{nv}"), + _ => String::default(), + } )) .build() }