The kde-neon extension

The kde-neon extension helps developers to create snaps that use Qt 5, with or without the add-on KDE Frameworks 5 libraries.

:information_source: Snapcraft extensions simplify and streamline the process of adding commonly used elements to a snap, such as libraries, themes and environment variables. See Snapcraft extensions for further details.

The extension is maintained and supported for use with the core22 base snap. Whilst older versions of the extension are still available for core20 and core18, these bases are no longer actively supported.

Base Versions Platform snap Build snap
core22 Qt 5.15.11 and KDE Frameworks 5.113 kf5-5-113-qt-5-15-11-core22 kf5-5-113-qt-5-15-11-core22-sdk

The kde-neon extension is designed for C++ based Qt/KDE Frameworks applications. It does not provide the bindings needed for Qt for Python (PySide2) nor PyQt applications. In addition, the extension does not provide all of the optional Qt 5 libraries; for example, it does not include Qt3D, QtCharts, QtDataVisualization or QtGamepad.

How to use it

To use the extension, add the extensions keyword with the value kde-neon to each app defined in your snapcraft.yaml file. For example:

apps:
  kcalc-example:
    command: usr/bin/kcalc
    extensions:
      - kde-neon
    ...

See Qt 5 and KDE Frameworks applications for an example of how to use this extension to build a Qt 5 and KDE Frameworks 5 based application.

Interface connections

The extension connects your snap to the following run-time content snaps:

The extension achieves this by adding the following plugs to your snapcraft.yaml at build time:

plugs:
    desktop:
        mount-host-font-cache: false
    icon-themes:
        interface: content
        target: $SNAP/data-dir/icons
        default-provider: gtk-common-themes
    sound-themes:
        interface: content
        target: $SNAP/data-dir/sounds
        default-provider: gtk-common-themes
    kf5-5-113-qt-5-15-11-core22:
        content: kf5-5-113-qt-5-15-11-core22-all
        interface: content
        default-provider: kf5-5-113-qt-5-15-11-core22
        target: $SNAP/kf5

In addition, the following plugs are added to each app that includes the kde-neon extension entry:

apps:
  <app name>:
    ...
    plugs:
      - desktop
      - desktop-legacy
      - opengl
      - wayland
      - x11
    ...

See Adding interfaces for more details.

Included packages

The kde-neon extension depends on two separate snaps: a build snap and a platform/content snap.

The build snap ensures that the relevant Qt 5 and KDE Frameworks development libraries and supporting files are available during the build process. These libraries are sourced from the Ubuntu-based KDE neon Linux distribution, which provides more recent versions of Qt 5 and the KDE Frameworks than are available in the core22 software archive.

The platform snap makes the corresponding run-time libraries available to your snap when it is launched by your users. If the platform snap isn’t already present on a user’s machine, then it will be installed automatically and simultaneously with the kde-neon extension based snap.

By relying on a standalone platform snap, developers can avoid bundling the Qt/KDE Frameworks libraries in their snap, keeping the file size of the snap to a minimum. The same installation of the platform snap can be used by multiple snaps that rely on the kde-neon extension.

The build environment

The kde-neon extension defines the PATH, XDG_DATA_DIRS and SNAPCRAFT_CMAKE_ARGS build-time environment variables by adding a build-environment section to each of your snap’s build parts:

build-environment:
-   PATH: /snap/kf5-5-113-qt-5-15-11-core22-sdk/current/usr/bin${PATH:+:$PATH}
-   XDG_DATA_DIRS: $CRAFT_STAGE/usr/share:/snap/kf5-5-113-qt-5-15-11-core22-sdk/current/usr/share:/usr/share${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}
-   SNAPCRAFT_CMAKE_ARGS: -DCMAKE_FIND_ROOT_PATH=/snap/kf5-5-113-qt-5-15-11-core22-sdk/current${SNAPCRAFT_CMAKE_ARGS:+:$SNAPCRAFT_CMAKE_ARGS}

You can override these defaults and/or define other build-time environment variables on a part-by-part basis by adding your own build-environment sections to snapcraft.yaml.

The run time environment

The extension also sets various run-time environment variables.

Most of these variables are set at launch by a command-chain shell script named desktop-launch:

apps:
  <app name>:
    ...
    command-chain:
    - snap/command-chain/desktop-launch
    ...

This shell script is added to the snap by a build part named kde-neon/sdk:

parts:
  kde-neon/sdk:
      source: /snap/snapcraft/current/share/snapcraft/extensions/desktop/kde-neon
      plugin: make
      make-parameters:
      - PLATFORM_PLUG=kf5-5-113-qt-5-15-11-core22
      build-snaps:
      - kf5-5-113-qt-5-15-11-core22-sdk

This part assembles the desktop-launch script from the following component scripts:

In addition to running the desktop-launch script at run time, the extension sets SNAP_DESKTOP_RUNTIME using an environment parameter:

environment:
  SNAP_DESKTOP_RUNTIME: $SNAP/kf5

Layout

The extension sets the following layout:

layout:
  /usr/share/X11:
    symlink: $SNAP/kf5/usr/share/X11

Hooks

The extension defines a configure hook that runs a script named hooks-configure-desktop upon installation of the snap, every time the snap is refreshed, and whenever the user changes a configuration option using snap set or snap unset:

hooks:
  configure:
    plugs:
    - desktop
    command-chain:
    - snap/command-chain/hooks-configure-desktop

The hooks-configure-desktop script is a copy of this fonts script.

3 Likes

A notable observation: the kde-frameworks-5-core18 snap ships the KDE Plasma platform theme. The developer may want to prevent loading said theme by setting QT_QPA_PLATFORMTHEME to something not kde for whatever reason, e.g. an incompatibility with the application.

However, the KDE Plasma platform theme will still be loaded if the snap’s being run in a KDE session. The env variables XDG_CURRENT_DESKTOP and KDE_FULL_SESSION affect whether this platform theme is loaded.

A possible solution is to incorporate a wrapper script that unsets said env vars:

if [ ! -z "$KDE_FULL_SESSION" ]; then
  unset KDE_FULL_SESSION
fi

if echo "$XDG_CURRENT_DESKTOP" | grep -q KDE; then
  unset XDG_CURRENT_DESKTOP
fi
1 Like

Thanks! Out of curiosity; what is the reason you use this in your snap?

qelectrotech looks hideous with this theme and also freezes after a while, so the decision was obvious.

1 Like

This does not seem to work on arm64, I suppose because the required kde-frameworks-5-core18 snap is not available on arm64. I filed a bug to note this: https://bugs.launchpad.net/snapcraft/+bug/1881963

3 Likes

The version described above is outdated, the current version that should be used is:

Brilliant, thank you - and thanks for formatting the new link perfectly for copying and pasting!

1 Like

It appears that the core20 and core22 variants support ARM64 as well, as depicted on the store listing page:

Good spot, thanks for letting us know!

1 Like

Please note: Core18 and Core20 is not supported. Until we find a way / manpower to support multiple bases, this is the way of it. Also our current supported setup is core22 -> kf5-5-108-qt-5-15-10-core22-sdk

Thanks

Thanks for the update. I’ve edited the Supported extensions page to reflect this.

1 Like

Using the kde-neon extension seems to prevent QtCharts from being found by cmake. Any idea why?

I have libqt5charts5-dev as a build-package, and it’s found when I build the snap without the kde-neon extension. (i.e. only change is adding kde-neon as an extension). Is there an additional build-snap needed for QtCharts?

Can you share the snap manifest? Probably this is the reason of that issue

https://github.com/canonical/snapcraft/blob/main/snapcraft/extensions/kde_neon.py#L118

The root is changed when using kde-neon & cmake

The root is changed when using kde-neon & cmake

Ok, thanks.

I’ve tried various combinations of -DQt5_DIR and -DQt5Charts_DIR (Also needed to use -DQt5Gamepad_DIR and DQt5TextToSpeech_DIR as they appear to be missing from the snap too), and although it can now build, I get various run-time problems (Missing symbols, GL driver loader failures, WebEngine resources missing) depending the options used and what files I strip from the application’s snap.

Will see if I can just use the desktop-launch script from the snap, without the rest.

If possible kindly share the manifest with us.

The .yaml is here: https://pastebin.com/ss5SKNsc - thanks.

This is for a build that seems to mostly work, without using kde-neon extension. For the kde-neon version, see the commented lines - and I’d also remove the qt build/stage packages.

I found that I needed to use layout in the .yaml to overlay the qt5 directories, rather than use environment variables and a qt.conf as in the kde-neon desktop-launch script. With the latter, Qt WebEngine would crash, not being able to find resources. It just seemed to ignore QTWEBENGINE_RESOURCES_PATH, regardless of what it was set to.

Also, Qt location isn’t working. I get ‘org.freedesktop.DBus.Error.AccessDeniedAn AppArmor policy prevents this sender from sending this message to this recipient; to’ … ‘org.freedesktop.GeoClue2.Manager’. I have location-observe plug, but ‘snap connect sdrangel:location-observe’ gives ‘error: snap “snapd” has no “location-observe” interface slots’

I just want to say a a huge thank you to userMaximilian (Maximilian) · GitHub for updating this document as part of their work on a task in the Open Documentation Academy.

1 Like