When building a snap and constructing a part, package dependencies are listed as either package names or snaps for the snap’s build environment. This is covered in Build and staging dependencies.
For a default Snapcraft installation running Multipass, the build environment is invariably Ubuntu 22.04 LTS (Jammy Jellyfish) or Ubuntu 20.04 LTS (Focal Fossa). Consequently, dependencies are listed using their apt package names and are retrieved from the set of repositories officially supported by the distribution.
However, it’s also possible to add your own apt repositories as sources for build-packages
and stage-packages
, including those hosted on a PPA, the Personal Package Archive, which serves personally hosted non-standard packages.
Adding repositories
Third-party apt repositories can be added to a snap’s snapcraft.yaml by using the top-level package-repositories
keyword with either a PPA-type repository, or a deb-type repository:
package-repositories:
- type: apt
ppa: snappy-dev/snapcraft-daily
package-repositories:
- type: apt
components: [main]
suites: [xenial]
key-id: 78E1918602959B9C59103100F1831DDAFC42E99D
url: http://ppa.launchpad.net/snappy-dev/snapcraft-daily/ubuntu
As shown above, PPA-type repositories and traditional deb-type each require a different set of properties:
Once configured, packages provided by these repositories will become available via stage-packages
and build-packages
.
The properties for both PPA-type and deb-type repositories are outlined below.
PPA properties
The following properties are supported for PPA-type repositories:
- type (required): The type of package-repository, only apt is currently supported.
- ppa (required): PPA identifier string.
-
type
- Type: enum[string]
- Description: Specifies type of package-repository, must currently be
apt
- Examples:
type: apt
-
ppa
- Type: string
- Description: PPA shortcut string
- Format:
<ppa-owner>/<ppa-name>
- Examples:
ppa: snappy-devs/snapcraft-daily
ppa: mozillateam/firefox-next
Deb properties
The following properties are supported for Deb-type repositories:
- architectures: List of architectures to enable, or restrict to, for this repository.
- components (required if using suites): List of apt repository components to enable, e.g.
main
,multiverse
,unstable
. - formats: List of deb types to enable (
deb
and/ordeb-src
). - key-id (required): 40-character GPG key identifier / thumbprint.
- key-server: Key-server to request key from.
- path (required if not using suites & components): Exact path to repository, relative to URL.
- suites (required if not using path): List of apt suites to enable, e.g.
bionic
,focal
. - type (required): type of package-repository. Only
apt
is currently supported. - url (required): apt repository URL.
-
architectures
- Type: list[string]
- Description: Architectures to enable, or restrict to, for this repository
- Default: If unspecified, architectures is assumed to match the host’s architecture
- Examples:
architectures: [i386]
architectures: [i386, amd64]
-
components
- Type: list[string]
- Description: Apt repository components to enable: e.g.
main
,multiverse
,unstable
- Examples:
components: [main]
components: [main, multiverse, universe, restricted]
-
formats
- Type: list[string]
- Description: List of deb types to enable
- Default: If unspecified, format is assumed to be
deb
, i.e.[deb]
- Examples:
formats: [deb]
formats: [deb, deb-src]
-
key-id
- Type: string
- Description: 40 character GPG key identifier (" long-form thumbprint" or “fingerprint”)
If not using a key-server, Snapcraft will look for the corresponding key at:<project>/snap/keys/<key-id[-8:]>.asc
.
To determine a key-id from a given key file with gpg, type the following:
gpg --import-options show-only --import <file>
- Format: alphanumeric, dash
-
, and underscores_
permitted. - Examples:
key-id: 590CA3D8E4826565BE3200526A634116E00F4C82
Snapcraft will install a corresponding key at<project>/snap/keys/E00F4C82.asc
-
key-server
- Type: string
- Description: Key server to fetch key
<key-id>
from - Default: If unspecified, Snapcraft will attempt to fetch a specified key from keyserver.ubuntu.com
- Format: Key server URL supported by
gpg --keyserver
- Examples:
key-server: keyserver.ubuntu.com
key-server: hkp://keyserver.ubuntu.com:80
-
path
- Type: string
- Description: Absolute path to repository (from
url
). Cannot be used withsuites
andcomponents
- Format: Path starting with
/
- Examples:
path: /
path: /my-repo
-
priority
- Requires Snapcraft 7.4
- Type: enum[string] or int
- Description: Overrides the default behavior when picking the source for a particular package
- Format:
always
,prefer
ordefer
. Alternatively an int other than 0 - Notes: string equivalencies are
always
: 1000;prefer
: 990;defer
: 100 - Examples:
priority: always
priority: 1000
-
suites
- Type: string
- Description: Repository suites to enable
- Notes: If your deb URL does not look like it has a suite defined, it is likely that the repository uses an absolute URL. Consider using
path
- Examples:
suites: [xenial]
suites: [xenial, xenial-updates]
-
type
- Type: enum[string]
- Description: Specifies type of package-repository
- Notes: Must be
apt
- Examples:
type: apt
-
url
- Type: string
- Description: Repository URL.
- Examples:
url: http://archive.canonical.com/ubuntu
url: https://apt-repo.com/stuff
Examples
PPA repository using "ppa" property
package-repositories:
- type: apt
ppa: snappy-dev/snapcraft-daily
Typical apt repository with components and suites
package-repositories:
- type: apt
components: [main]
suites: [xenial]
key-id: 78E1918602959B9C59103100F1831DDAFC42E99D
url: http://ppa.launchpad.net/snappy-dev/snapcraft-daily/ubuntu
Apt repository enabling deb sources
package-repositories:
- type: apt
formats: [deb, deb-src]
components: [main]
suites: [xenial]
key-id: 78E1918602959B9C59103100F1831DDAFC42E99D
url: http://ppa.launchpad.net/snappy-dev/snapcraft-daily/ubuntu
Absolute path repository with implied root path "/"
package-repositories:
- type: apt
key-id: AE09FE4BBD223A84B2CCFCE3F60F4B3D7FA2AF80
url: https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64`
Absolute path repository with explicit path and formats
package-repositories:
- type: apt
formats: [deb]
path: /
key-id: AE09FE4BBD223A84B2CCFCE3F60F4B3D7FA2AF80
url: https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64`
Preferring packages from a PPA
package-repositories:
- type: apt
ppa: deadsnakes/ppa
priority: always