diff --git a/profiles/pci/graphic_drivers/profiles.toml b/profiles/pci/graphic_drivers/profiles.toml index 04aabf0..0373bab 100644 --- a/profiles/pci/graphic_drivers/profiles.toml +++ b/profiles/pci/graphic_drivers/profiles.toml @@ -36,12 +36,6 @@ conditional_packages = """ # Fallback if there are no kernels with pre-built modules [ -z "$modules" ] && modules="nvidia-open-dkms" echo "$modules" - - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - echo "nvidia-prime switcheroo-control" - fi """ pre_install = """ cat </etc/mkinitcpio.conf.d/10-chwd.conf @@ -49,45 +43,52 @@ pre_install = """ MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm) EOF - # Remove kms hook from mkinitcpio.conf on desktops - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ! ((device_type >= 8 && device_type <= 11)); then - cat <<'EOF' >/etc/mkinitcpio.conf.d/10-chwd-kms.conf + cat <<'EOF' >/etc/mkinitcpio.conf.d/10-chwd-kms.conf # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. HOOKS=(${HOOKS[@]/kms/}) EOF - fi """ +pre_remove = """ + rm -f /etc/mkinitcpio.conf.d/10-chwd.conf + rm -f /etc/mkinitcpio.conf.d/10-chwd-kms.conf +""" + +[nvidia-open-dkms.prime] +desc = 'Open source NVIDIA drivers for Linux laptops (Latest)' +priority = 11 +packages = 'nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader nvidia-prime switcheroo-control' +chassis_types = "8 9 10 11" post_install = """ - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - # nvidia-powerd is not supported by Turing GPUs - if ! lspci -d "10de:*:030x" -vm | grep -q 'Device:\\tTU.*'; then - systemctl enable nvidia-powerd - fi + # nvidia-powerd is not supported by Turing GPUs + if ! lspci -d "10de:*:030x" -vm | grep -q 'Device:\\tTU.*'; then + systemctl enable nvidia-powerd + fi - systemctl enable switcheroo-control + systemctl enable switcheroo-control - cat << 'EOF' >/etc/profile.d/nvidia-rtd3-workaround.sh + cat << 'EOF' >/etc/profile.d/nvidia-rtd3-workaround.sh # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. if [ -n "$(lspci -d "10de:*:0302")" ]; then export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json fi EOF - cat << 'EOF' | install -Dm755 /dev/stdin /usr/lib/systemd/user-environment-generators/20-nvidia-rtd3-workaround + cat << 'EOF' | install -Dm755 /dev/stdin /usr/lib/systemd/user-environment-generators/20-nvidia-rtd3-workaround #!/usr/bin/env sh # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. if [ -n "$(lspci -d "10de:*:0302")" ]; then echo "__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json" fi EOF - fi +""" +pre_install = """ + cat </etc/mkinitcpio.conf.d/10-chwd.conf +# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. +MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm) +EOF """ pre_remove = """ rm -f /etc/mkinitcpio.conf.d/10-chwd.conf - rm -f /etc/mkinitcpio.conf.d/10-chwd-kms.conf """ post_remove = """ rm -f /etc/profile.d/nvidia-rtd3-workaround.sh @@ -106,12 +107,6 @@ conditional_packages = """ kernel="$(cat "$pkgbase")" echo "${kernel}-headers" done - - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - echo "nvidia-prime switcheroo-control" - fi """ pre_install = """ cat </etc/mkinitcpio.conf.d/10-chwd.conf @@ -119,40 +114,47 @@ pre_install = """ MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm) EOF - # Remove kms hook from mkinitcpio.conf on desktops - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ! ((device_type >= 8 && device_type <= 11)); then - cat <<'EOF' >/etc/mkinitcpio.conf.d/10-chwd-kms.conf + cat <<'EOF' >/etc/mkinitcpio.conf.d/10-chwd-kms.conf # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. HOOKS=(${HOOKS[@]/kms/}) EOF - fi +""" +pre_remove = """ + rm -f /etc/mkinitcpio.conf.d/10-chwd.conf + rm -f /etc/mkinitcpio.conf.d/10-chwd-kms.conf +""" + +[nvidia-dkms-580xx.prime] +desc = 'Closed source NVIDIA drivers for Linux laptops (580xx)' +priority = 13 +packages = 'nvidia-580xx-dkms nvidia-580xx-utils nvidia-580xx-settings opencl-nvidia-580xx lib32-opencl-nvidia-580xx lib32-nvidia-580xx-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader nvidia-prime switcheroo-control' +chassis_types = "8 9 10 11" +pre_install = """ + cat </etc/mkinitcpio.conf.d/10-chwd.conf +# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. +MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm) +EOF """ post_install = """ - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - systemctl enable switcheroo-control + systemctl enable switcheroo-control - cat << 'EOF' >/etc/profile.d/nvidia-rtd3-workaround.sh + cat << 'EOF' >/etc/profile.d/nvidia-rtd3-workaround.sh # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. if [ -n "$(lspci -d "10de:*:0302")" ]; then export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json fi EOF - cat << 'EOF' | install -Dm755 /dev/stdin /usr/lib/systemd/user-environment-generators/20-nvidia-rtd3-workaround + cat << 'EOF' | install -Dm755 /dev/stdin /usr/lib/systemd/user-environment-generators/20-nvidia-rtd3-workaround #!/usr/bin/env sh # This file is automatically generated by chwd. PLEASE DO NOT EDIT IT. if [ -n "$(lspci -d "10de:*:0302")" ]; then echo "__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json" fi EOF - fi """ pre_remove = """ rm -f /etc/mkinitcpio.conf.d/10-chwd.conf - rm -f /etc/mkinitcpio.conf.d/10-chwd-kms.conf """ post_remove = """ rm -f /etc/profile.d/nvidia-rtd3-workaround.sh @@ -166,19 +168,14 @@ class_ids = "0300 0302 0380" vendor_ids = "10de" device_ids = '>/var/lib/chwd/ids/nvidia-470.ids' packages = 'nvidia-470xx-dkms nvidia-470xx-utils nvidia-470xx-settings opencl-nvidia-470xx vulkan-icd-loader lib32-nvidia-470xx-utils lib32-opencl-nvidia-470xx lib32-vulkan-icd-loader libva-nvidia-driver' -conditional_packages = """ - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - echo "nvidia-prime switcheroo-control" - fi -""" + +[nvidia-dkms-470xx.prime] +desc = 'Closed source NVIDIA drivers for Linux (470xx branch, only for mobile Kepler GPUs)' +priority = 15 +packages = 'nvidia-470xx-dkms nvidia-470xx-utils nvidia-470xx-settings opencl-nvidia-470xx vulkan-icd-loader lib32-nvidia-470xx-utils lib32-opencl-nvidia-470xx lib32-vulkan-icd-loader libva-nvidia-driver nvidia-prime switcheroo-control' +chassis_types = "8 9 10 11" post_install = """ - # Trying to determine the laptop - device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)" - if ((device_type >= 8 && device_type <= 11)); then - systemctl enable switcheroo-control - fi + systemctl enable switcheroo-control """ [nouveau] diff --git a/src/data.rs b/src/data.rs index 23ff0ff..aebc411 100644 --- a/src/data.rs +++ b/src/data.rs @@ -262,6 +262,15 @@ pub fn get_all_devices_of_profile(devices: &ListOfDevicesT, profile: &Profile) - return vec![]; } + if let Some(chassis_types) = &profile.chassis_types { + let chassis_type = fs::read_to_string("/sys/devices/virtual/dmi/id/chassis_type") + .expect("Failed to read chassis type"); + let chassis_type = chassis_type.trim(); + if !chassis_types.iter().any(|x| x == chassis_type) { + return vec![]; + } + } + for hwd_id in &profile.hwd_ids { let mut found_device = false; diff --git a/src/profile.rs b/src/profile.rs index 173338d..b22ee26 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -48,6 +48,7 @@ pub struct Profile { pub gc_versions: Option>, pub cpu_family: Option, pub cpu_models: Option>, + pub chassis_types: Option>, pub hwd_ids: Vec, } @@ -71,6 +72,7 @@ impl Default for Profile { gc_versions: None, cpu_family: None, cpu_models: None, + chassis_types: None, hwd_ids: vec![Default::default()], } } @@ -247,6 +249,7 @@ fn parse_profile(node: &toml::Table, profile_name: &str) -> Result { gc_versions: parse_whitespace_list(node, "gc_versions"), cpu_family: node.get("cpu_family").and_then(|x| x.as_str().map(str::to_string)), cpu_models: parse_whitespace_list(node, "cpu_models"), + chassis_types: parse_whitespace_list(node, "chassis_types"), }; if profile.cpu_models.is_some() && profile.cpu_family.is_none() { @@ -451,6 +454,9 @@ fn profile_into_toml(profile: &Profile) -> toml::Table { if let Some(cpu_models) = &profile.cpu_models { table.insert("cpu_models".to_owned(), cpu_models.join(" ").into()); } + if let Some(chassis_types) = &profile.chassis_types { + table.insert("chassis_types".to_owned(), chassis_types.join(" ").into()); + } let last_hwd_id = profile.hwd_ids.last().unwrap(); @@ -519,6 +525,7 @@ mod tests { assert_eq!(parsed_profiles[1].hwd_product_name_pattern, Some("(Ally)\\w+".to_owned())); assert_eq!(parsed_profiles[1].hwd_ids, hwd_ids); assert_eq!(parsed_profiles[1].gc_versions, None); + assert_eq!(parsed_profiles[1].chassis_types, None); assert!(!parsed_profiles[1].post_install.is_empty()); assert!(!parsed_profiles[1].post_remove.is_empty()); assert!(parsed_profiles[1].pre_install.is_empty()); @@ -559,6 +566,7 @@ mod tests { assert_eq!(parsed_profiles[0].hwd_product_name_pattern, None); assert_eq!(parsed_profiles[0].hwd_ids, hwd_ids); assert_eq!(parsed_profiles[0].gc_versions, None); + assert_eq!(parsed_profiles[0].chassis_types, None); assert!(!parsed_profiles[0].post_install.is_empty()); assert!(!parsed_profiles[0].post_remove.is_empty()); assert!(!parsed_profiles[0].pre_install.is_empty());