We have a Yocto-based image, that has snapd and ships a bunch of snaps by default. Currently all snaps that we ship are downloaded from the Snap store by running
This works fine if we are pulling snaps from the snap store, but we want to be able to ship a snap that we built locally, something that we currently don’t publish to the snap store.
$ snap prepare-image --help
Usage:
snap prepare-image [prepare-image-OPTIONS] <model-assertion> <target-dir>
The prepare-image command performs some of the steps necessary for
creating device images.
For core images it is not invoked directly but usually via
ubuntu-image.
For preparing classic images it supports a --classic mode
[prepare-image command options]
--classic Enable classic mode to prepare a classic model image
--arch= Specify an architecture for snaps for --classic when the model does not
--channel= The channel to use
--snap=<snap>[=<channel>] Include the given snap from the store or a local file and/or specify the channel to track for the given snap
[prepare-image command arguments]
<model-assertion>: The model assertion name
<target-dir>: The target directory
So I now have another question, how can I “trick” snapd to automatically connect interfaces for snaps that I ship from files instead of downloading from store ?
For example I have a locally built snap that I “seed” into our image and want it to connect to the camera interface, how may I achieve that ?
The thing that controls how interfaces are auto-connected is a snap-declaration assertion. The assertion is signed by the store - so if your snap does not exist in the store, you will not have an assertion and auto connection at snap install time will not work.
Clearly, snapd only trusts the store’s private key (snapd has the corresponding public key to verify assertions) so signing the assertion yourself is unfeasible as well.
One thing you could do if you are using a gadget snap, is to use that to set up connections at image build / first boot time, rather than at install time. Someone from the snapd team might be able to confirm, I think this might allow you to connect without needing the assertion.
Look at the “connections” section in the gadget snap specification here : Gadget snaps
I need to talk this up with the “decision makers” in our team. I think we had a call with the Canonical sales team a while ago about this. IIRC the “X$ per device per year” model wouldn’t scale well for us (but I was not in that call).