I would like to expose a license file of a third party library to the snap package and think I have to use the system-files interface. Here are the relevant parts of my snapcraft.yml:
command: desktop-launch $SNAP/bin/annotate.bin
I did connect the plug:
snap connect my-package:cm-license
But it does not seem to work. The file cannot be opened from within the application. I also tried to “–shell” into the application (snap run --shell my-package.annotate) and cannot see the file there (is this supposed to work?).
Sorry, my knowledge of debugging this is quite limited. I have seen people with similar questions e.g. seen post apparmor policies generated, bu t I have no idea how they did that.
Note my package is build and installed in devmode.
Are you trying to have your snap read the file
/opt/cm/etc/Licenses from the host system? Or is your snap trying to provide this file to another snap?
The former, so the file is already in place on the host system.
/opt is not something from the host that is mounted inside the snap’s mount namespace, so to access it, you need to go through the hostfs mount and adjust your system-files interface to:
Ok, I will give it a shot, thanks a ton! Since I was assuming that /opt is maybe “special” I had been doing a test with a file in /etc. But that didn’t work either. Isn’t that unexpected?
/etc should be available through system-files directly without going through the hostfs mount. If you are seeing issues with
/etc make sure that the interface is connected, plugged by all applicable apps in your snap in the snapcraft.yaml and finally that there are no warnings generated when you install the snap as sometimes it’s tricky to get the syntax for system-files correct.
If I use the hostfs mount - will the file actually be mapped to /opt/…? Because I really have no possibility to make the third party library look elsewhere for that file.
I have tried your suggestion and it does not show up in the location I need. It does show up in the hostfs location, but then again I think because of devmode, I have full access to that anyway (the same seems to hold for /etc).
Could I “layout” the file from the hostfs to the location I need?
I had such a good idea:
…but still no cigar
It just does not show up in that location.
You should be able to use layouts in combination with the system-files interface, which should work also in devmode if system-files isn’t working for you with something like this:
So I just made a stupid typo and the layout approach does work when done right
Regarding your suggestion: I tried that (albeit with bind-file not with symlink), but it complained that the mapped filename must begin with either $SNAP, $SNAP_COMMON or $SNAP_DATA.
So you can do something like you have originally with
and then have an configure hook like:
# resize the file to 0
truncate -s 0 $SNAP_COMMON/Licenses
# append the real content
cat /var/lib/snapd/hostfs/opt/ipg/etc/Licenses >> $SNAP_COMMON/Licenses
This won’t handle updates to that file automatically but it will get automatically updated whenever you do
snap set <your-snap> something=something-else (you will also need to stage-packages
coreutils to get
truncate because while it exists in the base snaps, it is not allowed for use by app snaps for some reason. Perhaps we can get that changed
Nice, configure hooks are something I have not used so far, thanks for the practical example. For now, I will go with manually copying the file to the the common folder.