chore: Update akmods module to account for upstream changes (#165)

This change updates the akmods module to pull the new nvidia images. The
new property will be a boolean with property name of `nvidia`. If a user
continues to use the old `nvidia-version` property, a warning will be
printed telling them to switch to the new property. The old images will
still be allowed to be used to support backwards compatibility.
This commit is contained in:
Gerald Pinder 2024-04-20 13:00:38 -04:00 committed by GitHub
parent 4ef0bf9169
commit 71a3bda3c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 11 deletions

View file

@ -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

View file

@ -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()
}