[SRU][kernel-snaps-uc24.04/pc][PATCH 2/2] snapcraft.yaml: Template support for Nvidia components
Aaron Jauregui
aaron.jauregui at canonical.com
Tue Jun 17 04:05:21 UTC 2025
BugLink: https://bugs.launchpad.net/bugs/2114786
Nvidia drivers will have changes in streams relatively often. The need
to shift along with the changes and updates in streams requires
significant changes to the snapcraft.yaml every time a new Nvidia
version is to be supported. This is further compounded by the need to
handle EOL cycles for Nvidia driver components. Snap does not have a
built-in concept of EOL or a mechanism to handle this case.
Shifting to a template-based model provides the flexibility required to
handle the problems listed above. Snapcraft is not malleable enough on
its own, and thus a preprocessing script handles the creation of Nvidia
component stanzas, along with stanzas for dummy EOL components.
If the preprocessing script is not run, the snapcraft.yaml is still
valid and will build as normal (assuming existing templated values are
resolved) with a nouveau component and no Nvidia driver components.
Nvidia components are read from nvidia_streams. Each line of
nvidia_streams contains either a single stream version, e.g.:
550
Or two version, indicating that the former is EOL and the latter should
be installed instead:
350 570
EOL components contain a single file named "eol" containing the
replacement stream number. The logic to handle installation of the new
driver components is handled by the configure hook. As of now, ERD
streams are assumed, but the existing scripts can be extended to handle
UDA streams relatively painlessly.
The current preprocessing script is intentionally simple, and provides
the minimum required functionality for Nvidia components as of now. It
is intended to be replaced rather than extended if this concept is
generalized beyond Nvidia drivers.
Signed-off-by: Aaron Jauregui <aaron.jauregui at canonical.com>
---
nvidia-templates/comp-tmpl | 11 ++++
nvidia-templates/eol-comp-tmpl | 9 +++
nvidia-templates/eol-part-tmpl | 19 +++++++
nvidia-templates/part-tmpl | 81 ++++++++++++++++++++++++++
nvidia_streams | 1 +
snapcraft.yaml | 101 ++++-----------------------------
snapcraft.yaml.gen | 37 ++++++++++++
7 files changed, 169 insertions(+), 90 deletions(-)
create mode 100644 nvidia-templates/comp-tmpl
create mode 100644 nvidia-templates/eol-comp-tmpl
create mode 100644 nvidia-templates/eol-part-tmpl
create mode 100644 nvidia-templates/part-tmpl
create mode 100644 nvidia_streams
create mode 100755 snapcraft.yaml.gen
diff --git a/nvidia-templates/comp-tmpl b/nvidia-templates/comp-tmpl
new file mode 100644
index 0000000..139d004
--- /dev/null
+++ b/nvidia-templates/comp-tmpl
@@ -0,0 +1,11 @@
+ nvidia- at MAJOR_VER@-erd-ko:
+ type: kernel-modules
+ summary: Nvidia @MAJOR_VER at -server kernel objects
+ description: Nvidia @MAJOR_VER at -server driver kernel objects for the Ubuntu generic kernel snap
+ version: @SWM:lrm@
+
+ nvidia- at MAJOR_VER@-erd-user:
+ type: standard
+ summary: Nvidia @MAJOR_VER at -server userspace libraries
+ description: Userspace libraries required by the Nvidia @MAJOR_VER at -server driver for the Ubuntu generic kernel snap
+ version: @SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
diff --git a/nvidia-templates/eol-comp-tmpl b/nvidia-templates/eol-comp-tmpl
new file mode 100644
index 0000000..a3b9398
--- /dev/null
+++ b/nvidia-templates/eol-comp-tmpl
@@ -0,0 +1,9 @@
+ nvidia- at MAJOR_VER@-erd-ko:
+ type: kernel-modules
+ summary: Nvidia @MAJOR_VER at -server kernel objects (EOL)
+ description: Nvidia @MAJOR_VER at -server driver kernel objects for the Ubuntu generic kernel snap. This version has reached EOL. Installing this will trigger installation of a newer driver version.
+
+ nvidia- at MAJOR_VER@-erd-user:
+ type: standard
+ summary: Nvidia @MAJOR_VER at -server userspace libraries (EOL)
+ description: Userspace libraries required by the Nvidia @MAJOR_VER at -server driver for the Ubuntu generic kernel snap. This version has reached EOL. Installing this will trigger installation of a newer driver version.
diff --git a/nvidia-templates/eol-part-tmpl b/nvidia-templates/eol-part-tmpl
new file mode 100644
index 0000000..0a1f2f1
--- /dev/null
+++ b/nvidia-templates/eol-part-tmpl
@@ -0,0 +1,19 @@
+ nvidia- at MAJOR_VER@-erd-ko-comp:
+ plugin: nil
+ override-build: |
+ craftctl default
+
+ echo "@REPLACEMENT_VER at -erd" > "$CRAFT_PART_INSTALL/eol"
+
+ organize:
+ eol: (component/nvidia- at MAJOR_VER@-erd-ko)/eol
+
+ nvidia- at MAJOR_VER@-erd-user-comp:
+ plugin: nil
+ override-build: |
+ craftctl default
+
+ echo "@REPLACEMENT_VER at -erd" > "$CRAFT_PART_INSTALL/eol"
+
+ organize:
+ eol: (component/nvidia- at MAJOR_VER@-erd-user)/eol
diff --git a/nvidia-templates/part-tmpl b/nvidia-templates/part-tmpl
new file mode 100644
index 0000000..7ec2d3f
--- /dev/null
+++ b/nvidia-templates/part-tmpl
@@ -0,0 +1,81 @@
+ nvidia- at MAJOR_VER@-erd-ko-comp:
+ source: https://git.launchpad.net/canonical-kernel-snaps
+ source-type: git
+ source-branch: main
+ plugin: nil
+
+ stage-packages:
+ - binutils
+ - make
+
+ override-build: |
+ craftctl default
+ version=$(craftctl get version)
+
+ # Duplicate libc causing conflicts, deleting to use system's libc
+ rm -f -- "$CRAFT_PART_INSTALL/usr/lib/$(uname -m)-linux-gnu/libc.so.6"
+ apt-get download linux-objects-nvidia- at MAJOR_VER@-server-"@SWM:version:abi@"-generic="@SWM:lrm@" \
+ linux-signatures-nvidia-"@SWM:version:abi@"-generic="@SWM:lrm@"
+ for i in *.deb; do dpkg-deb -x "$i" nvidia-objects ; done
+
+ mkdir -p "$CRAFT_PART_INSTALL"/bits
+ mv nvidia-objects/lib/modules/*/kernel/nvidia- at MAJOR_VER@srv/bits/* "$CRAFT_PART_INSTALL"/bits
+ # Move hooks
+ mv hooks/nvidia-ko/* "$CRAFT_PART_INSTALL"
+
+ organize:
+ bits/: (component/nvidia- at MAJOR_VER@-erd-ko)/bits
+ usr/bin: (component/nvidia- at MAJOR_VER@-erd-ko)/bin
+ usr/lib: (component/nvidia- at MAJOR_VER@-erd-ko)/lib
+
+ install.nvidia-ko: (component/nvidia- at MAJOR_VER@-erd-ko)/snap/hooks/install
+ post-refresh.nvidia-ko: (component/nvidia- at MAJOR_VER@-erd-ko)/snap/hooks/post-refresh
+ remove.nvidia-ko: (component/nvidia- at MAJOR_VER@-erd-ko)/snap/hooks/remove
+
+ nvidia- at MAJOR_VER@-erd-user-comp:
+ source: https://git.launchpad.net/canonical-kernel-snaps
+ source-type: git
+ source-branch: main
+ plugin: nil
+
+ override-build: |
+ craftctl default
+
+ # Move hooks
+ mv hooks/nvidia-user/* "$CRAFT_PART_INSTALL"
+
+ stage-packages:
+ - libnvidia-egl-wayland1=1:1.1.13-1build1
+ - libnvidia-cfg1- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-common- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-compute- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-decode- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-encode- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-extra- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-gl- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-fbc1- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - nvidia-utils- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - xserver-xorg-video-nvidia- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+ - libnvidia-extra- at MAJOR_VER@-server=@SWM:nvidia-graphics-drivers- at MAJOR_VER@-server@
+
+
+ organize:
+ usr/share: (component/nvidia- at MAJOR_VER@-erd-user)/usr/share
+ usr/lib: (component/nvidia- at MAJOR_VER@-erd-user)/usr/lib
+ usr/bin: (component/nvidia- at MAJOR_VER@-erd-user)/usr/bin
+ kernel-gpu-2404-provider-mangler: (component/nvidia- at MAJOR_VER@-erd-user)/kernel-gpu-2404-provider-mangler
+ install.nvidia-user: (component/nvidia- at MAJOR_VER@-erd-user)/snap/hooks/install
+ post-refresh.nvidia-user: (component/nvidia- at MAJOR_VER@-erd-user)/snap/hooks/post-refresh
+ remove.nvidia-user: (component/nvidia- at MAJOR_VER@-erd-user)/snap/hooks/remove
+
+ # Prune nvidia- at MAJOR_VER@-erd-user to prevent shipping duplicate mesa libraries
+ nvidia- at MAJOR_VER@-erd-user-cleanup:
+ after: [nvidia- at MAJOR_VER@-erd-user-comp]
+ source: https://github.com/canonical/gpu-snap.git
+ plugin: dump
+ override-prime: |
+ craftctl default
+ CRAFT_PRIME="$CRAFT_COMPONENT_NVIDIA_ at MAJOR_VER@_ERD_USER_PRIME" \
+ "$CRAFT_PART_SRC"/bin/gpu-2404-cleanup mesa-2404
+
+
diff --git a/nvidia_streams b/nvidia_streams
new file mode 100644
index 0000000..75e27a6
--- /dev/null
+++ b/nvidia_streams
@@ -0,0 +1 @@
+550
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 400fc8c..a0e6eb8 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -15,22 +15,23 @@ platforms:
arm64:
components:
- nvidia-550-erd-ko:
- type: kernel-modules
- summary: Nvidia 550-server kernel objects
- description: Nvidia 550-server driver kernel objects for the Ubuntu generic kernel snap
-
- nvidia-550-erd-user:
- type: standard
- summary: Nvidia 550-server userspace libraries
- description: Userspace libraries required by the Nvidia 550-server driver for the Ubuntu generic kernel snap
-
nouveau-ko:
type: kernel-modules
summary: Nouveau kernel module
description: The Nouveau kernel module for the Ubuntu generic kernel snap
+# Nvidia components will be inserted below by gen-nvidia-components.sh
+# This script looks at the nvidia_comps file and generates entries based
+# on the templates provided in the nvidia-templates/ directory.
+# Each entry in nvidia_comps corresponds with an nvidia driver major version.
+# If there are two entries in a line, the first entry is EOL and to be replaced
+# by the second.
+###NVIDIA-COMPS
+
parts:
+
+###NVIDIA-PARTS
+
kernel:
source: https://git.launchpad.net/canonical-kernel-snaps
source-type: git
@@ -119,86 +120,6 @@ parts:
plugin: dump
source: files
- nvidia-550-erd-ko-comp:
- source: https://git.launchpad.net/canonical-kernel-snaps
- source-type: git
- source-branch: main
- plugin: nil
-
- stage-packages:
- - binutils
- - make
-
- override-build: |
- craftctl default
- version=$(craftctl get version)
-
- # Duplicate libc causing conflicts, deleting to use system's libc
- rm -f -- "$CRAFT_PART_INSTALL/usr/lib/$(uname -m)-linux-gnu/libc.so.6"
- apt-get download linux-objects-nvidia-550-server-"@SWM:version:abi@"-generic="@SWM:lrm@" \
- linux-signatures-nvidia-"@SWM:version:abi@"-generic="@SWM:lrm@"
- for i in *.deb; do dpkg-deb -x "$i" nvidia-objects ; done
-
- mkdir -p "$CRAFT_PART_INSTALL"/bits
- mv nvidia-objects/lib/modules/*/kernel/nvidia-550srv/bits/* "$CRAFT_PART_INSTALL"/bits
- # Move hooks
- mv hooks/nvidia-ko/* "$CRAFT_PART_INSTALL"
-
- organize:
- bits/: (component/nvidia-550-erd-ko)/bits
- usr/bin: (component/nvidia-550-erd-ko)/bin
- usr/lib: (component/nvidia-550-erd-ko)/lib
-
- install.nvidia-ko: (component/nvidia-550-erd-ko)/snap/hooks/install
- post-refresh.nvidia-ko: (component/nvidia-550-erd-ko)/snap/hooks/post-refresh
- remove.nvidia-ko: (component/nvidia-550-erd-ko)/snap/hooks/remove
-
- nvidia-550-erd-user-comp:
- source: https://git.launchpad.net/canonical-kernel-snaps
- source-type: git
- source-branch: main
- plugin: nil
-
- override-build: |
- craftctl default
-
- # Move hooks
- mv hooks/nvidia-user/* "$CRAFT_PART_INSTALL"
-
- stage-packages:
- - libnvidia-egl-wayland1=1:1.1.13-1build1
- - libnvidia-cfg1-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-common-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-compute-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-decode-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-encode-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-extra-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-gl-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-fbc1-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - nvidia-utils-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - xserver-xorg-video-nvidia-550-server=@SWM:nvidia-graphics-drivers-550-server@
- - libnvidia-extra-550-server=@SWM:nvidia-graphics-drivers-550-server@
-
-
- organize:
- usr/share: (component/nvidia-550-erd-user)/usr/share
- usr/lib: (component/nvidia-550-erd-user)/usr/lib
- usr/bin/nvidia-smi: (component/nvidia-550-erd-user)/usr/bin/nvidia-smi
- kernel-gpu-2404-provider-mangler: (component/nvidia-550-erd-user)/kernel-gpu-2404-provider-mangler
- install.nvidia-user: (component/nvidia-550-erd-user)/snap/hooks/install
- post-refresh.nvidia-user: (component/nvidia-550-erd-user)/snap/hooks/post-refresh
- remove.nvidia-user: (component/nvidia-550-erd-user)/snap/hooks/remove
-
- # Prune nvidia-550-erd-user to prevent shipping duplicate mesa libraries
- nvidia-550-erd-user-cleanup:
- after: [nvidia-550-erd-user-comp]
- source: https://github.com/canonical/gpu-snap.git
- plugin: dump
- override-prime: |
- craftctl default
- CRAFT_PRIME="$CRAFT_COMPONENT_NVIDIA_550_ERD_USER_PRIME" \
- "$CRAFT_PART_SRC"/bin/gpu-2404-cleanup mesa-2404
-
slots:
diff --git a/snapcraft.yaml.gen b/snapcraft.yaml.gen
new file mode 100755
index 0000000..b305a9e
--- /dev/null
+++ b/snapcraft.yaml.gen
@@ -0,0 +1,37 @@
+#!/bin/bash
+set -eux
+
+comp_tmpl="$(cat nvidia-templates/comp-tmpl)"
+part_tmpl="$(cat nvidia-templates/part-tmpl)"
+
+# Loop over Nvidia component version list and generate
+# component definitions and parts block entries.
+# NOTE: Currently only allows ERD (-server) nvidia versions.
+# Support for UDA versions will need some tweaks to templates, as
+# they assume pulling <ver>-server debs.
+while read -r line; do
+ # intentionally ommit quotes to split line into args
+ # shellcheck disable=SC2086
+ set -- $line
+
+ #two version numbers imply an EOL version, any more are ignored
+ if [ "$(wc -w <<< "$line")" -gt 1 ]; then
+ echo "$1 EOL, pointing to $2"
+ comps+="$(sed -e "s/@MAJOR_VER@/$1/g" \
+ -e "s/@REPLACEMENT_VER@/$2/g" \
+ < nvidia-templates/eol-comp-tmpl)"$'\n'
+ parts+="$(sed -e "s/@MAJOR_VER@/$1/g" \
+ -e "s/@REPLACEMENT_VER@/$2/g" \
+ < nvidia-templates/eol-part-tmpl)"$'\n'
+ else
+ echo "$1 valid"
+ comps+="${comp_tmpl//@MAJOR_VER@/$1}"$'\n'
+ parts+="${part_tmpl//@MAJOR_VER@/$1}"$'\n'
+ fi
+done < nvidia_streams
+
+# template out snapcraft.yaml with components
+awk -i inplace -v c="$comps" -v p="$parts" \
+ '{gsub("###NVIDIA-COMPS",c); gsub("###NVIDIA-PARTS",p)}1' \
+ snapcraft.yaml
+
--
2.43.0
More information about the kernel-team
mailing list