Since the document is quite short, I decided to just copy it here:
Abstract
This document proposes to include in the CONTENT snaps (like gnome-42-2204) an extra script to the command-chain, allowing to incorporate changes in the environment variables directly in the snap, without having to send them to the snapcraft project.
Rationale
Modifying the CONTENT snaps (for example gnome-42-2204 snaps) or fixing bugs, usually require adding new environment variables. Currently this requires modifying either the snapcraft and/or the snapcraft-desktop-integration projects to modify the scripts that are included in the snaps, in the command-chain/desktop-launch file. This makes the process cumbersome because doing a change requires updating both the content snap and snapcraft repositories (and thus having to wait for both changes to be accepted), and the rebuild of the CONTENT snap with the new version of snapcraft.
The solution proposed consists in adding an extra, optional, script file in the contents snap itself, that, during launch time, is executed along with the old command chain. This would allow adding new variables to the runtime environment without having to rebuild the snapcraft snap and recompile the contents snap with the new version.
Specification
The contents snapcraft.yaml file would include a piece of code like this in the parts section:
include_script:
override-prime: |
craftctl default
mkdir -p meta/custom-chain
cp $CRAFT_PROJECT_DIR/custom-chain/run.sh meta/custom-chain/
This will copy the run.sh script into the meta/custom-chain folder of the snap, copied from the custom-chain folder in the project directory. This script is where all the desired custom commands should be added.
Now, a single change should be made in the snapcraft project to implement this, in the desktop/extensions/common/mark-and-exec file: at the end, just before the exec “$@” statement, this piece of code should be added:
if [ -f $SNAP_DESKTOP_RUNTIME/meta/custom-chain/run.sh ]; then
source $SNAP_DESKTOP_RUNTIME/meta/custom-chain/run.sh
fi
Calling the script with source means that it will be executed inside the current shell; thus any change done by it will be included in the current environment. It also makes the operation much faster, because no new process has to be launched.
That’s all 