diff --git a/system_files/nvidia/usr/lib/systemd/system/ublue-nvidia-flatpak-runtime-sync.service b/system_files/nvidia/usr/lib/systemd/system/ublue-nvidia-flatpak-runtime-sync.service new file mode 100644 index 0000000..2b6a3fa --- /dev/null +++ b/system_files/nvidia/usr/lib/systemd/system/ublue-nvidia-flatpak-runtime-sync.service @@ -0,0 +1,14 @@ +[Unit] +Description=Sync NVIDIA system drivers with Flatpak runtime +After=network-online.target flatpak-system-helper.service +Wants=network-online.target +ConditionPathExists=/proc/driver/nvidia/version + +[Service] +Type=oneshot +ExecCondition=/usr/libexec/ublue-nvidia-flatpak-runtime-sync check +ExecStart=/usr/libexec/ublue-nvidia-flatpak-runtime-sync sync +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/system_files/nvidia/usr/libexec/ublue-nvidia-flatpak-runtime-sync b/system_files/nvidia/usr/libexec/ublue-nvidia-flatpak-runtime-sync new file mode 100755 index 0000000..64c658c --- /dev/null +++ b/system_files/nvidia/usr/libexec/ublue-nvidia-flatpak-runtime-sync @@ -0,0 +1,29 @@ +#!/usr/bin/bash + +set -euo pipefail + +SYSTEM_NVIDIA_VERSION=$(head -1 /proc/driver/nvidia/version | grep -oP '\d+\.\d+\.\d+') +FLATPAK_NVIDIA_VERSION=$(echo "${SYSTEM_NVIDIA_VERSION}" | tr '.' '-') + +case "${1}" in + check) + # Exit 0 if sync is needed (versions mismatch), exit 1 if already in sync + if flatpak info --system org.freedesktop.Platform.GL.nvidia-"${FLATPAK_NVIDIA_VERSION}" >/dev/null 2>&1 && \ + flatpak info --system org.freedesktop.Platform.GL32.nvidia-"${FLATPAK_NVIDIA_VERSION}" >/dev/null 2>&1; then + echo "NVIDIA Flatpak runtime ${SYSTEM_NVIDIA_VERSION} already installed" + exit 1 + fi + echo "NVIDIA Flatpak runtime ${SYSTEM_NVIDIA_VERSION} needs to be installed" + exit 0 + ;; + sync) + echo "Installing NVIDIA Flatpak runtime version ${SYSTEM_NVIDIA_VERSION}" + flatpak install --noninteractive flathub \ + org.freedesktop.Platform.GL.nvidia-"${FLATPAK_NVIDIA_VERSION}" \ + org.freedesktop.Platform.GL32.nvidia-"${FLATPAK_NVIDIA_VERSION}" + ;; + *) + echo "Usage: $0 {check|sync}" + exit 1 + ;; +esac