When I download open-source snaps on Ubuntu 20.10 I cannot find their source code, even though they are free.
Can anyone tell me where their source code is?
When I download open-source snaps on Ubuntu 20.10 I cannot find their source code, even though they are free.
Can anyone tell me where their source code is?
To see the source code of a snap (that is how it was built), you can download the snap and inspect it.
For example, say you want to read the source code of gnome-system-monitor
snap. You can download the snap in your current directory using:
sudo snap download gnome-system-monitor
This command will download two files, gnome-system-monitor_148.snap
and gnome-system-monitor_148.assert
(the number represents the snap's version and it can be different than 148
).
Then, open Nautilus and go to the directory where the files are downloaded (it's the directory inside which you ran the above command). right-click the .snap
file, select to open it with the Archive Manager and navigate in the snap
directory in the Archive Manager window that opens. Finally double click the snapcraft.yaml
and manifest.yaml
to open them with your text editor. These files will show you how the snap package was built.
You can find some more info in this article: How to verify the source of a Snap package
.snap
file with "Archive manager". I can still check it with less ...
since it's just text, but it's huge (at the one I'm looking at is some 130Mb). The apt-get source ...
command is better. Snaps are not easy to work with...
– Alexis Wilke
Jun 01 '23 at 18:10
As mentioned by BeastOfCaerbannog, you can download the snap file like so:
mkdir <name>
cd <name>
snap download <name>
(Note: no need to use sudo ...
, this is just a download in your current directory.)
The download saves two files in your current folder: a .assert
and a .snap
. The filename also includes a version.
The .snap
file contains the actual binary snap, which includes a manifest with information about the source. That file is a compressed set of files found in a SquashFS file system. To see the list of files on newer systems, you can simply do:
less <name>_<version>.snap
That way you can verify that the files of interest exist.
To actually check the files, you need to mount the file system. mount
does require sudo
. I'm sure there are other ways to extract the data, but I find this one easy enough:
mkdir <name>.snap
sudo mount <name>_<version>.snap <name>.snap -t squashfs -o loop
Now all the files inside <name>.snap
are accessible like any file on your disks (well, except that they are read-only). The manifest
and snapcraft
can be read like so:
less docker.snap/snap/manifest.yaml
less docker.snap/snap/snapcraft.yaml
It looks like the manifest has links to the git
specifically used by this <name>
project. That's where you would find the source.
For example, for docker, I found these:
source: https://github.com/moby/moby.git
source: https://github.com/containerd/containerd.git
source: https://github.com/opencontainers/runc.git
source: https://github.com/NVIDIA/nvidia-container-toolkit.git
source: https://github.com/NVIDIA/libnvidia-container.git
source: https://github.com/docker/libnetwork.git
source: https://github.com/krallin/tini.git
source: https://github.com/docker/cli.git
source: https://github.com/docker/buildx.git
source: https://github.com/docker/compose.git