Improved graphics detection.

This commit is contained in:
Raphaël Numbus
2026-05-25 19:05:22 +02:00
parent 354b3a8aa8
commit 1eacc23288
+41 -44
View File
@@ -99,6 +99,11 @@ hardware_detection() {
ssh_to_host "nix-shell -p jq pciutils usbutils smartmontools iproute2 --run 'bash -s'" << SSHEND >> "${STDOUT}" 2>> "${STDERR}"
set -euo pipefail
if [[ ${DEBUG} -eq 1 ]]; then
mkdir -${MKDIR_FLAGS} "${STDOUT}"
mkdir -${MKDIR_FLAGS} "${STDERR}"
fi
# --- Initialize Global JSON Output ---
HW_REPORT=\$(jq -n '{}')
@@ -116,64 +121,54 @@ detect_graphics() {
local renderer
local product
for line in lspci | grep VGA; do
local pci_addr
OLD_IFS="\$IFS"
IFS=\$'n'
for line in \$(lspci | grep -e VGA -e 3D >> "${STDOUT}" 2>> "${STDERR}"); do
local pci_addr
pci_addr="\$(lspci | grep VGA | head -c 7)"
# Brand
for b in Intel AMD NVIDIA; do
if [[ echo "\${line}" | grep -i "\${b}" ]]; then
if echo "\${line}" | grep -i "\${b}" >> "${STDOUT}" 2>> "${STDERR}"; then
brand="\${b}"
fi
done
# Renderer info
renderer="\$(ls -lh /dev/dri/by-path | grep "\$pci_addr" | grep "render")"
if [[ -n "\${renderer}" ]]; then
renderer="${renderer##*render}"
renderer="render${renderer}"
else
renderer="none"
fi
# Product name
product="\${line#*:}"
product="\${product#*: }"
#
# Form factor
if [[ "\${brand}" == "NVIDIA" ]]; then
integrated="false"
fi
if [[ "\${brand}" == "Intel" ]]; then
if echo "\${line}" | grep -e "HD Graphics" -e "Xe"; then
integrated="true"
else
integrated="false"
fi
fi
if [[ "\${brand}" == "AMD" ]]; then
if echo "\${line}" | grep "Mobile"; then
integrated="true"
else
integrated="false"
fi
fi
done
# Iterate over all VGA and 3D controllers
while read -r pci_addr; do
local brand="Unknown"
local integrated="false"
local renderer=""
# Determine Brand
local vendor_info
vendor_info=\$(lspci -vms "\$pci_addr" | grep -i "^Vendor:" || true)
if echo "\$vendor_info" | grep -iq "intel"; then
brand="Intel"
integrated="true" # General heuristic for Intel
elif echo "\$vendor_info" | grep -iq "amd"; then
brand="AMD"
# If boot_vga is 1, it's likely the primary/integrated APU
if [[ -f "/sys/bus/pci/devices/0000:\$pci_addr/boot_vga" ]] && grep -q "1" "/sys/bus/pci/devices/0000:\$pci_addr/boot_vga"; then
integrated="true"
fi
elif echo "\$vendor_info" | grep -iq "nvidia"; then
brand="NVIDIA"
integrated="false" # NVIDIA is almost always discrete in these contexts
fi
# Find Renderer (e.g., renderD128)
if [[ -d "/sys/bus/pci/devices/0000:\$pci_addr/drm" ]]; then
renderer=\$(find "/sys/bus/pci/devices/0000:\$pci_addr/drm" -maxdepth 1 -name "renderD*" -exec basename {} \; | head -n 1)
[[ -n "\$renderer" ]] && renderer="/dev/dri/\$renderer"
fi
# Append to array
local gpu_obj
gpu_obj=\$(jq -n --arg b "\$brand" --arg r "\${renderer:-N/A}" --argjson i "\$integrated" \
'{brand: \$b, renderer: \$r, integrated: \$i}')
gpus=\$(echo "\$gpus" | jq --argjson obj "\$gpu_obj" '. += [\$obj]')
done < <(lspci -D | grep -iE 'VGA|3D' | awk '{print \$1}')
IFS="\${OLD_IFS}"
append_to_report "graphics" "\$gpus"
}
@@ -183,7 +178,7 @@ detect_corals() {
local corals="[]"
# Check PCIe Coral (Google ID 1ac1:089a)
if lspci -nn >> "${STDOUT}" 2>> "${STDERR}" | grep -iq "1ac1:089a"; then
if lspci -nn | grep -iq "1ac1:089a" >> "${STDOUT}" 2>> "${STDERR}"; then
local pcie_count
pcie_count=\$(lspci -nn | grep -ic "1ac1:089a")
for ((i=1; i<=pcie_count; i++)); do
@@ -348,6 +343,8 @@ echo "\$HW_REPORT" | jq '.' > "$TMPFILE"
SSHEND
scp -i "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" "${TARGET_USER}@${LIVE_TARGET_IP}":"${TMPFILE}" "${HW_DATA_FILE}" >> "${STDOUT}" 2>> "${STDERR}"
[[ ${DEBUG} -eq 1 ]] && scp -i "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" "${TARGET_USER}@${LIVE_TARGET_IP}":"${STDOUT}" "${INSTALL_DIR}/logs/hw_std.log" >> "${STDOUT}" 2>> "${STDERR}"
[[ ${DEBUG} -eq 1 ]] && scp -i "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" "${TARGET_USER}@${LIVE_TARGET_IP}":"${STDERR}" "${INSTALL_DIR}/logs/hw_err.log" >> "${STDOUT}" 2>> "${STDERR}"
if ssh_to_host "sudo nixos-generate-config --no-filesystems --show-hardware-config" > ${TMP_EXTRA_PATH}/etc/nixos/hardware-configuration.nix; then
echo -e "\n ✅ Hardware configuration generated"