Build configuration

Every snap project depends on a file called snapcraft.yaml, which is the recipe that instructs Snapcraft on how to build it. This page provides an overview of the major sections of a snapcraft.yaml file.

For practical guidance about how to approach this file and your snap project for the first time, see the Snapcraft checklist. For a reference with all the keys and values available for this file, see the snapcraft.yaml schema.

The snapcraft.yaml file can be organised into three main sections according to function:

  1. Top-level directives and information about the snap, which describe its base properties and publication details.
  2. App directives, which describe the execution, interfaces, and resources available to each app in the snap.
  3. Part directives, which describe how to import and build each required part of the snap.

Since the configuration is written in YAML, these sections are merely recommendations to make the file readable for humans. The order of the directives doesn’t affect the build process of Snapcraft.

Top-level directives

The first block of the configuration typically contains all the base settings for the snap, which can be roughly split into two categories:

  • Directives for the snap’s software base and runtime, such as the silicon architecture, platform, core libraries, packaging, runtime confinement, and development tooling.
  • Information about the snap itself, such as its name, version, contributors, and the publisher’s website, which is made public on its page on the Snap Store.

As an example, here are the first lines in snapcraft.yaml for the Hello World snap:

name: hello
base: core22
version: '2.10'
summary: GNU Hello, the "hello world" snap
description: |
  GNU hello prints a friendly greeting.
grade: stable
confinement: strict

App directives

The apps key declares the applications and services that the snap runs. For each app you can declare settings that control how each app is executed and which system resources it can access. Example settings include the path and parameters to run, the app’s environment variables, and other binaries that the app requires.

Continuing with Hello World as an example, here’s its apps key:

apps:
  hello:
    command: bin/hello

Part directives

The parts key details all of the upstream code components that contribute to the apps inside the snap. Every aspect of the part is managed here, such as its source, dependencies, and how it’s compiled. For a primer on parts, see Adding parts.

Cribbing from Hello World again, this is its parts key:

parts:
  gnu-hello:
    source: http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
    plugin: autotools

Further reading

You can pass certain environment variables to Snapcraft during build. See Environment variables that Snapcraft exposes for a list of them.

See Snapcraft advanced grammar to learn how to check for specific conditions for certain keys.


Last updated 3 months ago.