This is interesting, snap is another kind of container in itself, one that seems like it was developed for ubuntu phone's OS (not sure that turned out as expected) and thus is now being used more broadly. You really could sub out "snap" with another container technology:
The snap format is a single compressed filesystem that is mounted dynamically by the host operating system, together with declarative metadata that is interpreted by the snap system to set up an appropriately shaped secure sandbox or container for that application. The file format extension is .snap.
So in the same way you would have trouble running Docker or another Singularity while building without some kind of hack, this is likely to be the case (and I tested out your recipe and came to the same issues with not having control of those services). But it also means that there is likely just a dump of files and metadata that needs to happen, and if you can find another way to do that and get it into the container, this would work! Docker Hub has an API for the metadata and layers, and snap doesn't, but it can be used via your host.
So the direction I would go in, and have caution in doing this because it relies on your host, is to use snap as it was intended - as a package manager. I would try installing the snap in the %setup section (still working on your host) and then basically move it from host to container. Here is a little test I just did - here is what I can figure out.
snap is already installed on my host, install hello-world
snap install hello-world
snap list
Name Version Rev Developer Notes
core 16-2.31.1 4110 canonical core
hello-world 6.3 27 canonical -
Note if you do the above before install, it tells you that you don't have any, and you should install hello-world :) Next, get information about the snap
summary: The 'hello-world' of snaps
This is a simple hello world example.
snap-id: buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ
installed: 6.3 (27) 20kB -
refreshed: 2016-07-11 17:20:44 -0400 EDT
candidate: 6.3 (27) 20kB -
Ah I found a download command, let's try that. It looks like it will download to the directory I'm in, and I can't control output name.
$ mkdir dump && cd dump
$ snap download hello-world
Fetching snap "hello-world"
Fetching assertions for "hello-world"
Install the snap with:
snap ack hello-world_27.assert
snap install hello-world_27.snap
That could be informative if there is more than just the file structure. But actually if you want the snap contents, just look in the /snap folder:
tree /snap/hello-world/current
/snap/hello-world/current
├── bin
│ ├── echo
│ ├── env
│ ├── evil
│ └── sh
└── meta
├── gui
│ └── icon.png
└── snap.yaml
and the metadata is in the yaml file, as you would guess:
$ cat /snap/hello-world/current/meta/snap.yaml
name: hello-world
version: 6.3
architectures: [ all ]
summary: The 'hello-world' of snaps
description: |
This is a simple snap example that includes a few interesting binaries
to demonstrate snaps and their confinement.
* hello-world.env - dump the env of commands run inside app sandbox
* hello-world.evil - show how snappy sandboxes binaries
* hello-world.sh - enter interactive shell that runs in app sandbox
* hello-world - simply output text
apps:
env:
command: bin/env
evil:
command: bin/evil
sh:
command: bin/sh
hello-world:
command: bin/echo
So! This is good news I think, because you would basically install these snaps to your container by copying the contents from your host. You won't be able to interact with the service / daemon and use them as containers, but you should be able to interact with the extracted contents. And given a consistent structure, this very likely could be added as a base to bootstrap from (or a particular kind of other container to input). I would open an issue and ask for this feature if you think it is important, and others can discuss. In the meantime so you don't have to wait, you can add some basic logic/commands in your setup (on the host) to minimally "get the snap guts" into your container!
%setup
# snap is already installed on my host
snap install hello-world
# copy a snap directory to your container somewhere
SNAP_BASE=/snap/current
mkdir -p ${SINGULARITY_ROOTFS}$SNAP_BASE
# Copy hello-world
cp -R $SNAP_BASE/hello-world ${SINGULARITY_ROOTFS}$SNAP_BASE
or something like that :) I think it would be up to you to determine how to run the contents, since snap is likely not to work (unless the running bit doesn't require the package manager / service thing!) But since they give you an obvious "bin" I think it would be pretty easy to add that to a path. If you make it a SCIF app and install the snap to /scif/apps/hello-world for example, then the contents of the "bin" would automatically be on the PATH when you do a run with --app hello-world. That's pretty neat!
Good luck!
Best,
V