[SRU][canonical-kernel-snaps/main][PATCH 1/2] nvidia-hooks: add pc-kernel configure hook

Juerg Haefliger juerg.haefliger at canonical.com
Tue Apr 15 08:39:37 UTC 2025


On Mon, 31 Mar 2025 09:27:03 +1100
Aaron Jauregui <aaron.jauregui at canonical.com> wrote:

> 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.

This sounds like a new feature? Is there an LP bug this? 


> 
> 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

This could be a symlink, no? Is 'test -d' safe to use on a symlink that
points at a directory?


> +		snapctl install "+$1"

Curious, what's the significance of the '+' here?


> +	else
> +		comprev=$(basename "$(readlink "$compdir/$1")")

Hm. Is "$compdir/$1" guaranteed to always be a symlink?

It would help if you could show a sample directory layout in the commit
message, to understand what the tree looks like and which entries are
symlinks.


> +		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"

Curly braces would make it more readable IMO:

install_component "nvidia-${nvidia_ver}-ko"

...Juerg


> +fi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20250415/79c03476/attachment.sig>


More information about the kernel-team mailing list