The snapcraft.yaml schema

The snapcraft.yaml file is the main entry point to create a snap through Snapcraft. It contains all the details the snapcraft command needs to build a snap.

:information_source: See Snapcraft checklist for an overview of the typical project details needed before creating snapcraft.yaml.

In general, snapcraft.yaml can be organised into three main sections:

1. top-level metadata, containing values, such as name, typically used by the store:

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

2. apps detailing how apps and services are exposed to the host system:

apps:
  hello:
    command: bin/hello

3. and parts to describes how to import, and potentially build, each required part of the snap:

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

For further details on the metadata contained within each of the above sections, see one of the following:

  1. Snapcraft top-level metadata
  2. Snapcraft app and service metadata
  3. Snapcraft parts metadata

A set of environment variables is also available during the build process. See Environment variables that Snapcraft exposes for further details.

Additionally, see Snapcraft.yaml reference for a complete overview of the metadata supported by snapcraft.yaml, and Snapcraft advanced grammar to learn how to check for specific conditions for certain YAML keys.

3 Likes

Note that you can, as the last resort, check out the schema in the source tree: snapcraft/snapcraft.json at master · snapcore/snapcraft.

1 Like

That schema is not relevant for Snapcraft 7.

This should have a title change to state snapcraft.yaml format rather than simply snapcraft format. Even better might be to replace format with syntax or schema in addition to adding .yaml. Snapcraft itself is a tool, which does not have a “format”. The configuration file that it consumes, snapcraft.yaml is the thing that has a format!

I haven’t done this myself, as I am wary that changing the title might change the URL and therefore the links from the contents/navigation post, which is rightly locked from my access, so I might break the docs site by doing the change myself without the consequent change to the contents doc.

Thanks so much for this suggestion, and I think you’re absolutely right. I’ll do a quick audit of what it might involve across the docs/links, but I think we should change this page to The snapcraft.yaml schema. I’ll do the same for The snap format.

1 Like

I don’t think SC7 uses that JSON file anymore for schema; AIUI, the new definition for snapcraft.yaml grammar is here, https://github.com/snapcore/snapcraft/blob/main/snapcraft/projects.py. But I’m not absolutely sure.

Snapcraft is still using (and updating) that schema. It’s particularly useful to validate your yaml files before you save them via an editor like VSCode.

The last sentence is not accurate – that JSON file no longer defines the current schema for Snapcraft, it’s defined by a number of Python files.

Thanks. I’ve removed this reference for now.