Changes to the script. Removed the IDs, now in a dedicated ids-database branch.
This commit is contained in:
+151
-121
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p bash coreutils gnugrep gum
|
||||
#!nix-shell -i bash -p bash coreutils gnugrep gum git pciutils
|
||||
#
|
||||
# Based on https://wiki.debian.org/NvidiaGraphicsDrivers?action=AttachFile&do=view&target=nvidia-versions.sh
|
||||
#
|
||||
@@ -18,13 +18,22 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
|
||||
gum style --border-foreground="030" --bold --border=normal --padding="0 2" "GPU detection tool for NixOS"
|
||||
# Avoid cryptic failure when running dash on this script
|
||||
shopt -s compat31 nocasematch 2>/dev/null || { echo "Error: this script only works with bash." && exit; }
|
||||
|
||||
# Defining variables
|
||||
USER_ID="$(id -u)"
|
||||
PCI_IDS_LOCATION="/run/user/${USER_ID}/gpu-detect"
|
||||
declare -A args=(
|
||||
["brand"]="all"
|
||||
["hw_accel"]="true"
|
||||
)
|
||||
|
||||
|
||||
gum style --border-foreground="030" --bold --border=normal --padding="0 2" "GPU detection tool for NixOS"
|
||||
|
||||
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1}" in
|
||||
--brand|-b)
|
||||
@@ -45,138 +54,159 @@ while [[ $# -gt 0 ]]; do
|
||||
esac
|
||||
done
|
||||
|
||||
shopt -s compat31 nocasematch 2>/dev/null || { echo "Error: this script only works with bash." && exit; } # Avoid cryptic failure when running dash on this script
|
||||
gpu_detect() {
|
||||
# Get the PCI IDs from the repo
|
||||
if [[ ! -d "${PCI_IDS_LOCATION}" ]]; then
|
||||
mkdir -p "${PCI_IDS_LOCATION}"
|
||||
git clone -q -b ids-database https://gittea.dev/numbus/gpu-detect.git "${PCI_IDS_LOCATION}"
|
||||
else
|
||||
if ! git -C "${PCI_IDS_LOCATION}" pull; then
|
||||
echo "Directory ${PCI_IDS_LOCATION} is not empty and does not"
|
||||
echo "contain the repository. Please check the folder clean up manually."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# last time the PCI IDs were updated
|
||||
LATEST="#VERSION#"
|
||||
PACKAGE=
|
||||
RET=1
|
||||
amd_detect() {
|
||||
|
||||
NV_DETECT() {
|
||||
}
|
||||
|
||||
intel_detect() {
|
||||
|
||||
}
|
||||
|
||||
nvidia_detect() {
|
||||
PCI_ID=${1}
|
||||
NVIDIA_VERSION=""
|
||||
local NVIDIA_TEXT="""
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
hardware.graphics = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs; [ ${EXTRA_PACKAGES} ];
|
||||
};
|
||||
services.xserver.videoDrivers = [ "nvidia" ];
|
||||
hardware.nvidia = {
|
||||
modesetting.enable = true;
|
||||
nvidiaSettings = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.${NVIDIA_VERSION};
|
||||
|
||||
# Unsupported options
|
||||
powerManagement.enable = false;
|
||||
powerManagement.finegrained = false;
|
||||
open = false;
|
||||
};
|
||||
}
|
||||
"""
|
||||
local VERSIONS=("unsupported" "legacy_340" "legacy_390" "legacy_470" "legacy_580" "current")
|
||||
|
||||
for version in ${VERSIONS[@]}; do
|
||||
if grep -q -i "${PCI_ID}" "${PCI_IDS_LOCATION}/nvidia/${version}.ids" 2>/dev/null; then
|
||||
NVIDIA_VERSION="${version}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "${NVIDIA_VERSION}" ]]; then
|
||||
echo "Uh oh. It seems that your card couldn't be detected."
|
||||
echo "A newer driver may add support for your card later."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "${NVIDIA_VERSION}" == "unsupported" ]]; then
|
||||
echo "Good news! You have nothing to do, your card runs with the"
|
||||
echo "\"nouveau\" driver that is integrated in the kernel."
|
||||
echo ""
|
||||
echo "It seems you have a very old card!"
|
||||
echo "The proprietary NVIDIA drivers have been removed from Nixpkgs"
|
||||
echo "therefore it is not possible to install them."
|
||||
elif [[ "${NVIDIA_VERSION}" == "legacy_340" || "${NVIDIA_VERSION}" == "legacy_390" || "${NVIDIA_VERSION}" == "legacy_470" ]]; then
|
||||
echo "An official legacy NVIDIA driver release is available for"
|
||||
echo "your card."
|
||||
echo ""
|
||||
echo "You can add the following code snippet to your NixOS configuration"
|
||||
echo "in order to enable the proprietary NVIDIA driver with VDPAU support."
|
||||
EXTRA_PACKAGES="\"libvdpau\""
|
||||
echo ${NVIDIA_TEXT}
|
||||
elif [[ "${NVIDIA_VERSION}" == "legacy_580" ]]; then
|
||||
echo "An official legacy NVIDIA driver release is available for"
|
||||
echo "your card."
|
||||
echo ""
|
||||
echo "You can add the following nix code to your NixOS configuration"
|
||||
echo "in order to enable the proprietary NVIDIA driver with VDPAU and"
|
||||
echo "VAAPI (if applicable) support."
|
||||
EXTRA_PACKAGES="\"nvidia-vaapi-driver\" \"libvdpau\""
|
||||
echo ${NVIDIA_TEXT}
|
||||
elif [[ "${NVIDIA_VERSION}" == "current" ]]; then
|
||||
echo "An official stable NVIDIA driver release is available for"
|
||||
echo "your card."
|
||||
echo ""
|
||||
echo "You can add the following nix code to your NixOS configuration"
|
||||
echo "in order to enable the proprietary NVIDIA driver with hardware"
|
||||
echo "acceleration support."
|
||||
echo """
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
hardware.graphics = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs; [ ${EXTRA_PACKAGES} ];
|
||||
};
|
||||
services.xserver.videoDrivers = [ "nvidia" ];
|
||||
hardware.nvidia = {
|
||||
modesetting.enable = true;
|
||||
nvidiaSettings = true;
|
||||
open = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.${NVIDIA_VERSION};
|
||||
|
||||
# Advanced options, tweak if needed
|
||||
powerManagement.enable = false; # Experimental: Enable this if you have graphical corruption issues or application crashes after waking up from sleep.
|
||||
powerManagement.finegrained = false; # Experimental: Turns off GPU when not in use
|
||||
};
|
||||
}
|
||||
"""
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
NVGA=${1}
|
||||
IDLISTDIR=/usr/share/nvidia
|
||||
local VERSIONS
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-71xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[71]=71.86
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-96xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[96]=96.43
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-173xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[173]=173.14
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-304xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[304]=304.123
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-340xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[340]=340.76
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-390xx.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[390]=390.87
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-legacy-390xx-amd64.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[391]=390.87
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-tesla-418.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[418]=418.87.01
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-tesla-470.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[470]=470.57.02
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-tesla-535.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[535]=535.216.01
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia-open.ids 2>/dev/null
|
||||
then
|
||||
VERSIONS[990]=515.48.07
|
||||
fi
|
||||
|
||||
if grep -q -i $NVGA $IDLISTDIR/nvidia.ids 2>/dev/null
|
||||
then
|
||||
# 999 means current
|
||||
VERSIONS[999]=$LATEST
|
||||
fi
|
||||
if [ -z "${1}" ]; then
|
||||
|
||||
|
||||
if [[ ${#VERSIONS[*]} == 0 ]]; then
|
||||
echo "Uh oh. Your card is not supported by any driver version up to $LATEST."
|
||||
echo "A newer driver may add support for your card."
|
||||
echo "Newer driver releases may be available in backports, unstable or experimental."
|
||||
return
|
||||
fi
|
||||
NV_DEVICES=$(lspci -mn | awk '{ gsub("\"",""); if ((${2} ~ "030[0-2]") && ($3 == "10de" || $3 == "12d2")) { print ${1} } }')
|
||||
|
||||
if [ -z "$NV_DEVICES" ]; then
|
||||
echo "No NVIDIA GPU detected."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Detected NVIDIA GPUs:"
|
||||
for d in $NV_DEVICES ; do
|
||||
lspci -nn -s $d
|
||||
done
|
||||
|
||||
for d in $NV_DEVICES ; do
|
||||
echo -e "\nChecking card: $(lspci -s $d | awk -F: '{print $3}')"
|
||||
nvidia_detect "$(lspci -mn -s "$d" | awk '{ gsub("\"",""); print $3 $4 }')"
|
||||
done
|
||||
|
||||
else
|
||||
|
||||
for id in "$@" ; do
|
||||
PCIID=$(echo "$id" | sed -rn 's/^(10de)?:?([0-9a-fA-F]{4})$/10de\2/ip')
|
||||
if [ -z "$PCIID" ]; then
|
||||
echo "Error parsing PCI ID '$id'."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Checking driver support for PCI ID [$(echo $PCIID | sed -r 's/(....)(....)/\1:\2/')]"
|
||||
nvidia_detect "$PCIID"
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "$PACKAGE" ]; then
|
||||
echo "It is recommended to install the"
|
||||
echo " $PACKAGE"
|
||||
echo "package."
|
||||
RET=0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
if [ -z "${1}" ]; then
|
||||
|
||||
if ! (lspci --version) > /dev/null 2>&1; then
|
||||
echo "ERROR: The 'lspci' command was not found. Please install the 'pciutils' package." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NV_DEVICES=$(lspci -mn | awk '{ gsub("\"",""); if ((${2} ~ "030[0-2]") && ($3 == "10de" || $3 == "12d2")) { print ${1} } }')
|
||||
|
||||
if [ -z "$NV_DEVICES" ]; then
|
||||
echo "No NVIDIA GPU detected."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Detected NVIDIA GPUs:"
|
||||
for d in $NV_DEVICES ; do
|
||||
lspci -nn -s $d
|
||||
done
|
||||
|
||||
for d in $NV_DEVICES ; do
|
||||
echo -e "\nChecking card: $(lspci -s $d | awk -F: '{print $3}')"
|
||||
NV_DETECT "$(lspci -mn -s "$d" | awk '{ gsub("\"",""); print $3 $4 }')"
|
||||
done
|
||||
|
||||
else
|
||||
|
||||
for id in "$@" ; do
|
||||
PCIID=$(echo "$id" | sed -rn 's/^(10de)?:?([0-9a-fA-F]{4})$/10de\2/ip')
|
||||
if [ -z "$PCIID" ]; then
|
||||
echo "Error parsing PCI ID '$id'."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Checking driver support for PCI ID [$(echo $PCIID | sed -r 's/(....)(....)/\1:\2/')]"
|
||||
NV_DETECT "$PCIID"
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit $RET
|
||||
|
||||
Reference in New Issue
Block a user