314 Words

Article by editor Leo [email protected]

The Linux distro I contribute to, Alpine Linux, uses build recipes called APKBUILDs. They are shell scripts but with context-aware variables that can affect the final result of package. APKBUILDs are subject to policies that only apply to Alpine Linux and its packaging system abuild.

Vim is a text editor used by many of our developers and users use for editing APKBUILDs. But while vim has a filetype for shellscripts, it is insufficient to provide syntax, plugins, indentation and other nice to have features that are specific to the context of an APKBUILD.

In light of that I took upon myself to write a complete implementation of a vim filetype for APKBUILDs.

Meet APKBUILD.vim.

The Whole Deal

APKBUILD.vim is a plugin for Vim and Neovim, that provides:

  1. Syntax Highlighting:
    1.1. Different colors for variables that affect abuild behavior.
    1.2. Error highlighting for invalid values inside abuild variables, like non-existent arches in arch. 1.4. Highlighting of secfixes: blocks, version identifiers and recognized security identifiers (CVE, XSA, etc).
    1.5. It is built on top of sh.vim. That means all the syntax highlighting of filetype=sh is still in place.
  2. Configuration:
    2.1. Sets correct textwidth of 80 columns.
    2.2: Sets noexpandtab as APKBUILD use tabs for indentation.
    2.3: Sets softtabstop to 0.
    2.4: Sets tabstop and shiftwidth to 4
  3. ALE Integration:
    3.1. Provides a script to run shellcheck with APKBUILD aware filtering and register it into ALE.
    3.2. Adds support for the linters apkbuild-lint and secfixes-check from atools and registers a handler for them.


Here are some comparisons of APKBUILDs with filetype=sh and filetype=APKBUILD:

Main block of variables used by abuild, notice that the variables that are from abuild have a different color than the ones normally used by shell.

Main block under filetype=apkbuild

Main block under filetype=sh

Comparison of secfixes, notice how the secfixes: declaration, the versions and the security identifiers are all highlighted.

Secfixes under filetype=apkbuild

Secfixes under filetype=sh

General comparison of Error highlighting.

Errors under apkbuild

Errors under sh