Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

88.18. yq-4.53.6

Portable YAML / JSON / TOML / XML processor (Go, Mike Farah)

Version 4.53.6, release 1
Shelf formats — Data-format and serialisation libraries (XML, JSON, YAML, TOML, INI, RDF, protobuf, thrift), plus data query and convert tools
Phase 41_system (System), 548 of 1047 in build order
Licence MIT
Homepage https://github.com/mikefarah/yq
Build time 0.5 SBU
Installed size 14.9 MiB in 6 files
Recipe ports/core/formats/yq/kpkgbuild

About

yq is Mike Farah’s command-line processor for YAML, JSON, TOML, XML, HCL, INI, CSV, TSV and properties files, with a jq-like expression language: yq '.services.web.image' compose.yaml reads a value, and -i edits a file in place, keeping its comments. It is a single Go binary, built without cgo. jq is the JSON tool; yq is the one for the formats jq cannot read.

Sources

Dependencies

Depends on: go, lowdown.

Required by: no port names it.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install yq'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/formats/yq.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/formats/yq
echo '132a28a669526f99dba52486ac80de3bdafdf9a1a52a0c6bd6045301aca0cd25  yq-4.53.6.tar.gz' | sha256sum -c -
echo 'caaa21fe0025ba2eca353f9d4982b55edb6808fc6c0cbdba5b95cc110146741f  yq-vendor-4.53.6.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/yq
SRC=$SRC_ROOT/yq-4.53.6
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf yq-4.53.6.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz

export CGO_ENABLED=0
go build -mod=vendor -ldflags "-s -w" -o yq
install -Dm755 yq $PKG/usr/bin/yq
./yq completion bash > yq.bash
./yq completion zsh  > _yq
./yq completion fish > yq.fish
install -Dm644 yq.bash $PKG/usr/share/bash-completion/completions/yq
install -Dm644 _yq     $PKG/usr/share/zsh/site-functions/_yq
install -Dm644 yq.fish $PKG/usr/share/fish/vendor_completions.d/yq.fish
bash scripts/generate-man-page-md.sh
lowdown -s -Tman -M title=YQ -M section=1 -M "author=Mike Farah" -o yq.1 man.md
install -Dm644 yq.1 $PKG/usr/share/man/man1/yq.1

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/yq, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf yq-4.53.6-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/yq, and runs the triggers its paths call for.

Contents

Installed programs: yq.

Installed directories: /usr/share/licenses/yq.

Notes

The manual page is built in two steps: upstream’s scripts/generate-man-page-md.sh concatenates pkg/yqlib/doc/operators/headers/Main.md, the top-level how-it-works.md, and the operator and usage pages from pkg/yqlib/doc into one man.md, and lowdown -s -Tman turns it into yq.1.

The shell completions are written by running the freshly built ./yq completion bash|zsh|fish, so they always match the binary. The Go modules come from the vendor bundle, yq-vendor-<version>.tar.xz, made by go mod vendor and pinned by its own sha256 = line (see Vendoring).