Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(akmods): Update akmods image ref gen to handle open drivers #255

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions recipe/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use blue_build_utils::syntax_highlighting::highlight_ser;
use bon::Builder;
use colored::Colorize;
use indexmap::IndexMap;
use log::{trace, warn};
use log::trace;
use miette::{bail, Result};
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
Expand Down Expand Up @@ -93,10 +93,30 @@ impl<'a> ModuleRequiredFields<'a> {

#[must_use]
pub fn generate_akmods_info(&'a self, os_version: &u64) -> AkmodsInfo {
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone)]
enum NvidiaAkmods {
Nvidia(bool),
Version(u64),
#[default]
Disabled,
Enabled,
Open,
Proprietary,
}

impl From<&Value> for NvidiaAkmods {
fn from(value: &Value) -> Self {
match value.get("nvidia") {
Some(enabled) if enabled.is_bool() => match enabled.as_bool() {
Some(true) => Self::Enabled,
_ => Self::Disabled,
},
Some(driver_type) if driver_type.is_string() => match driver_type.as_str() {
Some("open") => Self::Open,
Some("proprietary") => Self::Proprietary,
_ => Self::Disabled,
},
_ => Self::Disabled,
}
}
}

trace!("generate_akmods_base({self:#?}, {os_version})");
Expand All @@ -105,60 +125,50 @@ impl<'a> ModuleRequiredFields<'a> {
.config
.get("base")
.map(|b| b.as_str().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())
},
);
let nvidia = self
.config
.get("nvidia")
.map_or_else(Default::default, NvidiaAkmods::from);

AkmodsInfo::builder()
.images(match (base, nvidia) {
(Some(b), NvidiaAkmods::Nvidia(nv)) if !b.is_empty() && nv => (
(Some(b), NvidiaAkmods::Enabled | NvidiaAkmods::Proprietary) if !b.is_empty() => (
format!("akmods:{b}-{os_version}"),
format!("akmods-extra:{b}-{os_version}"),
Some(format!("akmods-nvidia:{b}-{os_version}")),
),
(Some(b), NvidiaAkmods::Version(nv)) if !b.is_empty() && nv > 0 => (
(Some(b), NvidiaAkmods::Disabled) if !b.is_empty() => (
format!("akmods:{b}-{os_version}"),
format!("akmods-extra:{b}-{os_version}"),
Some(format!("akmods-nvidia:{b}-{os_version}-{nv}")),
None,
),
(Some(b), _) if !b.is_empty() => (
(Some(b), NvidiaAkmods::Open) if !b.is_empty() => (
format!("akmods:{b}-{os_version}"),
format!("akmods-extra:{b}-{os_version}"),
None,
Some(format!("akmods-nvidia-open:{b}-{os_version}")),
),
(_, NvidiaAkmods::Nvidia(nv)) if nv => (
(_, NvidiaAkmods::Enabled | NvidiaAkmods::Proprietary) => (
format!("akmods:main-{os_version}"),
format!("akmods-extra:main-{os_version}"),
Some(format!("akmods-nvidia:main-{os_version}")),
),
(_, NvidiaAkmods::Version(nv)) if nv > 0 => (
(_, NvidiaAkmods::Disabled) => (
format!("akmods:main-{os_version}"),
format!("akmods-extra:main-{os_version}"),
Some(format!("akmods-nvidia:main-{os_version}-{nv}")),
None,
),
_ => (
(_, NvidiaAkmods::Open) => (
format!("akmods:main-{os_version}"),
format!("akmods-extra:main-{os_version}"),
None,
Some(format!("akmods-nvidia-open:main-{os_version}")),
),
})
.stage_name(format!(
"{}{}",
base.unwrap_or("main"),
match nvidia {
NvidiaAkmods::Nvidia(nv) if nv => "-nvidia".to_string(),
NvidiaAkmods::Version(nv) if nv > 0 => format!("-nvidia-{nv}"),
_ => String::default(),
NvidiaAkmods::Disabled => String::default(),
_ => "-nvidia".to_string(),
}
))
.build()
Expand Down
Loading