[SRU][canonical-kernel-snaps/main][PATCH 1/2] nvidia-hooks: add pc-kernel configure hook
Aaron Jauregui
aaron.jauregui at canonical.com
Sun Mar 30 22:27:03 UTC 2025
Add a configure hook to the pc-kernel snap to be able to switch between
installed graphics drivers on a system. Configure hook installs
components based off the nvidia-stream snap variable by pulling
nvidia-<nvidia-stream>-ko and nvidia-<nvidia-stream>-server. Setting
nvidia-stream to nouveau triggers a special case where only the
nouveau-ko component is installed. If components are already on the
system they are "loaded" into the graphics dir by rerunning their
install hook.
Signed-off-by: Aaron Jauregui <aaron.jauregui at canonical.com>
---
hooks/pc-kernel/configure.pc-kernel | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100755 hooks/pc-kernel/configure.pc-kernel
diff --git a/hooks/pc-kernel/configure.pc-kernel b/hooks/pc-kernel/configure.pc-kernel
new file mode 100755
index 0000000..7052286
--- /dev/null
+++ b/hooks/pc-kernel/configure.pc-kernel
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Configuration hook for selecting nvidia driver version
+
+nvidia_ver="$(snapctl get nvidia-stream)"
+
+# Do not install any components by default
+[ -z "$nvidia_ver" ] && exit 0
+
+set -eux
+
+install_component () {
+ compdir="/snap/$SNAP_NAME/components/$SNAP_REVISION"
+
+ # only install component if it does not exist, otherwise rerun install hook
+ if [ ! -d "$compdir/$1" ]; then
+ snapctl install "+$1"
+ else
+ comprev=$(basename "$(readlink "$compdir/$1")")
+ SNAP_COMPONENT_REVISION="$comprev" SNAP_COMPONENT_NAME="$SNAP_NAME+$1" SNAP_COMPONENT="$compdir/$1" "$compdir/$1/meta/hooks/install"
+ fi
+}
+
+
+if [ "$nvidia_ver" = "nouveau" ]; then
+ install_component "nouveau-ko"
+else
+ install_component "nvidia-$nvidia_ver-ko"
+ install_component "nvidia-$nvidia_ver-user"
+fi
--
2.43.0
More information about the kernel-team
mailing list