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

430. kpkg

kpkg is the package manager of KDOS. The build uses it to make every package from its port, and the same program is on every installed system and on the live medium, where it lists what is installed, checks the installed files against what was installed, removes packages, and builds and installs a port from the recipe tree at /ports. This page is about that second use, on a running machine. Updating the whole system is Updating; rebuilding a port with a recipe of your own is Local rebuilds and kdos march. What kpkg install does step by step is Anatomy of a kpkg install.

Installation

kpkg is not a port, because building a port needs it. The bootstrap step 120_kpkg.sh compiles it from src/system/kdos-kpkg and three of KDOS’s own libraries, and installs it into the root as /usr/bin/kpkg with four symbolic links to it; kpkg in Part III describes the step. No later phase rebuilds it, and no package database entry owns it, so kdos why /usr/bin/kpkg reports that no package provides it.

The five names, each dispatching on the name it was run under:

Name Does
kpkg The front end: every command below
kpkgadd Installs a package file that is already built
kpkgbuild Builds the port in the current directory into a package, and installs nothing
kpkgdel Removes packages
kpkgdepends Prints the resolved install order, and nothing else

Every image carries the recipe tree at /ports: each port’s kpkgbuild, build.sh and patches, ports/shelves, ports/sources.idx, ports/groups, and KDOS’s own programs under /ports/src, with no upstream source archive in it (105_ports stages it). The trust ring for prebuilt packages, /etc/kdos/keys/, comes from the base filesystem, fs/etc/kdos/keys/.

kpkg needs no service. It downloads sources with curl, which the curl port installs.

Configuration

/etc/kpkg.conf

Where kpkg finds ports and keeps its trees. The bootstrap step copies it into the root:

cp "$SRC"/kpkg.conf $SYSROOT/etc/kpkg.conf

script/phases/10_bootstrap/120_kpkg.sh, lines 66–66

The file is src/system/kdos-kpkg/kpkg.conf:

# Port repositories: the recipe tree every image carries at /ports, and the
# areas of src/ under it that hold ports of our own
PORT_REPO="${PORT_REPO:-/ports/core /ports/src/system /ports/src/art /ports/src/desktop /ports/src/daemons}"

# Package cache directories
SOURCE_DIR="${SOURCE_DIR:-/var/cache/kpkg/sources}"
PACKAGE_DIR="${PACKAGE_DIR:-/var/cache/kpkg/packages}"
WORK_DIR="${WORK_DIR:-/var/cache/kpkg/work}"

# Package database
PKGDB_DIR="${PKGDB_DIR:-/var/lib/kpkg/db}"

# Which files of a package an install places: `all`, every file (the build
# chroot, which compiles against the headers and libraries it installs), or
# `run`, the package without its development and documentation files, each
# left out listed in $PKGDB_DIR/.facets/<name>. The image's copy says `run`
# (70_image/017_stage.sh); `kdos update install --dev <port>` installs a port
# whole again
FACETS="${KPKG_FACETS:-all}"

src/system/kdos-kpkg/kpkg.conf

Every line is NAME="${VARIABLE:-default}", the variable named after the key but for FACETS, whose variable is KPKG_FACETS. kpkg reads it as a key and a value without running a shell, and the variable wins over the file, so one command can point kpkg somewhere else without editing anything:

PORT_REPO="/home/kdos/ports /ports/core" kpkg info foo

Each directory PORT_REPO names is searched for a port at <name>/ and one shelf down at <shelf>/<name>/, and the first directory holding the name wins. The keys and their limits are in /etc/kpkg.conf.

The file above says FACETS="${KPKG_FACETS:-all}", which is what the build uses. The image’s copy says run (The image stage): an install on the medium, or on a machine installed from it, leaves out each package’s headers, static libraries, CMake and pkg-config files, man sections 0, 2 and 3 and its manuals under /usr/share/doc, info and gtk-doc. See Development files.

The package database

/var/lib/kpkg/db/ is written only by kpkg itself, as it installs and removes packages. Do not edit it by hand. For each installed package it holds <name> (the version and release, then every path the package owns), and .recipe/<name>, .pkgsha/<name>, .files/<name> and .needs/<name> (what its files need at run time) beside it, and .facets/<name> for a package installed without its development and documentation files; The database entry shows the five files of one package, and /var/lib/kpkg/ says what each file and the lock beside them hold.

/etc/kdos/keys/

The keys kpkg accepts a signature from, for a binary host’s index and for a package’s own .sig. The image ships the directory with no key in it, only its description:

Trusted package-signing keys.

Every `*.pub` in this directory is a key this machine will accept a signature
from — for the binhost index (PACKAGES.sig) and for a package's own `.sig`
sidecar. Adding a key is copying a file in; removing trust is deleting one.
There is no revocation list and no online check: the directory IS the policy.

    kpkg keygen builder          # on the machine that builds
    cp builder.pub /etc/kdos/keys/   # on every machine that should trust it

A key id (16 hex characters, printed by kpkg) identifies a key. It is NOT a
credential: a signature file names the id so a person can be told which key
signed, and verification always uses the key from THIS directory.

THE IMAGE SHIPS ITS OWN BUILD'S TWO KEYS HERE: kdos-binhost.pub, which signs
its release's binhost, and kdos-release.pub, which signs the release index
and the slot image. Both come from the same build that made this image, so
trusting them is trusting whoever built the image, which booting the image
already is. They verify the release index, the binhost index (PACKAGES.sig),
each prebuilt package's .sig and the slot image's manifest, and nothing from
another builder. Delete them and this machine takes no prebuilt package and
no slot image; it still builds every port from source, whose integrity comes
from the `sha256 =` lines of its recipe. Add another builder's .pub to trust
that binhost too.

`packs/` IS SHIPPED WITH A KEY, and it is a different question. kdos-packd
checks an application pack's own signature, or a signed pack index (PACKAGES)
beside the packs being imported, against it. Nothing the build makes is signed
with that key and the build does not hold its secret half, so on a fresh system
it verifies nothing; add the `.pub` from `kdos-pack keygen` to trust packs you
sign yourself. It is a subdirectory because a keyring is a flat read of
`*.pub`: a key that vouches for a pack must not thereby vouch for a package
repository.

`tree/` holds the key that signs a published ports tree, which
`kdos update fetch` installs as /ports. The build puts its release key's public
half there; tree/README says how. It is a subdirectory for the same reason.

fs/etc/kdos/keys/README

The two subdirectories, packs/ and tree/, are separate rings that kpkg does not read; they belong to Packs and Updating.

Environment variables

The settings that change what kpkg does, rather than where its trees are, are read from the environment only. Two matter on a running machine: KPKG_FETCH=1, which lets a build download the sources it lacks, and KPKG_REQUIRE_SIG=1, which refuses any package file without a good signature. KPKG_CONF names another configuration file and KPKG_KEYRING another trusted-key directory. kpkg binhost also reads the compiler variables CC, CFLAGS, CXXFLAGS, LDFLAGS and KDOS_TARGET; see Using a binary host. Every variable is in the table under kpkg; the image sets none of them.

Usage

Every command that changes the root runs as root. The ones that only read it do not, except where a file they read is root’s own.

Seeing what is installed

  1. List every installed package with its version and release:

    kpkg list
    kpkg list --json
  2. Show one package. For an installed package this is its version, release, licence and file count; for one that is not installed, the recipe’s description, licence and depends = list, and Status: not installed:

    kpkg info zlib
    Package: zlib
    Version: 1.3.2-1
    License: Zlib
    Files: 19
  3. Find the package that owns a file. kdos why reads the database’s own file lists and prints the package, its version and its recipe, then any reason the system records for that path:

    kdos why /usr/bin/xz

    A path no package owns is reported as none — provided by fs/ or 10_bootstrap, or not installed: the base filesystem is copied into the image rather than installed by a package, and kpkg and kinstall are compiled by 10_bootstrap and are not packages either. The manifest itself can be searched too:

    grep -lx './usr/bin/xz' /var/lib/kpkg/db/*
  4. Print a recipe’s metadata as shell assignments, expanded:

    kpkg meta xz

Checking the installed files

kpkg check compares the root with what was installed: every path a package’s manifest lists, and the SHA-256 and mode of every regular file it placed.

  1. Check one package, or all of them:

    sudo kpkg check openssh
    sudo kpkg check --all
  2. Read the findings. missing, changed and mode lines are faults and make the exit status 1; a config line is a file under /etc that someone edited, and an unowned line (with --all) is a file under /usr or /opt that no package claims. Neither of the last two changes the exit status. A package that is not installed, or a usage error, exits 2. Every line but an unowned one names the package first, and the last line counts them:

    libvirt: config ./etc/libvirt/qemu/networks/default.xml
    unowned ./usr/bin/kpkg
    2107 packages checked: 0 missing, 0 changed, 0 mode, 25 config, 73 unowned

    That is the freshly booted image, and it exits 0. The image leaves out the build’s logs and caches but carries every directory a package claims under /var/log and /var/cache, empty (110_iso), so none of them is missing. Its config lines are libvirt’s network and filter files under /etc/libvirt, which libvirtd rewrites at its first start, so they differ from their recorded hashes; the unowned ones include kpkg and kinstall themselves. The meaning of each line is in Checking an installed root.

  3. Check another root, such as a mounted second slot, with --root:

    sudo kpkg check --all --root /mnt/slot-b
  4. Print only the faults and the summary with --brief, and keep every line in a file with --log <file>. --brief leaves the config and unowned lines off the terminal and still counts them in the summary; neither option changes the exit status. kdos update apply checks a slot this way, with its list in /var/log/kdos-update-check.log:

    sudo kpkg check --all --brief --log /tmp/check.log --root /mnt/slot-b

Development files

The image installs each package without the files only a build or a reader of manuals uses, and lists what it left out of each one.

  1. See what a package was installed without:

    kpkg facets --list zlib
    dev ./usr/include/zconf.h
    dev ./usr/include/zlib.h
    dev ./usr/lib/libz.a
    dev ./usr/lib/libz.so
    dev ./usr/lib/pkgconfig/zlib.pc
    dev ./usr/share/man/man3/zlib.3

    A package installed with every file prints zlib: every facet installed.

  2. Bring them back. kdos update install --dev installs the package again, whole, from the release’s binary host, and it stays whole across updates; a group name restores each member:

    sudo kdos update install --dev zlib
  3. Strip them again, from one package or, with no name, from every package:

    sudo kpkg facets --strip zlib
    ==> zlib: 6 files left out, 261K
    ==> facets: 1 package stripped, 267579 bytes (261K) freed

The rules, and the files each keeps a running program from losing, are in Facets.

What a package needs at run time

Each install records what the package’s files need at run time: the libraries its programs link, the interpreters its scripts name, the QML modules and Python packages they import, and what its recipe’s runtime = line names.

  1. Print the record, and which installed package provides each line:

    kpkg needs --resolve kirigami
    qml QtQuick qt6-qtdeclarative
    qml org.kde.kitemmodels kitemmodels
    so libQt6Core.so.6 qt6-qtbase
    so libc.so musl

    A line ending (nothing) is an edge nothing installed provides, and the command then exits 1; (unowned) is a file no package claims.

  2. A package installed before records were kept prints no run-time needs recorded; measure it from its installed files, writing nothing:

    kpkg needs --scan zlib

What each kind of line is found in, and how the image uses the records to prove its base, is in Run-time needs.

Building and installing a port

On a running machine a port is built from /ports with its sources fetched over the network, because /ports holds no source archive. This needs the network, and it compiles on the machine against the headers and libraries of what it depends on, which the image left out (Development files): restore them first, as step 2 does.

The image carries only the base, and pv is not in it, so these steps work as written. An image built with KDOS_IMAGE=full carries every port, pv among them: remove it first with sudo kpkg remove pv. For a port that is installed, step 1 prints an empty line and step 4 prints Nothing to do. These steps are kpkg alone; kdos update install --source <port> does the same build and also records the port in the world set and its route in /var/lib/kdos/origin, so updates keep it and build it here again (see Installing software).

  1. Look at what would be built. kpkgdepends prints the install order, leaving out every package that is already installed, so with ncurses present it prints pv alone:

    kpkgdepends pv
  2. Install the build tools the base does not carry, binutils and make among them, and restore the development files of what pv compiles against: ncurses, which its recipe names, and musl, linux and gcc, which every compile reads. kpkg install refuses until they are back, and names them. --dev --deps pv restores that closure though pv itself is not installed:

    sudo kdos update install build-tools
    sudo kdos update install --dev --deps pv

    kdos update install --source pv does this step itself.

  3. Fetch the sources of the port. kpkg fetch takes each file the recipe hashes and the machine lacks from the KDOS source archive first and from the recipe’s own URL second, and keeps a copy in /var/cache/kpkg/sources only when it matches the recipe’s sha256 =:

    sudo kpkg fetch pv
    ==> Fetching pv-1.12.0.tar.gz from the archive (sources-1)

    It exits 0 when every source is present, 1 when one could not be had, and 3 when nothing could be reached at all. See Fetching sources on a machine.

  4. Build and install it. With KPKG_FETCH=1 the port, and each dependency built on the way, fetches whatever sources are still missing as kpkg reaches it:

    sudo env KPKG_FETCH=1 kpkg install pv

    The build’s output scrolls past, then ==> Package created: /var/cache/kpkg/packages/pv-1.12.0-2.tar.xz, ==> Installing pv-1.12.0-2, and ==> Package 'pv' installed successfully. On an eight-thread virtual machine this takes about 12 seconds. --keep-cache keeps the package file for a later kpkgadd.

  5. Confirm the result:

    kpkg info pv
    kpkg check pv
    1 package checked: 0 missing, 0 changed, 0 mode, 0 config

On a running system an installed package counts as current whatever its recipe says, so kpkg install of an installed port prints Nothing to do and builds nothing. -f rebuilds the named ports; a dependency is built only when it is not installed, and the walk stops at an installed package, so nothing beneath one is built:

sudo env KPKG_FETCH=1 kpkg install -f pv

Removing a package

sudo kpkg remove pv

kpkg remove is kpkgdel. It removes the files in the package’s manifest that no other package claims, and every directory of it that is left empty. It also drops the package’s lines from the world set and the origin record, /var/lib/kdos/world and /var/lib/kdos/origin, so the next kdos update does not install it again. The removal reaches only the running root: if an update is already waiting in the other A/B slot, the package is still installed there, so run kpkg remove again after booting into it. It does not check reverse dependencies: kpkg remove bash removes bash. Before removing a library, list the recipes whose depends = names it:

awk '$1 == "depends" { for (i = 3; i <= NF; i++) if ($i == "zstd") print FILENAME }' \
    /ports/core/*/*/kpkgbuild /ports/src/*/*/kpkgbuild

Installing a prebuilt package

A package file built elsewhere, by kpkgbuild or kept in /var/cache/kpkg/packages by kpkg install --keep-cache, is installed with kpkgadd. Its name is <name>-<version>-<release>.tar.xz:

sudo kpkgadd /media/stick/pv-<version>-<release>.tar.xz

When a .sig file lies beside the package and /etc/kdos/keys/ holds a key, kpkgadd verifies it and refuses a package whose signature does not verify. A package with no .sig, or a .sig with no key in the ring to check it, is installed, unless KPKG_REQUIRE_SIG=1 is set, when it is refused with <file>: signature check FAILED — not installing.

Using a binary host

A binary host is a directory of prebuilt packages with a signed index, PACKAGES. A release’s binhost is the package repository of that release, and kdos update install installs from it with every dependency, recording what it installed (see Installing software); this section uses a binary host by hand, with kpkg alone. A build machine writes one to build/binhost/ with make build KDOS_MAKE_BINHOST=1, which 010_binhost indexes and signs, putting the public key beside the index as kdos-binhost.pub. A medium built with KDOS_ISO_SOURCES=1 as well carries that directory at /mnt/iso/sources/binhost.

  1. Have a public key for the index. For a binary host the build wrote, it is kdos-binhost.pub in the same directory. For a directory of packages of your own, make a key once and sign the index with it; kpkg keygen writes builder.key, mode 0600, and builder.pub into the current directory and prints the key’s id:

    kpkg keygen builder
    kpkg index /mnt/binhost --sign builder.key
  2. On each client, trust the key by copying its public half into the ring (builder.pub for a key of your own):

    sudo cp /mnt/binhost/kdos-binhost.pub /etc/kdos/keys/
  3. Check the index:

    kpkg verify-index /mnt/binhost
  4. Install a package from it, with the compiler variables the index was written under. The build-configuration hash kpkg binhost compares is taken from CC, CFLAGS, CXXFLAGS, LDFLAGS and KDOS_TARGET in its own environment, with the version $CC -dumpversion prints. A binary host the build wrote was indexed under script/env/chroot.env of the tree that built it, which sets CC=gcc and the three flag variables and leaves KDOS_TARGET unset. Export those values, copied from that file, and pass them through sudo:

    sudo env CC="$CC" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" \
        kpkg binhost /mnt/binhost zlib

    Typed at a shell with none of them set, every package is answered with ==> <name>: different build config (<hash>... vs <hash>...) — build from source.

kpkg binhost uses a package only when its architecture, its build-configuration hash and its recipe hash all equal this machine’s. It installs the one package named and nothing it depends on, and records the recipe hash it matched, as kpkg install records the hash of what it built. The full form is kpkg binhost [--root <path>] <dir> <port> [--dry-run] [--insecure]; --root installs into another root, as it does for kpkg install. An option it does not know, or a second port, is refused with exit 1. It exits 0 when it used the package, 1 when nothing matched (build from source instead), and 2 when it refused: no index (ERROR: no index at <dir>/PACKAGES), no trusted key, a failed verification, or a package whose checksum does not match the index. --dry-run says what it would do. As shipped the ring is empty, so until step 2 kpkg verify-index answers ERROR: no trusted keys in /etc/kdos/keys and exits 2. See The binary host and B: — the build-config hash.

On the live medium

kpkg works the same on the live medium, but the root it installs into is an overlay held in RAM, so everything it installs or removes is gone at power-off unless the medium has a persistence store (kdos persist; see kdos persist). A large build on the live medium also compiles into RAM: /var/cache/kpkg/work is on the same overlay.

Tips

Troubleshooting

sha256 MISMATCH for <file>
The copy of a source does not hash to the recipe’s sha256 =. Delete it from /var/cache/kpkg/sources and fetch it again with sudo kpkg fetch <port>. A second mismatch means the archive and upstream both serve a different file from the one the recipe names.
ERROR: Source not found: <file> (checked /ports/core/<shelf>/<name> and /var/cache/kpkg/sources)
The build reached a port whose source is not on the machine, and KPKG_FETCH=1 was not set, so it did not download it. Run sudo kpkg fetch <name>, or repeat the install with sudo env KPKG_FETCH=1. A dependency that has to be built on the way, for example under --root into an empty root, stops the same way.
No sha256 for <file> in the recipe
The recipe names a source it gives no hash for, and kpkg refuses to unpack it. The recipe is wrong; see Checksums.
kpkg fetch exits 3
Nothing could be reached. Check the network with nmcli general status and try again.
kpkg fetch exits 1
Neither the archive nor the recipe’s upstream URL gave a copy with the recipe’s hash. The file has to come from somewhere else, such as a medium built with KDOS_ISO_SOURCES=1, which holds every source beside its recipe under /mnt/iso/sources/ports/core/<shelf>/<name>/; copy it into /var/cache/kpkg/sources.
ERROR: File conflict detected
The package holds a path another installed package owns. kpkg takes such a path only when the recipe names the owner in replaces =; see Who owns a file. Find the owner with kdos why <path>.
Nothing to do
Every port named is installed, and on a running system that is enough. Add -f to rebuild it.
ERROR: <port> builds against <pkg>, installed without its development files
The image left out the headers and libraries the build needs. Run the sudo kdos update install --dev <pkg>... the message names, then the install again. See Development files.
ERROR: Build failed
Read the build’s output above the line; the unpacked source is still in /var/cache/kpkg/work/<name>/. A build on a running machine does not get the compiler flags the tree’s build sets; see Local rebuilds and kdos march.
kpkg check reports changed files under /usr
Something wrote over a package’s file. Rebuild that package with sudo env KPKG_FETCH=1 kpkg install -f <name>, and find what wrote it before trusting the root.
A kpkg install or kpkg remove waits and never finishes
Another kpkgadd or kpkgdel holds the database’s lock, /var/lib/kpkg/db/.lock. Find it with pgrep -a kpkg. An install hook that runs kpkg itself waits on its own installer for ever.

Known gaps

See also