Can a snap package add files to a pre-existing|installed snaps files?

Suppose there is a snap package named ‘snap1’ that installs files that looks like

/snap/snap1/current/bin/run.sh
/snap/snap1/current/plugins/a
/snap/snap1/current/plugins/b
/snap/snap1/current/plugins/c

is it possible for a second snap package named ‘snap2’ to add a file to ‘snap1’ files? for example to add a file named ‘new_plugin_from_snap2’ into /snap/snap1/10/plugins? so if the user installed snap1 and snap2 they would have the following files

/snap/snap1/current/bin/run.sh
/snap/snap1/current/plugins/a
/snap/snap1/current/plugins/b
/snap/snap1/current/plugins/c
/snap/snap1/current/plugins/new_plugin_from_snap2

I am trying to port debian packages to the snap format and looking to mirror the above behavior of those debian packages in the snap world. I understand this sort of behavior is very “un snap like”

Yes it is possible! I will reply with details on how to do it tomorrow.

Not sure if this is what @zyga-snapd was going to show, but you can accomplish this with 2 technologies in snapd, the content interface and layouts. If snap1 is consuming the files but the files are located in snap2, you would first plug a content interface inside snap1 like this in the snapcraft.yaml for snap1:

plugs:
  plugin:
    content: plugin
    interface: content
    target: $SNAP_DATA/plugins

and then snap2 would expose a content interface slot like this in the snapcraft.yaml for snap2 (assuming the plugin files in snap2 are located in $SNAP/plugins):

slots:
  plugin:
    content: plugin
    interface: content
    read: [$SNAP/plugins]

Then when both snaps are installed you can connect the interfaces (put the plug in the slot) like so:

$ snap connect snap1:plugin snap2:plugin

And the files will show up in $SNAP_DATA/plugins for snap1. Then you can use layouts to map $SNAP_DATA/plugins to $SNAP/plugins/new_plugin_from_snap2 by adding the following to the snippet in the snapcraft.yaml for snap1:

layout:
  $SNAP/plugins/new_plugin_from_snap2:
    bind: $SNAP_DATA/plugins

I meant to show the source property that allows you to connect any number of plugins to one directory. Sorry for not having the time to do so yet.

Is there any documentation on the source property?

I tried to follow ijohnson example with no success so far.

I had a look at https://docs.snapcraft.io/content-interface but didn’t find this documented. I will look at fixing that.