Manifests v2 (preview)

version: 2 is the next manifest format. It's a preview and can still change until comtrya 0.13.0, so don't use it yet for manifests you depend on. Version 1 manifests keep working, and both versions can sit in the same manifest directory.

Version 2 lets you write less and need fewer command.run workarounds. In short:

Comtrya 0.12.0 and older refuse version: 2; 0.9.x and older ignore version and misread such a manifest. Migrating from version 1 lists what to change.

Templates per value

Version 1 renders the whole file with Tera and then parses the result. Version 2 parses the file first, checks the manifest's where, and then renders each value on its own:

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
where: os.name == "linux"
actions:
  - action: directory.create
    path: "{{ user.home_dir }}/bin"

  - action: command.run
    command: echo
    args: ["{{ variables.greeting }}, {{ user.name }}"]
    privileged: "{{ variables.as_root }}"
  • The file has to be valid YAML or TOML as it is, so quote values with templates: path: "{{ user.home_dir }}/bin".
  • A manifest whose where is false isn't rendered at all, so a template that only works on Linux can't fail on macOS. where conditions aren't templates; they read the contexts themselves.
  • An error names the value it's in, like actions[1].args[0]: ….
  • A value that is one template and nothing else becomes a number or a boolean when its field doesn't hold text, like privileged: "{{ variables.as_root }}" above, or chmod: "{{ variables.mode }}". Text fields keep the rendered text, so args: ["{{ variables.port }}"] stays "8080".
  • {% if %} and {% for %} work inside a value, but not around keys or actions: use where on the action, or a variant, instead.

One name per action and field

Version 1 knows several names for some actions and fields. Version 2 knows one, and an old name is an error that names the one to use:

Version 1 also takesVersion 2 only takes
cmd.runcommand.run
dir.copy, dir.create, dir.removedirectory.copy, directory.create, directory.remove
binary.gh, bin.github, bin.ghbinary.github
package.installed, package.repopackage.install, package.repository
source, target in file.copy, file.download, file.unarchive and file.linkfrom, to
sudoprivileged
repository in git.clonerepo_url
url in package.repositoryname

The schema shows every action and field under its one name. Values aren't affected: provider names like linux or privilege providers like doas work as before.

Variants set only what differs

In version 1, a variant is a complete action and repeats every field the action needs. In version 2, a variant sets only the fields that differ, and takes the others from its action:

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
  - action: package.install
    name: fd
    variants:
      - where: os.distribution == "Ubuntu"
        name: fd-find
  • A field the variant sets replaces the action's field whole; lists and maps aren't merged.
  • Which version applies is the same as in version 1: the first variant whose where is true, else the action itself.
  • title and continue_on_error belong to the whole action; a variant can't set them.

More in Variants.

Files next to the manifest

A source path that starts with ./ or ../ is relative to the manifest file, so a folder can hold a manifest and its files:

manifests/
  zsh/
    zsh.yaml
    zshrc
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
  - action: file.link
    from: ./zshrc
    to: "{{ user.home_dir }}/.zshrc"
  • A plain name, like from: zshrc, still looks in files/, as in version 1.
  • This works for file.copy, file.link, file.unarchive and directory.copy.
  • Comtrya reads every YAML and TOML file below the manifest directory as a manifest. If such a folder also holds YAML or TOML files that aren't manifests, like an app's own config, list them in ignore in Comtrya.yaml.
  • {{ manifest.dir }} and {{ manifest.name }} are the manifest's directory and name, in both versions.

title

title on an action is shown in the log instead of the generated summary:

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
  - action: package.install
    title: Shell tools
    list: [fd, ripgrep]

register

register: <name> on a command.run keeps what the command printed and how it exited. Later actions read it as registered.<name>.stdout, .stderr and .exit_code, in templates and in where:

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
  - action: command.run
    command: rustc
    args: [--version]
    register: rustc

  - action: command.run
    title: Say which Rust is installed
    command: echo
    args: ["{{ registered.rustc.stdout }}"]
    where: registered.rustc.exit_code == 0

The values are there for the later actions of the manifest and for the manifests that depend on it. A dry run runs no commands, so it skips actions that read registered.*. All rules in Registering the output.

Package states

state on package.install says whether a package is installed (present, the default), installed and up to date (latest), or removed (absent). It works in version 1 too:

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
  - action: package.install
    list: [fd, ripgrep]
    state: latest

  - action: package.install
    name: nano
    state: absent

Which providers support it, and how they find outdated packages: Packages.

Editor support

Version 2 has its own JSON schema, published at https://comtrya.dev/schema-v2.json. It knows only the version 2 names, title, register, variants that set only some fields, and templates in place of numbers or booleans.

For YAML (yaml-language-server):

# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions: []

For TOML (Taplo):

#:schema https://comtrya.dev/schema-v2.json
version = 2
actions = []