Skip to the text
KDOS
Menu

Packaging

This chapter describes how software on the KDOS host is organised, fetched, built, installed, verified and updated. It is written for administrators who want to know what kpkg does to their machine, and for contributors who are about to add or change a port and want to understand the machinery around the recipe. It assumes the overview in Architecture overview; the recipe format itself, key by key, is in Writing ports, and the end-to-end story of a build, from a fresh clone to a bootable image, is in How KDOS is built. How this packaging compares with other distributions’ is in How KDOS differs.

It starts with the ports tree and how its recipes are grouped into build phases, then follows a source archive from the network to the port directory, through the package manager kpkg, into an installed package. It then covers what a build checks, how the build decides what to rebuild, how packages are made reproducible, the signed binary host, binary deltas, the signed images of a whole root slot, updating a running machine, installing more software on it, and vulnerability tracking.

If you administer a KDOS machine and do not build it, the sections you need most are Updating a machine, Installing more software, Groups, Checking an installed root and Vulnerability tracking; the rest explains the machinery behind them.

The natively ported graphical applications, Chromium and LibreOffice among them, are ports like any other and are packaged this way, and so is the whole desktop: KDE Frameworks, Plasma and every KDE Gear application are ports built from KDE’s release tarballs. The applications in the box catalogue are not: they ship as read-only images run in a sandbox, a separate system described in Packs and boxes.

The ports tree

A port is a directory that describes how to build one piece of software. A recipe is the pair of files that make up that description, and a package is what building a port produces: an archive that kpkg installs and records. Every program on the KDOS host, the compiler and the kernel included, is built from a port, except kpkg itself, which the bootstrap compiles before any recipe can be read (see The recipes under src/).

The build that turns ports into a system runs in numbered phases, from 00_cross to 70_image. From 20_selfhost onwards each runs inside the build chroot: the directory tree holding the system built so far, which the build enters as its root. The phases are introduced under Phases, package lists and shelves, and run as described in The build system.

What a port holds

A port holds two files:

File What it is
kpkgbuild Declarative metadata: name, version, release, sources, hashes, dependencies. Parsed, never run as a script
build.sh The build. Ordinary bash, run with the working directory set to the unpacked source

A port may also carry a postinstall.sh hook, .patch files, and small files committed beside the recipe: upstream patch-level files such as bash53-001, data files such as the IANA registries, and local files such as the kernel configuration linux/kdos.config. The upstream archives and vendor bundles a recipe names sit beside it once make fetch has run, but git does not track them; see Where sources come from.

The split into two files is deliberate. Because the metadata is parsed rather than executed, reading a recipe runs no shell, so querying a thousand recipes is as cheap and as safe as reading a thousand configuration files. Because the build is a real script, syntax checking, shellcheck, highlighting and diffing all work on it, and no parser has to tell a heredoc in the build apart from the metadata’s own syntax. Decisions gives the reasoning in full.

A recipe’s depends = line is the only dependency list. It names every port that must be installed before this one builds, and serves as the runtime dependency list as well; a recipe has no separate list of build-only dependencies. What is build-only is said once for the whole tree, by ports/buildonly: the ports a build needs and a running system does not, which the base image’s closure does not follow (see The base image).

Repositories and shelves

There are five port repositories, all in the same format, searched in this order:

Repository (inside the build chroot) In the tree Recipes What it holds
/ports/core ports/core/ 2,402 Upstream software, filed on 102 shelves
/kdos/src/system src/system/ 8 KDOS’s own kdos command and tools, the packer, the box runtime, its init and its Wayland socket holder, the installer, and the two books: kdos-doc, the KDOS book on the image, and kdos-kfs, KDOS from Scratch, which is not on the image and installs with sudo kdos update install kdos-kfs
/kdos/src/art src/art/ 8 KDOS’s own theme generator, icon themes, wallpapers, sounds, login screen, boot splash, offline add-ons and demo
/kdos/src/desktop src/desktop/ 21 KDOS’s own Plasma code and data: the global themes and Plasma style, the settings pages, widgets, KWin effects and scripts, the KRunner runner, the Discover backend, the welcome pages, the kded module and the graphical installer
/kdos/src/daemons src/daemons/ 7 KDOS’s own root daemons, and kdos-mdnsd

That is 2,446 recipes in all (counted as directories holding a kpkgbuild).

A repository holds a port either directly, as <repo>/<name>/, or one level down, as <repo>/<shelf>/<name>/. The src/ areas hold theirs directly. ports/core holds none directly: every upstream port sits on a shelf, a directory named for its subject, such as ports/core/kde/kwin/, ports/core/fonts/noto-fonts/ or ports/core/python-net/python3-requests/. The shelves are a closed list, the file ports/shelves, with one line per shelf giving its id, the source-archive volume that keeps its files, and what belongs on it. Writing ports gives the rules for choosing one.

A shelf is only where a recipe is filed. A port’s identity is its bare name: depends = lines, package lists, the package database, the binary host and the source index all name kwin, never kde/kwin, and there is no recipe key for the shelf, so moving a port to another shelf changes nothing but its path (and the .gitignore line of the few ports ignored by path, which spells the shelf). So a name must be unique across the whole tree: kpkg looks a name up in each repository, first as <repo>/<name>/ and then on every shelf, and a name found at two paths inside one repository is an error that names both, never a choice between them. kpkg, kdos update, kdos cve and the version checker all stop on it. A port nested below its shelf is an error too. Across repositories the first in the search order wins a name. testing/preflight.sh refuses a tree in which any port sits anywhere but ports/core/<shelf>/<name>/ or src/<area>/<name>/, a shelf is missing from ports/shelves, or a name is filed twice, and the pre-push hook makes the same checks of ports/core at the tip of every ref it pushes.

PORT_REPO lists the repositories kpkg may resolve against, in order. It holds at most eight; an entry past the eighth is dropped with a warning. Shelves are never listed on it: kpkg finds them itself. Its default, from /etc/kpkg.conf, is the recipe tree a shipped image carries: /ports/core and the four areas of /ports/src that hold ports. Inside the build’s chroot only /ports/core of those exists, so 20_selfhost, 30_foundation, 31_compilers and 70_image, which use that default, resolve against /ports/core alone (00_cross and 10_bootstrap do not use PORT_REPO: their step scripts read recipes through script/lib/port.sh, which finds a name one shelf down in ports/core itself). The package-building phases from 40_lang to 60_kernel widen it in their environment files, script/phases/<phase>/phase.env:

Phases PORT_REPO
40_lang to 44_apps, 60_kernel /ports/core /kdos/src/system /kdos/src/art
50_desktop /ports/core /kdos/src/system /kdos/src/art /kdos/src/desktop /kdos/src/daemons

Building KDOS’s own programs is therefore not a special case anywhere in the build system: they are ports like any other, found on a longer search path.

Beside ports/core, the ports/ directory holds files that describe the tree as a whole, and the tools that operate on it rather than on one recipe:

File What it is
shelves The closed list of shelves
base, buildonly, groups What the installation medium carries, which ports only a build needs, and the named sets of applications a machine installs in one step (see The base image)
buildheaders The build-only ports whose headers other packages’ headers include, which a build on an installed machine installs first (see Building here)
unbuilt The recipes no phase builds on purpose (see Phases, package lists and shelves)
RELEASE The release notes the image carries as /ports/RELEASE (see Updating a machine)
sources.idx The source index (see Where sources come from)
fetch, publish Fetching sources, and publishing them and releases
srclib.sh The library fetch and publish share
releaselib.sh The release index’s writer, shared by publish and the image phase
update The upstream version checker
hackage-vendor Writes Haskell vendor bundles
fwupd-snapshot Packs a signature-checked snapshot of the LVFS firmware metadata as the fwupd-snapshot port’s source
Containerfile.fetch The container that generates vendor bundles

Each of these tools names a port by its bare name and finds it on any shelf.

The recipes under src/

The four src/ areas that hold recipes hold KDOS’s own software. Each directory there is a port whose recipe names no source =: the code lives in the port directory itself, and build.sh compiles it from $PORT_SRC (the port directory; see What a build verifies), usually together with some of the shared libraries under src/libs (see The C libraries).

Every port there sits exactly two levels below src/, at src/<area>/<name>/. That depth is load bearing: a recipe finds the libraries at $PORT_SRC/../../libs, and kdos-installer compiles a file of its sibling kdos-appbox. The areas divide the programs by what they are:

Area Holds
src/desktop KDOS’s Qt, QML and KDE code and data for the Plasma session: settings pages, widgets, KWin effects and scripts, the Discover backend, theme packages and the graphical installer
src/daemons Root daemons whose client is the desktop account
src/system The package manager, the kdos command and its services, packs and boxes, and the installer
src/art Themes, pictures and the programs that generate them
src/libs The shared libk* C libraries; no recipes
src/devtools The build orchestrator kdosbuild and the version checker kdos-portup behind ports/update; no recipes. They run on the build machine and are compiled on demand

Three directories under src/system are special:

A source-less port is hashed differently from an upstream one when the build decides whether it is current: its whole directory, and all of src/libs, count as its recipe. The two source-less ports in ports/core, containers-common and musl-ldd, hash their whole directory but not src/libs. See E: — the recipe hash.

Phases, package lists and shelves

The ports tree says how to build each piece of software; it does not say which pieces make up the system or in what order they are built. That is the job of the phase package lists, one per package-building phase directory under script/phases/. A list is either one file, packages.txt, or a directory of files, packages.d/, whose *.txt files are read in byte order as one list. A phase has one or the other, never both.

Phase List Names Installs
20_selfhost packages.txt 9 15
30_foundation packages.txt 138 127
31_compilers packages.txt 22 22
40_lang packages.d/, 13 files 186 186
41_system packages.d/, 98 files 1,047 1,047
42_graphics packages.d/, 53 files 189 189
43_toolkits packages.d/, 56 files 344 344
44_apps packages.d/, 61 files 422 422
50_desktop packages.txt 92 92
60_kernel packages.txt 2 2

“Names” counts the port names a list writes; “Installs” counts the packages the phase installs that no earlier phase did. Between them the lists name 2,442 distinct ports and install 2,446: 2,402 of the 2,402 in ports/core, and every recipe under src/. ports/unbuilt is where a recipe kept for kpkg install and built by no phase would be named, removed from the image by the orphan sweep if an earlier build left it installed; it names none. Any other recipe no list reaches would never be built, so testing/bookcounts.py, run by testing/docscheck.sh, refuses one, and refuses a name in ports/unbuilt that a phase does install.

Where a list names more ports than it installs, the extra names are ports an earlier phase already installed, named again so that one whose recipe changed is rebuilt at that point in the order. A name may be written again only in the list’s order run: packages.d/00-order.txt, or the names a packages.txt gives ahead of its first shelf heading. 30_foundation’s order run is the build tools recipes use without naming them in depends = (make, file, muon, pkgconf, the autotools, bison, flex, cmake, meson, ninja, python3, perl, bash, and the userland a build.sh runs in: coreutils, grep, which and musl-utils), led by the toolchain 20_selfhost built (fortify-headers, musl, gcc, binutils) and followed by the rest of 20_selfhost’s ports, so a changed recipe among them is rebuilt before anything uses it (see The base userland).

From 30_foundation on, a list names exactly the ports its phase installs. Each port’s depends = still pulls in its dependencies, but every dependency the phase needs is either installed by an earlier phase or named in the list itself. So a phase means what it says: a port cannot drift into an earlier phase because something there started to depend on it, and a list cannot reach forward into a later one. testing/phaseclosure.py, which preflight runs, checks this for every phase and names each port that breaks it, with the phase that installs it and the phase that names it. It also refuses a name that is not a port on the phase’s PORT_REPO, a name listed twice, and a dependency that only a later phase’s PORT_REPO can resolve.

The phases split the system by what a port’s dependency closure reaches, not by subject:

Phase Holds
20_selfhost The C library, the compilers and the tools their builds run, rebuilt inside the chroot
30_foundation Build systems, the Perl and Python interpreters, and the base libraries every later recipe builds with
31_compilers LLVM and clang with their runtimes, Rust, Go, GHC, Zig, Node.js and Ruby, and the ports whose closure reaches one of them, such as cargo-c, bindgen and pandoc. They take most of the hours before 40_lang, so 30_foundation is a restore point in front of them
40_lang Language modules and developer tools whose closure needs nothing past 31_compilers
41_system Everything whose closure reaches no graphics and no toolkit: services, networking, storage, the command line, codecs, and the science and hardware libraries
42_graphics Ports whose closure reaches Wayland, X11, Mesa, cairo, pango, GStreamer, FFmpeg or PipeWire but no toolkit, other than ports nothing depends on that sit on an application shelf
43_toolkits GTK, Qt, KDE Frameworks, wxWidgets, FLTK and Motif, and every library over them that something else depends on, the Plasma libraries KDE Gear applications link (libplasma, kpipewire, plasma-activities, union and the rest) among them
44_apps Ports nothing depends on whose closure reaches a toolkit, and those on an application shelf whose closure reaches the graphics stack, the KDE Gear applications among them. The application shelves are listed in Which phase lists a port
50_desktop Everything the desktop session is and no application needs to build: KWin, the Plasma shell and its daemons, SDDM, the desktop portal, the input method, KDOS’s own Plasma code and daemons, and the meta ports. No port of 41_system to 44_apps names one of them in depends =
60_kernel The kernel, linux, and dwarves for its BTF

A list is a plain file: one port name per line, with # comments. After the file’s banner, which holds the KDOS name, the phase directory and its title, such as “41_system: System”, comments do two jobs. The first is grouping, and the lists are grouped by shelf. In a packages.d/ directory each file is one shelf’s ports and is named after it, <shelf>.txt, such as 41_system/packages.d/network.txt, or one src/ area’s, src-<area>.txt; a file’s banner repeats the shelf’s line from ports/shelves. In a single packages.txt a heading between two rules, # <shelf> — <description>, opens each shelf’s ports, in the order ports/shelves lists them, and after the shelves a # src-<area> — <description> heading opens the ports of KDOS’s own from that src/ area, as 50_desktop’s list does for src-desktop and src-daemons; the two shortest lists, 20_selfhost’s and 60_kernel’s, have no headings. The grouping exists for the reader, and the build ignores it. Preflight refuses a packages.d/ file that names a port filed on another shelf, and testing/phaseclosure.py refuses a shelf’s ports naming one an earlier phase installs.

The second job is stating the constraint that pins a port’s position, such as the build tools at the head of 30_foundation. A run of ports whose order a comment pins cannot be split across shelf files, so in a packages.d/ directory it lives in 00-order.txt, which sorts ahead of every shelf file and installs first, in the order written. 41_system is the only phase with that file, and it names no port: none of that phase’s ports needs a pinned position.

The toolkits and the natively ported graphical applications build last among the userland phases, in 43_toolkits and 44_apps, and the desktop after them in 50_desktop, because Plasma links Qt and KDE Frameworks like any KDE application does. Which KDOS code may link which toolkit is decided by its src/ area: the code under src/desktop may link Qt 6, KDE Frameworks 6 and the Plasma libraries built on them and nothing else from a toolkit, and the code under src/system, src/daemons, src/art and src/devtools, every set-id file and every program rcS starts link no toolkit at all, so the login never depends on a GUI stack. testing/preflight.sh reads the dynamic dependencies of every binary those ports install, and of each library they name, in the built tree (see Principles).

Order within a list matters. The orchestrator hands the whole list to kpkgdepends, which walks each name in turn and emits its dependencies before it, so a name written earlier is installed earlier unless a dependency says otherwise. Each port in the resulting order is then installed with kpkg install, which skips a package whose recipe has not changed; see Deciding what to rebuild. How phases are discovered, entered and snapshotted is in The build system, and The ports catalogue lists every port by shelf, with the phase that installs it.

The group key

A recipe may also carry a group = key, and that is a different kind of group. kpkg and the build never read it. Two programs do: the upstream version checker, ports/update, and testing/preflight.sh, which uses it for the shelf rule and the KDE release sets below. The checker offers related version bumps together: two ports in the same group are offered as one bump, and only when every member has the same newer version available upstream. Anything short of that is not offered as a group: each member that has a newer version is then reviewed on its own, like a port with no group, and keeping a set of ports that must move in step together is left to the reviewer.

Most ports need no key. Without one, the checker derives a group from the first source = URL: two ports whose sources come from the same organisation on GitHub, Codeberg, sr.ht or a GitLab instance, at the same version, fall into one group. The key overrides that derivation. In ports/core, 149 recipes carry it, naming 22 groups between them.

A group = family is not a shelf either, but it usually lives on one: every member of a group is filed on the same shelf, so a bump offered as one group touches one directory. Preflight refuses a group whose members sit on different shelves, with one exception, the KDE release sets below: group = plasma joins modules filed by what each one does (Spectacle on graphics, KWin on kde) into the one bump their release needs, and group = gear is allowed across shelves in the same way. No Gear recipe carries a key: Konsole, filed with the shells, and the other Gear applications are one family by their source directory alone.

KDE release sets

KDE releases three families, each as one set built and tested together: KDE Frameworks monthly, Plasma in feature and bug-fix releases, and the KDE Gear applications three times a year with bug-fix releases between. Plasma’s modules require each other at their own version, every Gear application is tested against the Gear libraries of its release, and a Framework from another month’s release breaks the ABI the rest were built against. So the tree holds exactly one release of each family: Plasma 6.8.2, Frameworks 6.31 and Gear 26.08.2. A bump of a family is one change that moves every member and rebuilds them.

testing/preflight.sh enforces it. A port belongs to a family by the release directory its source comes from on download.kde.org (stable/plasma, stable/frameworks or stable/release-service), by group = plasma or group = gear for a member whose source is elsewhere, and, for the Frameworks, by sitting on the kf6 shelf whatever its source. A Plasma or Gear release is the first three components of the version and a Frameworks release the first two, so a respin such as 6.8.2.1 belongs to the release it fixes; Frameworks of another major version are a family of their own, and Plasma’s side releases (plasma-wayland-protocols, kirigami-addons) belong to none. A tree that holds two releases of one family is refused, naming the ports on each. The check proves itself first on testing/fixtures/releaseset.

KDOS is English only. The KDE ports that carry translation catalogues are built with -DKF_SKIP_PO_PROCESSING=ON, so their catalogues are never compiled, and the size and language policy removes every non-English catalogue and handbook a build installs anyway. The Region & Language settings page sets the formats of dates, numbers, currency and paper, not the language; see Known gaps.

Meta ports

A meta port installs nothing of its own: its recipe is a depends = line and its build.sh the banner alone, so its package is empty and installing it installs what it names. The KDE metas are KDE as kpkg install gives it to a machine:

Meta Names
kde-all kde-plasma and kde-gear
kde-plasma The Plasma session: KWin, the shell and its daemons, SDDM, the desktop portal, the input method, Discover, and KDOS’s own Plasma code, art and daemons
kde-gear The eight metas below
kde-gear-core The applications every desktop starts with: Dolphin, Konsole, Kate, Okular, Gwenview, Ark, Spectacle, KDE Connect, their KIO workers, plugins and thumbnailers
kde-gear-devtools, kde-gear-education, kde-gear-games, kde-gear-graphics, kde-gear-multimedia, kde-gear-pim, kde-gear-utilities The rest of KDE Gear, by subject

The metas say what a machine gets; the phase lists say what the build makes, and ports/base says what the installation medium carries (see The base image). Every Gear application is named by exactly one kde-gear-* meta, which preflight checks, so kpkg install kde-gear leaves none out and two metas never fight over one.

A recipe’s depends = line holds at most 128 ports (KP_MAX_DEPS in libkpkg), and a recipe naming more is refused rather than read short: kpkg stops with <port>: depends names N ports; the limit is 128, and preflight fails the same recipe before a build reads it. A dependency list cut at the limit would leave its tail out of the install order with nothing to say so, which is why all of Gear is eight metas under one and not one meta of some two hundred names.

The base image

The build installs every port the phase lists name into build/fs; the ISO carries a subset of them, the base. Every other package is built all the same, kept in the release’s binary host and installed from there on a machine that wants it (see Installing more software). Three files in ports/ and one script decide the set:

File What it says
ports/base The seeds of the set, listed below
ports/buildonly The ports a build needs and a running system does not; the closure does not follow a depends = edge into one unless ports/base names it
ports/groups Not part of the set: the named sets of applications a machine installs in one step (see Groups)
script/lib/imageset.py Works the set out from the three files, and reports on it

ports/base names the seeds. Each line names ports (any number to a line), phase <dir> (every port that phase’s list names) or src <area> (every recipe under src/<area>). It names:

Ports reach the base through depends = too: kdos-tools depends on wl-clipboard, whose wl-copy and wl-paste are how kdos-shot and kdos-share reach the clipboard.

ports/buildonly lists:

What it leaves out matters as much: llvm is not listed, because Mesa loads libLLVM; nor is gcc, whose package carries libstdc++ and libgcc_s; nor libtool, which carries libltdl; nor glslang, whose library libplacebo links.

script/lib/imageset.py computes the closure of the seeds over each recipe’s first depends = line, not followed into ports/buildonly. Its modes:

Mode Prints or does
--keep, --drop The installed packages a root’s database holds inside and outside the set
--sizes Their counts and bytes
--why <port> The shortest dependency path from a seed to a port, or “not in the base”
--ledger Every installed package with its bytes and that path, largest first; 70_image/088_ledger.sh writes it to build/image-ledger, and 110_iso.sh’s size gate prints it
--check Refuses a name in any of the three files that is not a port, a phase or area that does not exist, and a group id that is a port’s name; preflight runs it as “the installation medium’s base names ports that exist”
--verify Fails a kept package whose run-time needs only a package outside the base provides; 087_gates.sh runs it on the stage

depends = names a port’s build and run-time needs alike (see What a port holds), so without ports/buildonly the closure would follow every recipe into the compiler it was built with. A port listed there must be nothing a program on the image runs or loads. The image gates prove it after the trim: 087_gates.sh’s linkcheck and entrycheck fail the image when a DT_NEEDED or a #! in it resolves to a package that went, and imageset.py --verify --full /kdos/build/fs fails it when a kept package’s recorded run-time needs (its sonames, interpreters, QML and Python imports and runtime = words) are met only by a package of build/fs the stage dropped. That is the one check that sees a QML module or a Python import. A package installed before needs were recorded has no record and is reported as unmeasured, not failed; for such a tree the proof is kpkg needs --scan over build/fs followed by --verify --needs (the commands are under Run-time needs). Measured that way on the build tree, every recorded need of the base’s packages, every QML and Python import among them, is met inside the base or by nothing at all (the modules a host program registers in-process). This is why glslang is not on the list, since libplacebo links libglslang, and why ports/base names tk, since xorriso-tcltk in libisoburn starts with #!/usr/bin/wish.

Measured on the build tree (imageset.py --sizes and --ledger), the base is 906 of 2,446 packages and 5.5 GB of their 49.5 GB of files, and about 4.6 GB once the development and documentation facets are left out, which is what the ISO’s root holds before compression. With every facet counted, the largest are gcc (0.34 GB, of which the run-time libraries every C++ program loads are about 10 MB and the compiler, its drivers and its static libraries the rest), llvm, Firefox ESR, Qt WebEngine, the kernel, Qt Declarative, firmware-intel and Mesa. The base takes four of linux-firmware’s eight vendor ports, firmware-intel, firmware-amd, firmware-mediatek and firmware-realtek, about a quarter of a gigabyte between them, and leaves the rest to kdos firmware sync (the bytes of each are in linux-firmware’s note).

What the base leaves out is one install away, prebuilt from the binhost:

Left out Installed with
The compilers and build tools kdos update install build-tools (a group, below), which also restores the development files of gcc, musl and linux: a working cc with the C library’s and kernel’s headers
Chinese, Japanese and Korean input and fonts the lang-zh, lang-ja and lang-ko groups
The rest of KDE Gear: torrents, remote desktop, Samba sharing, online accounts, Sweeper, KSystemLog, the Help Center and the others the kde-network, kde-system and kde-* subject groups
The KDE wallpaper collection and Oxygen the kde-artwork group
KDOS from Scratch, the build book sudo kdos update install kdos-kfs
OpenCL kdos update install mesa-opencl, Mesa’s rusticl with clang
Firmware for NVIDIA GPUs, Qualcomm, Atheros and Broadcom Wi-Fi and Bluetooth, the Cirrus and TI sound amplifiers and the less common hardware sudo kdos firmware sync, which installs the vendor ports this machine’s devices and kernel log ask for; --all installs all of them, and kdos update install linux-firmware is the same

Qt WebEngine is in the base because Skanpage, the scanning application, depends on it. The Help Center, which also needs it, is left to the kde-system group, and kdeplasma-addons is built without the two widgets that would need it, the dictionary and the web browser. The base keeps Samba’s client libraries, because kio-extras’ smb: worker links libsmbclient.

The base is made from a stage, never from build/fs. Under KDOS_IMAGE=base, the default, every 70_image step from 017_stage.sh on runs chrooted in an overlay whose lower layer is build/fs, read and never written; the changes go to build/image-upper. 017_stage.sh starts from an empty upper layer, refuses to run unless / is that overlay, and kpkg removes every installed package outside the closure in one run, so the index triggers rebuild the caches once for the trimmed tree. The cleanup, the orphan sweep, the caches, the gates, the initramfs and the ISO all run on the stage, and build/fs keeps every package for the next build and the binhost; the mechanics are in The build system. Once the set is the base, 017_stage.sh runs kpkg facets --strip over the stage, so the ISO carries the run-time facet of each package, about 0.95 GB fewer bytes, and writes FACETS=run into the stage’s /etc/kpkg.conf, so every later install on the medium or on a machine installed from it leaves the same files out; build/fs keeps FACETS=all and every file. make build KDOS_IMAGE=full skips the trim and makes the ISO from build/fs whole: the medium for a machine that installs with no network, and for the rig.

A machine installed from the base installs anything else from the binhost of its own release, so a release’s base ISO and its binhost are one unit: the binhost’s packages were built against exactly the base that ISO carries.

Where sources come from

Every upstream file a recipe uses is named by a sha256 = line in its kpkgbuild. That hash is the file’s identity: any copy that hashes to it is the right file, wherever it came from. Git carries the recipes and a few small hashed files committed beside them, such as bash’s patch-level files; every other hashed file, the upstream archives and the vendor bundles, is fetched.

make fetch, which runs ports/fetch, puts every hashed file that git does not track into its port directory and is the only step that uses the network. make build reads nothing but port directories, so a tree fetched once builds offline indefinitely. For each file, ports/fetch stops at the first copy that verifies, looking in this order:

  1. the port directory itself;
  2. the local cache, ports/.srccache/sha256-XX/<hash> (XX is the hash’s first two hex digits), hard-linked into the port directory;
  3. the KDOS source archive, https://github.com/kunaldawn/kdos/releases/download/sources-<N>/<asset>, where ports/sources.idx gives the release tag and the asset name for each hash; a hash the index does not name skips this step;
  4. the recipe’s own source = URL upstream;
  5. for a port’s own vendor bundle only, generating it again.

A vendor bundle is a port’s language dependencies (Go modules, Rust crates, Python or Haskell packages) packed as <name>-vendor-<version>.tar.xz; 173 ports carry one. It has a sha256 = line but no source = URL, so when no copy exists anywhere it is generated rather than downloaded, inside the kdos-fetch container that ports/Containerfile.fetch describes. Four of them, pdfium’s, LibreOffice’s, LibrePCB’s and Surfer’s, ports/fetch cannot generate: they are made by hand, and when no copy exists the fetch fails. Vendoring covers both kinds, the hand-made ones under A bundle no tool writes.

Whatever verifies is entered into the cache, so switching branches downloads nothing twice.

The source archive is a run of numbered GitHub pre-releases on kunaldawn/kdos, the volumes sources-1, sources-2 and on, titled by the first and last shelf they hold. ports/shelves gives each shelf its volume, and a volume holds the files of a run of shelves in sorted order. Each is a pre-release and never “latest”, so the repository’s latest release is always a KDOS system release. An asset carries its shelf and the file’s own name, such as archiver--zstd-1.5.7.tar.gz; when that name is already taken in the volume by other bytes it is <shelf>--<port>--<file>, and then <shelf>--<port>--<hash12>--<file>. A file only old history names is attic--<file> in the highest volume. A volume holds at most 1,000 assets; a file whose volume is full goes to the lowest-numbered volume with room, or opens a new one, and the index records where. GitHub turns every character outside [A-Za-z0-9._-] into a dot and a run of dots into one, so libsigc++2 is stored as libsigc.2, and the index records the name GitHub stored. A file larger than 1,900 MiB, near GitHub’s 2 GiB limit per asset, is stored in parts <asset>.part01 onwards; ports/fetch downloads each part, checks it against its own hash, joins them and checks the whole. For a moment the parts and the joined file are on disk together, so a split file needs about twice its size free: 10 GB for the 4.96 GB TeX Live tree.

The committed index ports/sources.idx starts with the line # kdos-sources-index 2 and has one line per file, <hash> <tag> <asset> <port>/<file>, with parts=<N>:<h1>,… after it for a split file. A <tag> is sources-<N>, or src-<shelf> for a file in the archive’s older layout of one release per shelf, which fetches the same way until ports/publish --rehome moves it into a volume; the committed index holds no such line. An index without that first line is not read at all, and every file then comes from upstream. Whatever the name or the release, a file is used only once it hashes to the recipe’s sha256 =.

Nothing in the archive is replaced, and an asset is removed only by two explicit maintainer commands: ports/publish --rehome, which moves a file to the volume and name of the shelf its port now sits on and deletes the old copy only after the new one is verified and the index is pushed, and ports/publish --orphans --prune=yes-delete, which deletes files no current recipe, no recipe at any v* tag and no freeze list names. A checkout years old therefore finds the exact bytes it was written against even after the upstream host has gone, fetched with the newest index through ports/fetch --tree. The current ports/core recipes name 2,877 distinct hashed files over 102 shelves, the largest shelf, python-libs, naming 87. 46 of them are small files git tracks beside their recipes, and the other 2,831, about 40.2 GiB, are archived in four volumes. Stored by hash, a file several ports use is one asset, in the volume of the first shelf that names it; the LLVM monorepo tarball, for example, is shared by eight ports.

The commands and settings:

Command or variable Does
make fetch Fetch and verify everything; generate missing vendor bundles in the kdos-fetch container
make fetch-check Offline (ports/fetch --check): list each archived source that is missing or corrupt, download nothing, exit 1 if any is
ports/fetch [port…] Fetch only the named ports
ports/fetch --tree <dir> [port…] Fetch for another checkout’s ports/core; never generates a vendor bundle
KDOS_SOURCES_BASE= (empty) Skip the archive and go straight to upstream
KDOS_SOURCES_BASE=<dir> Read the archive from a directory laid out as <tag>/<asset>, such as an archive disk, with no network
FETCH_JOBS=N Fetch up to N ports at once (default 1); make fetch passes it through
KDOS_SOURCES_REPO The archive repository (default kunaldawn/kdos)
KDOS_SOURCES_INDEX The index to read (default ports/sources.idx); only format 2 is read
KDOS_SRCCACHE Move the cache, for example to share one between checkouts
KDOS_FETCH_HOST=1 Do everything in one pass on this host, generating bundles with its own toolchains

An empty file or a hash mismatch is always refused, and a corrupt cache entry is deleted. A file whose recipe carries no hash yet, as after a version = bump, can only come from upstream, and a vendor bundle with no hash is generated.

The contributor’s side of this is adding a new source to the archive: ports/publish uploads it and writes its index line, and an opt-in pre-push hook (script/hooks/pre-push, enabled with git config core.hooksPath script/hooks) refuses a push whose recipes name a hash that the pushed ports/sources.idx does not, or whose file, or any of whose parts, the archive does not answer for. Both are described in Writing ports; the fetch flow, step by step, is in Developing.

Fetching sources on a machine

An installed machine has the recipe-only tree at /ports and no source, and builds an update with kpkg, which fetches what it needs itself. kpkg fetch <pkg>… takes every sha256 = file the port directory and SOURCE_DIR do not hold, in the order ports/fetch uses: the archive, at the release and asset the tree’s own sources.idx names, then the source = URL that names the file upstream. A file split into parts is fetched part by part, each part checked against its own hash. A copy is kept in SOURCE_DIR only once it hashes to the recipe’s sha256 =; any other copy is deleted. A file no source = entry names, such as a vendor bundle, is also linked into the port directory, because its build.sh opens it there as $PORT_SRC/<file> and only the extraction of a source = entry looks in SOURCE_DIR. KDOS_SOURCES_BASE means what it means to ports/fetch: unset is the published archive, empty skips the archive, and a directory is an archive disk laid out as <tag>/<asset>.

Exit Meaning
0 Every source is present
1 A source could not be had: no copy verified, or neither the archive nor a source = URL names it (a vendor bundle the archive lacks)
3 No copy could be reached at all: the network is down

kpkg fetch --size <pkg>… downloads nothing. For each file the fetch would download it asks the same URLs in the same order for the Content-Length of their final response (curl -sIL, 15 seconds a request; a file in parts is the sum of its parts) and prints <file> <bytes>, or <file> ? when no copy answered with one; a file two of the ports share is printed once. The size is a server’s word, not a verified one, and is what kdos update reckons a build’s space from before its sources are here. Its exit status is the table’s, 1 meaning a size is not known.

A build fetches on its own only with KPKG_FETCH=1, which kdos update apply sets so that a dependency a new tree adds has its sources fetched as kpkg install reaches it. Without it a missing source fails the build: make build runs with no network, and a build that downloaded on its own would stop being a build of the fetched tree.

kpkg

kpkg is the package manager: one C program that builds ports, installs and removes packages, resolves dependencies, signs and verifies binary packages, and makes deltas. It is one binary answering to five names. The bootstrap phase installs it as /usr/bin/kpkg with the other four names as symbolic links, and what it does depends on the name it was run as:

Name Does
kpkg The front end, with the commands below
kpkgadd Install a prebuilt package file: kpkgadd [-f] [--root <path>] <file>; -f skips the conflict scan and leaves a contested path claimed by both packages
kpkgbuild Build the port in the current directory into a package without installing it
kpkgdel Remove packages: kpkgdel [--root <path>] <package>…; it also drops each removed package’s line from the root’s world set and origin record (see Upgrades and removals)
kpkgdepends Print the resolved install order, and nothing else: kpkgdepends [--root <path>] <package>…

The kpkgbuild command shares its name with the recipe file it reads; this chapter says “the kpkgbuild file” where the file is meant.

The front end’s commands:

Command Does
install <pkg>… (i) Build and install packages with their dependencies
remove <pkg>… (r) Remove packages
list [--root <path>] [--json] (l) List installed packages
info [--root <path>] [--json] <pkg> For an installed package, its version, release, licence (the recipe’s license =) and file count; for one that is not installed, the recipe’s description, licence and depends = list
check [--root <path>] [--brief] [--log <file>] <pkg>… or check … --all Compare the root with what was installed; see Checking an installed root
facets --strip [--root <path>] [<pkg>…] Remove installed packages’ development and documentation files, every package’s when none is named; see Facets
facets --list [--root <path>] <pkg> Print what a package was installed without, or <pkg>: every facet installed
needs [--resolve \| --scan] [--root <path>] <pkg> Print what a package needs at run time as its install recorded it; --resolve names the installed package providing each edge and exits 1 when nothing provides one, --scan measures it from the installed files without writing; see Run-time needs
meta <pkg or portdir> Print the recipe’s metadata as shell assignments, which ports/fetch reads
fetch [--size] <pkg>… Download each source the port directory and SOURCE_DIR lack, or with --size print the size each would download; see Fetching sources on a machine
verify <pkg> Build the current recipe and a candidate written beside it as kpkgbuild.new (with an optional build.sh.new), then compare the two packages; exits 0 when their payloads match, 1 when they differ, a build fails or there is no kpkgbuild.new
verify --repro <pkg> Build the same recipe twice; exits 0 only when the two packages are byte-identical. Either form leaves the two packages at /tmp/kpkg-verify-0.tar.xz and /tmp/kpkg-verify-1.tar.xz
keygen <name> Make an Ed25519 signing key pair
sign <file> <key> Write <file>.sig, one signature over any file, which verify-pkg checks; a release’s SHA256SUMS is signed this way
index <dir> [--sign <key>] [--buildonly <file>] Write PACKAGES for a directory of packages, optionally signing it and every package; with --buildonly, each measured package’s N: line
verify-index <dir> Check PACKAGES against the trusted keys
verify-pkg <file> Check <file>.sig against the trusted keys
delta <old> <new> [-o <file>] Write the difference between two packages
apply-delta <old> <delta> -o <new> [--expect <sha256>] Rebuild a package from a delta; with --expect, delete the result and exit 1 unless it hashes to the given SHA-256
binhost [--root <path>] <dir> <pkg> [--dry-run] [--insecure] Install a prebuilt package if it matches this machine exactly; --dry-run checks and installs nothing. An unknown option or a second port is refused with exit 1
store gc <dir> <max-size> Shrink a package store to a size such as 60G; see Eviction
help Print usage

kpkg help, --help and -h print the usage and exit 0, -V and --version print kpkg <version> and exit 0, and a bare kpkg prints the usage and exits 1. An unknown command prints kpkg: unknown command '<word>' — try: kpkg help on standard error, with no usage text, and exits 1. The options may also come before the command word, as kpkg [--root <path>] [-f] <command> …: a - word there that the usage does not list under Options prints kpkg: unknown option '<word>' — try: kpkg help and exits 1, an install-only option before any command but install prints kpkg: option '<word>' is for install only, and a leading --root before a command that reads no root prints kpkg: option '--root' is not for '<command>', each exiting 1. A --root that is not a directory makes list print no such directory: <path> and exit 1, and one it cannot reach for another reason, such as a parent it may not search, cannot read <path>: <reason>, also exit 1; a directory with no package database lists nothing and exits 0, as a fresh sysroot does. The commands that write — install, remove, facets --strip — test whether the root is a writable directory, not whether they run as uid 0, and name the reason they cannot: no such directory: <path> for a root that is missing or not a directory (a regular file included, as for list), <path> is read-only, or cannot write to <path> — run as root when permission is what is missing.

Options and environment:

Option or variable Effect
--root <path>, KPKG_ROOT Install into, remove from or read another root directory, such as an installer’s target. Only the install and the package database move: a build still runs on this system, with its compiler, headers and libraries. install, remove, list, info, check, facets, needs, binhost, kpkgadd, kpkgdel and kpkgdepends take --root, and the kpkg commands among them take it before the command word too
--keep-cache, KPKG_KEEP_CACHE=1 Keep each built package in PACKAGE_DIR after installing it, compressed with the kept xz -9 setting; by default it is compressed with xz -0 and deleted once installed
-f, --force Rebuild the named packages; a dependency is built only when it is not installed, and the walk stops at an installed package. The rebuilt package is installed through the same conflict scan as any other
install --build-only <pkg>… Build exactly the named ports into PACKAGE_DIR and install nothing; see Building apart from installing
install --commit <pkg>… Install what --build-only built for each named port, in the order named
KPKG_CONF Configuration file (default /etc/kpkg.conf)
KPKG_KEYRING Trusted-key directory (default /etc/kdos/keys)
KPKG_REQUIRE_SIG=1 Refuse any package without a valid signature
KPKG_SKIP_INDEX Space-separated shared indexes not to rebuild after an install or removal (man, schemas, gio, pixbuf, mime, fonts, info, hwdb, xfonts, texmf, desktop, icons, vlc). The build’s chroot phases set man; nothing sets it on a running system
KPKG_FACETS all or run, over kpkg.conf’s FACETS: which facets of a package an install places. kdos update install sets all for a restore and for every install of a run that builds
KPKG_CC_ID=<cc> <version> The compiler field of the build-config hash, used instead of asking $CC -dumpversion; /etc/kdos/chroot.env sets it on an installed machine
KPKG_STRICT_RECIPE=1 Rebuild an installed package whose recipe hash differs; without it, every installed package is skipped. See Deciding what to rebuild
KPKG_STORE=<dir> Install a port from the package store in <dir> when its key is there, and store every package it builds; empty or unset, the store is off
KPKG_STORE_CHECK=1 Build every store hit anyway and log a difference; see Check mode
KPKG_STORE_SALT, KPKG_STORE_BASE Two terms of the store key: the hash of what the bootstrap phases built, and the ports every key depends on whether declared or not
KDOS_ALLOW_UNVERIFIED=1 Extract a source the recipe gives no hash for; see What a build verifies
KPKG_FETCH=1 Have every build fetch its missing sources before it verifies them, as kpkg fetch does; kdos update apply sets it, and the build never does

install, remove, check and kpkgadd refuse an unknown option rather than read it as a package name.

/etc/kpkg.conf sets PORT_REPO (default /ports/core /ports/src/system /ports/src/art /ports/src/desktop /ports/src/daemons), SOURCE_DIR (/var/cache/kpkg/sources), PACKAGE_DIR (/var/cache/kpkg/packages), WORK_DIR (/var/cache/kpkg/work) and PKGDB_DIR (/var/lib/kpkg/db). Every line has the form NAME="${NAME:-default}", and kpkg reads it as key and value without running a shell. An environment variable of the same name always wins over the file, which is how each phase’s environment file points kpkg at its own repositories.

The solver is a depth-first walk of depends = lines: each port’s dependencies are emitted before the port itself, a port is visited once, and a dependency cycle terminates rather than recursing without end. A package that is installed and current is dropped from the order before any build starts.

kpkgdepends writes one bare, space-separated line to standard output and nothing else, because the build orchestrator parses it. The orchestrator checks every token against the pattern ^[A-Za-z0-9][A-Za-z0-9._+-]*$ and treats empty output as an error, and diagnostics from anything running inside the build chroot go to a log, so stray output fails loudly instead of being installed as a package.

kpkg links three of this tree’s libraries, libkbase, libkpkg and libksig, and nothing else but the C library, so it is cross-compiled early and exists on every tree from the first bootable image onwards.

Building apart from installing

kpkg install --build-only and kpkg install --commit split one install in two, so ports that do not depend on each other can build side by side while their installs still happen one at a time.

--build-only <pkg>… builds each named port in the order named and resolves nothing. Every depends = entry of a named port must already be installed and current; one that is not is an error that names it and stops the run at that port: the ports named before it keep their builds and records, and it and the ports after it are not built. A port that is itself installed and current is skipped as in an ordinary install, unless -f names it. The recipe hash is taken before the build, and the package is compressed as a normal install would: the cheap preset unless the cache is kept. On success the build writes PACKAGE_DIR/<name>.pending, replaced whole through a temporary file, so it is either absent or complete:

/var/cache/kpkg/packages/foo-1.0-1.tar.xz
<the recipe hash taken at build start>
transient
<the package-store key taken before the build, or an empty line>

The third line is kept or transient, the xz preset the package was packed with. The fourth is the package store key, empty when the store is off or the key is unknown; --commit stores the package under it once it is installed. Lines after the fourth are ignored. A --build-only that finds a record naming an existing package built from the same recipe hash prints already built and builds nothing, so a run that was interrupted resumes at no cost. Under a kept cache the record must also say kept: a transient package is not the bytes kpkgbuild makes, so it is built again rather than left in the cache the binhost publishes.

--commit <pkg>… handles the names in the order given. For each it reads the record, installs the package it names through the same conflict scan as kpkg install, records the recipe hash from the record under the database’s writer lock, deletes the package unless the cache is kept and the record says kept, deletes the record, and prints kpkg: committed <name>. A name with no record is an error that stops the run. kpkgadd holds the writer lock for the install itself, so installs from any number of callers into one root never overlap.

The image phase deletes leftover .pending records together with the package cache.

Packages

A package is a compressed tar archive plus a database entry.

File name <name>-<version>-<release>.tar.xz, parsed from the right because a name may contain hyphens
Compression xz -9 -T0 --block-size=32MiB --no-adjust for every package that outlives its install; xz -0 -T0 --block-size=8MiB --no-adjust for one kpkg install deletes straight after installing it. See Reproducible packages
Decompression One xz thread, whatever the core count: kpkgadd extracts with tar --use-compress-program="xz -T1", the compressor split into its words by tar and not by a shell. A -9 package with 32 MiB blocks needs about 100 MB a decoding thread, so the default of one thread per core can be killed for memory on a 4 GB machine; one thread peaks at about 65 to 70 MB
Database entry /var/lib/kpkg/db/<name>: the version and release on the first line, then the manifest
Manifest Every path the package owns, one per line, ./-prefixed, directories with a trailing slash. Each line is the name’s own bytes, as tar --quoting-style=literal lists it, so a name outside ASCII is stored as the UTF-8 the package holds rather than as tar’s octal escapes; a name holding a newline cannot be stored
Recipe hash /var/lib/kpkg/db/.recipe/<name>, one line, written by kpkg install, --commit and kpkg binhost, which records the matched stanza’s E:. kpkgadd removes any existing record before it writes the entry, so a direct kpkgadd leaves the package with no record. See Deciding what to rebuild
Package-file hash /var/lib/kpkg/db/.pkgsha/<name>, one line: the SHA-256 of the .tar.xz it was installed from, written by kpkgadd after the entry; see The package store
File record /var/lib/kpkg/db/.files/<name>, one line per regular file the install placed: <sha256> <mode> <path>, the mode as four octal digits and the path as the manifest spells it; written by kpkgadd after the entry, once the install hook has run, and read by kpkg check
Facet record /var/lib/kpkg/db/.facets/<name>, one <facet> <path> line per file an install under FACETS=run or kpkg facets --strip left out; present, even empty, on a package installed with its run-time facet only. See Facets
Needs record /var/lib/kpkg/db/.needs/<name>, one <kind> <value> line per run-time edge found in the installed files, written by kpkgadd after the file record; present, even empty, on every package installed since needs were recorded. See Run-time needs
Writer lock /var/lib/kpkg/db/.lock, empty; held by kpkgadd and kpkgdel while they change the tree and the database
Install hook .POSTINSTALL at the root of the archive, when the port has a postinstall.sh

A package holds what the port’s build installed into $PKG, less what the tree’s size and language policy removes: HTML and PDF manuals, every non-English translation, and the symbol table of an executable or shared object over 32 MiB (see Writing ports). kpkg strips no other binary and splits off no debug package, so the compile and link flags decide a package’s size. No port ships debug information: each recipe overrides the upstream defaults that add -g by flag (meson’s --buildtype=release, Go’s -ldflags "-s -w", GCC’s CXXFLAGS_FOR_TARGET, CPython’s OPT), preflight enforces the meson and Go flags, and testing/debuginfo.py fails a built tree that carries more than 1 MiB of debug sections outside ghc’s -debug runtimes; see Writing ports.

The file name is the only metadata a package carries. The install hook is a standalone bash script: a shebang, the recipe’s metadata, then postinstall.sh byte for byte. kpkgadd lifts it out before placing any file, so it is never installed and never in the manifest, and runs it after the install with PKG_ROOT set to the root and PKG_OLD_VERSION to the <version>-<release> the install replaced (empty on a first install); a hook that fails produces a warning, not a failed install.

kpkgadd extracts into a staging directory on the target filesystem, so placing a file is a rename. The archive is decompressed once: the extraction runs with --quoting-style=literal, its verbose listing is byte for byte what tar -tf --quoting-style=literal prints, and it becomes the manifest, less ./.POSTINSTALL. GNU tar’s default quoting writes every byte outside printable ASCII as an octal escape, and a manifest line in that form names no file on disk, so removal and every ownership question would miss it. A file that cannot be placed aborts the install before any database entry is written, because an entry written past a failure would claim a complete install of a package that is half on disk. Writing to the root is permitted whenever the root is writable, which is what lets a build install into a sysroot (a directory standing in for a target’s root filesystem) it owns without being root. kpkgadd creates every directory 0755, whatever mode it was packaged with: the package is rolled root:root, and a mode that leaned on a daemon’s group would lock that daemon out. A hook that needs a directory’s mode sets it.

The database has one writer at a time. kpkgadd and kpkgdel take an exclusive lock on .lock in the database directory before they read who owns what, and release it after the shared indexes are rebuilt. Two installs into one root therefore run their conflict scans, placement and database edits one after the other, and neither decides against a table the other is rewriting; extraction happens before the lock and overlaps. The install hook runs inside the lock, so a hook that calls kpkg waits on its own installer for ever. Every command that lists the database skips its dot-names: .lock, .recipe/, .pkgsha/, .files/, .facets/ and .needs/ are not packages.

Who owns a file

A file conflict is between packages. A path that exists but that no installed package claims is adopted, not refused. This is what makes the bootstrap work: the earliest build phases install a toolchain by hand, leaving files no database entry owns, and the bootstrap then rebuilds those packages with kpkg.

The scan asks the database about every staged path that is not a directory, on a first install and on an upgrade alike, whether or not the path exists under the root. A path another package claims is a conflict even when its file was deleted from the root, and an upgrade that adds a path another package owns is a conflict too: asked only of paths on disk, or only on a first install, either would be taken without a word and left claimed by two packages. Every manifest is streamed and only the claims on the staged paths are kept, rather than sorting the million-odd paths a desktop tree holds on every install. The package’s own claims, an upgrade’s old version, are never a conflict. An upgrade’s orphan sweep and a removal read ownership the same way, for the files they are about to delete.

A path another package owns is taken only when the recipe declares it: replaces = <package>… names the packages this one may take paths from (see Writing ports). kpkgadd reads the line from the recipe of the same name in the ports tree, so a package installed with no recipe beside it declares nothing. A declared path changes hands: the file is placed, the path is removed from the previous owner’s manifest, and kpkgadd prints Taking <n> path(s) from <package>. Without that, removing the older package would delete a file the newer one installed. The declaration runs one way: the package a path was taken from, installed again while its taker holds the path, is refused like any other conflict, so a taker names that package in depends too and installs after it. Any other claim refuses the install before a file is placed:

ERROR: File conflict detected:
  usr/bin/foo (owned by bar)
  baz may take a path from a package only when its recipe names that package in `replaces =`

The refusal holds for kpkg install -f and for the build, which installs every package through this scan. kpkgadd -f alone skips it, placing the files over whatever claims them and leaving each contested path claimed by both packages; nothing in the build passes it. Of several claimants of one path, the one every ownership question names (the conflict scan, kdos why, kpkg check’s unowned walk) is the first by package name in byte order, whichever C library kpkg was built against and whether the whole table was read or only the claims on the staged paths.

Ownership is compared on the canonical path. The root’s bin, sbin, lib and lib64 are links into /usr, so a package built with --exec-prefix= records ./bin/free for the same file another records as ./usr/bin/free. Compared as strings the two never collide: the scan passes, the file is claimed twice, and removing or upgrading either package deletes the other’s file. kpkg reads which top-level names are such links from the root it installs into, and folds each path through them before comparing.

The base userland

The command line is GNU’s, and every name has one owner. coreutils installs each of its programs as a binary of its own, with no multi-call binary; grep, sed, gawk (which /usr/bin/awk names), findutils, diffutils, patch, tar, gzip, cpio and which are the GNU packages of those names. musl-utils builds the getconf, getent and iconv programs musl’s own source does not carry, from Alpine’s musl package; util-linux, procps-ng, iproute2 and iputils supply the system tools, and sysvinit supplies PID 1 and the commands that talk to it (see Boot and init). mkpasswd, which hashes a password for /etc/shadow or useradd -p, comes from the whois port, whose source carries it. Nothing on the image is a multi-call userland.

coreutils’ configure line carries four constraints:

--enable-install-program=arch,hostname adds the two programs coreutils leaves out by default, and --with-libgmp stops configure when gmp is missing instead of building expr and factor against gnulib’s smaller copy. FORCE_UNSAFE_CONFIGURE=1 is there because kpkg builds as root, which coreutils’ configure otherwise refuses.

Upgrades and removals

An upgrade removes orphans. A file present in the old version and absent from the new one is removed rather than left on disk owned by nothing, unless another package claims it, in which case it is that package’s file and stays. “Absent” is judged on the canonical path, so ./bin/x in the old version and ./usr/bin/x in the new are one file.

An install of the version and release already installed (a --dev restore, a forced reinstall) leaves in place every regular file whose size, mode, owner and bytes match the staged copy, and prints Keeping <n> unchanged files in place. Only a file that differs is replaced. A file renamed over gets a new inode with the same contents, and every running program that maps it then maps a deleted file, which the restarts check behind kdos-notice reports as a desktop update. An install of any other version replaces every file.

A path the new version ships as a directory where the root holds a file, such as a zipped Python egg the new version ships unpacked, is asked about like a staged file: claimed by another package, it is a conflict; otherwise the file is unlinked and kpkgadd prints Replacing file <path> with a directory. Left in place, every path beneath it fails with Not a directory and the install aborts half-written.

A removal walks the manifest in reverse, so a directory is reached only after everything inside it; a directory that still holds another package’s files survives, and so does an empty one another installed package still lists, because a package may ship an empty directory something else fills or reads (hicolor-icon-theme’s icon sizes, a plugin directory). A run counts each directory’s claims once and takes each removed package’s off as it goes, so a directory goes when the last package listing it does. A file another installed package claims is left in place. One run takes any number of names. kpkgdel does not check reverse dependencies: kpkgdel bash removes bash. The entry’s sidecars in .recipe/, .pkgsha/, .files/, .facets/ and .needs/ go with it. A name that is not installed is reported (ERROR: Package '<name>' not installed) and skipped, the rest of the command line is still processed, and the command exits 1.

A removal also takes the package out of what kdos update installs back. Every line whose first word is a removed package (read as kdos update reads it: leading blanks skipped, cut at a blank, a carriage return or #) is dropped from <root>/var/lib/kdos/world and <root>/var/lib/kdos/origin, so the next update does not reinstall it. Each file is rewritten whole through a temporary file and a rename, mode 0644, and only when it exists and a line was dropped; a missing file is not created, other packages’ lines are kept, and a name that was not installed stays in both. A rewrite that fails prints ERROR: cannot rewrite <path>: <reason> and exits 1.

The removal reaches this root only. The other A/B slot is a separate root: a slot an update has already filled has the package installed, and a slot it has armed was also given a copy of this root’s world set and origin record at the arm, so it boots with the package installed and listed, and its updates keep it. Removing it there means running kpkg remove again once that slot is running.

kpkgadd prints ==> Installing <name>-<version>-<release>, or ==> Upgrading <name> (<old> => <new>), then the facets line, any Skipping, Keeping <n> unchanged files in place, Removing orphan, Keeping and Taking lines and warnings, and ==> Package '<name>' installed successfully; it prints no line per file. When the extraction fails, tar’s and xz’s own messages (xz: (stdin): Unexpected end of input, Cannot allocate memory, a full disk) are printed between the Installing line and ERROR: Failed to extract <file>, in that order in a log that collects both streams, and it exits 1.

An install or removal ends by rebuilding the shared indexes its manifest fed, from everything then on disk: the GSettings schemas, the GIO module and pixbuf loader caches, the MIME database, the desktop entries’ mimeinfo.cache, the font cache and the X core fonts’ fonts.dir, the info directory, the TeX ls-R files, the udev hardware database and the icon-theme.cache of each icon theme it touched, or of every theme when the package carries gtk-update-icon-cache itself, and VLC’s plugin cache, plugins.dat. The manual index is merged instead: an install that only adds pages adds them to mandoc.db, and the index is rebuilt from the whole tree only when a page was removed (by a removal, or as an upgrade’s orphan) or when there is no mandoc.db yet. A tool that is not installed yet is skipped, and a tool that fails produces a warning, because the package is already on disk. KPKG_SKIP_INDEX names indexes not to rebuild, space-separated (man, schemas, fonts, and so on); each one skipped prints index skipped: <name>. The build’s chroot phases set it to man, because 70_image writes every mandoc.db from scratch over the finished tree; a running system never sets it. No package owns these files, so no package ships them; kpkgbuild deletes the info dir file, the desktop entries’ mimeinfo.cache and each fonts.dir from the staged tree for that reason. The list is in Writing ports.

Checking an installed root

kpkg check <package>… compares the root with what was installed, and kpkg check --all does so for every installed package; --root <path> checks another root, such as an A/B slot. Each package’s manifest is walked against the root and against its file record in .files/<name>, the SHA-256 and mode kpkgadd took from every regular file it placed. Each finding is one line:

Line Means
<package>: missing <path> Nothing is at a path the manifest lists, or a directory entry is not a directory
<package>: changed <path> A recorded file outside /etc whose bytes do not hash to its record, or that is not a regular file
<package>: mode <path> <now>, installed <then> A recorded file outside /etc whose permission bits differ
<package>: config <path> A recorded file under /etc that is changed in the same sense: configuration someone edited
<package>: config mode <path> <now>, installed <then> A recorded file under /etc whose permission bits differ
unowned <path> With --all: a file or link under /usr or /opt that no package claims

A summary line follows, counting each kind. --brief prints only the missing, changed and mode lines and the summary, which still counts config and unowned files, and --log <file> writes every line to <file>; neither changes the exit status. The exit status is 1 when anything is missing, changed or has a changed mode, 0 otherwise, and 2 for a usage error or a name that is not installed. A config line and an unowned file do not change the status: a package’s file under /etc is a default the machine is meant to edit, so a check that failed on it would fail every configured machine; the skeleton the build copies from fs/ and anything installed by hand under /usr/local belong to no package by design. A file under /etc that is gone is still missing, and still fails. The indexes kpkg writes itself (listed under Shared indexes) and Python’s __pycache__ bytecode are not reported, and one a package ships that a trigger then rewrites, as mktexlsr does texlive’s ls-R files, is checked for presence only.

A path is checked as the manifest spells it, so ./bin/x on a merged-/usr root is checked through the root’s own bin link, and a file claimed under either spelling is owned. A path another package took leaves the old owner’s manifest, so it is checked only against its new owner’s record. A symbolic link, device node or FIFO is checked for presence only, and so is every file of a package installed with no file record. The record is taken once the install hook has run, so a mode or a file the hook sets is what is checked.

A freshly built image checks with no missing, changed or mode line and exits 0. The image leaves out the build tree’s logs and caches, but recreates every directory a package claims under /var/log and /var/cache, empty and with the tree’s mode and owner (the live medium); a package that installed a file there, rather than a directory, would be missing on the image.

kdos update apply runs kpkg check --all --brief --log /var/log/kdos-update-check.log on an A/B slot it installed into, before it puts the slot’s kernel on the ESP and marks the slot to be tried, so an apply prints the faults and the summary and the slot’s whole file list is in that log; a slot that fails the check is not tried, and one whose only findings are config lines is. See Updating a machine.

Facets

A package holds every file its build installed, and a machine that never compiles uses about a sixth of the base’s bytes for nothing: headers, static libraries, the files a build finds a library by, and manuals. A facet is a class of a package’s files, decided by the path (and, for the few files a recipe names, by the recipe), so one recipe, one build and one signed package file serve a machine that builds and one that does not. There are no development packages: the package names, the signatures, the recipe hash and the binhost index are the same either way.

Facet Files Bytes in the base
dev everything under usr/include/ 252 MB
dev a .a archive under usr/lib/ (static libraries, gcc’s libgcc.a among them); one elsewhere is run time, as libclc’s bitcode under usr/share/clc/ is for Mesa’s OpenCL 254 MB
dev usr/lib/cmake/, and usr/share/cmake/ except CMake’s own Help/, Modules/, Templates/ and include/, which cmake reads every time it runs 17 MB
dev usr/lib/pkgconfig/, usr/share/pkgconfig/ and usr/share/aclocal/ 1 MB
dev usr/share/gir-1.0/ (GObject introspection’s XML; the compiled typelibs under usr/lib are run time) and usr/share/vala*/vapi/ 73 MB
dev man sections 0, 2 and 3: the POSIX headers, the system calls and the library functions 45 MB
dev a symbolic link usr/lib/lib<x>.so whose target is that name plus a version (libz.so -> libz.so.1.3.1), the link -lz resolves through. A real file named lib<x>.so is run time, since most plugins and every library built without a version are one, and so is a link to anything else, unless it points into its own package’s dev facet (below) 0
doc usr/share/doc/ except HTML/ (KDE’s handbooks, which help:/ and every Help menu open) and kdos/ and kfs/ (the KDOS book, and KDOS from Scratch once kdos-kfs is installed, which the desktop links into) 20 MB
doc usr/share/info/, and usr/share/gtk-doc/html/, the generated API references; the rest of usr/share/gtk-doc/ is gtk-doc’s own python/ and data/ (the stylesheets gtkdoc-mkhtml reads and the gtk-doc.make files gtkdocize copies), which are run time 35 MB
run everything else, man sections 1 and 4 to 8 among it

The figures are measured over the packages of the base on a full build tree, hard links counted once: about 0.7 GB of its 5.5 GB by these rules, and about 0.95 GB with gcc’s facet_dev = line below.

A link goes with its target. A symbolic link the rules call run time whose target is a path of the same package in dev or doc takes that facet: once the target is left out it would point at nothing. Chains settle, so libcurses.so -> libncurses.so -> libncursesw.so -> libncursesw.so.6 leaves with its -l link and only libncursesw.so.6 stays, and a compatibility name such as glslang’s libglslang.so.0 -> libglslang.so leaves with the link it names. A link into another package keeps its own facet.

A recipe may only add to the dev facet. Its facet_dev = line, whitespace-separated globs matched against each of its own package’s paths without the ./ (* crosses /), moves a file the rules call run time into dev; nothing moves a file out of dev or doc. gcc uses it for its compiler: the drivers in /usr/bin, everything under /usr/lib/gcc/, the sanitizer runtimes and its manual pages, 270 MB of its 339 MB beyond the rules’ 59 MB, so the base keeps gcc’s 10 MB of run-time libraries (libstdc++, libgcc_s, libgfortran, libgomp) and nothing of the compiler. python3-pyside6 uses it for its shiboken6 binding generator, which links libclang, so the package’s run-time needs name no clang (see The binary host). The rules are kp_facet_of in libkpkg, and both spellings of a merged-/usr path match, so ./lib/libz.a is a static library.

FACETS in /etc/kpkg.conf, with KPKG_FACETS over it, says which facets an install places:

Under run, kpkgadd takes the left-out files out of the staged tree before the conflict scan, so they are never placed, scanned for conflicts, put in the manifest or the file record, or swept as an upgrade’s orphans, and lists each as dev <path> or doc <path> in .facets/<name>. A directory leaves the manifest with them when it held a file that was left out and holds none that was kept; kpkg facets --strip deletes such a directory from the tree only when it is empty and no other installed package lists it. kpkg check therefore passes such a package, a removal never asks about the files, and kdos update check counts it current: what it was installed without is neither behind nor damage.

The record says how the package is installed, and an upgrade keeps it that way: under run, an upgrade of a package that has a record leaves the same facets out, and an upgrade of a package installed whole, which has none, stays whole. That is what keeps a package kdos update install --dev restored whole across later updates. A first install under run writes a record, empty when nothing was left out; any install under all removes it. So on a machine under run, a package with no record and a dev or doc file in its manifest is one the machine keeps whole, restored by --dev, built here, or installed as a build tool, and the running root’s database is the only list of them: a slot kdos update apply fills, which holds its own database, has each installed whole again (Updating a machine).

kpkg facets --strip [--root R] [<package>...]   # apply FACETS=run to what is installed; every package when none is named
kpkg facets --list [--root R] <package>         # the record, or "<package>: every facet installed"

--strip removes each package’s dev and doc files from the root, rewrites its manifest and file record without them, appends them to its record, writes an empty record for a package with nothing to leave out, and prints <package>: N files left out, <size> per package it changed and facets: N packages stripped, B bytes (<size>) freed at the end. A file another installed package also claims stays on disk. It is how the base image drops the facets.

A port is not built against a package without its headers. Before kpkg install or --build-only builds a port, it asks whether anything the port compiles against (its declared closure, and musl, linux and gcc, whose headers and libgcc.a every compile reads) has its dev facet left out, and refuses, naming sudo kdos update install --dev <pkg>..., rather than failing deep in a configure script. A database with no record anywhere, as in every build chroot, is answered without walking the closure. kdos update install --source restores those facets itself before it builds; see Building here.

What the rules cannot see is a program that opens a library by an unversioned name at run time: one that dlopen()s libfoo.so finds nothing on a machine without the dev facet, and no image gate sees a dlopen(). No program in the base links a lib<x>.so development link by DT_NEEDED, measured on the full build tree.

Run-time needs

depends = is what a recipe declares, and it names build and run-time needs alike. What a package needs at run time is also found: once its files and file record are in place, kpkgadd reads the package’s run-time files (the facet rules and facet_dev = decide which) and writes /var/lib/kpkg/db/.needs/<name>, one line per edge, sorted:

Edge Found in Provided by
so <soname> each DT_NEEDED of an ELF file, read from its dynamic section with no process; so /<path> when the library is found only on the file’s own RUNPATH <dir>/<soname> in a directory of etc/ld-musl-x86_64.path (musl’s lib, usr/local/lib, usr/lib without one); a path as itself
exe /<path> the #! interpreter of each executable script; #!/usr/bin/env X adds X as the first PATH directory of the root holding it, /usr/bin/X when none does the path
qml <module> each import of an installed .qml file that names a module (import org.kde.kirigami 2.20 as Kirigami); a quoted directory or script is not one usr/lib/qt6/qml/<module path>/qmldir, then usr/lib/qt5/qml/...; a QtQml, QtQuick or QML module with neither is qt6-qtdeclarative’s built-in types
py <name> the top-level name of each column-0 import x or from x import, outside a triple-quoted string, in an executable script whose #! names a Python and in a top-level package’s __init__.py or top-level module directly under site-packages; recorded only when a site-packages directory of the root holds the name usr/lib/python3.<minor>/site-packages/<name>/__init__.py, <name>.py, <name>.so or <name>.*.so; for a namespace package, a file directly in <name>/
need <port> each word of the recipe’s runtime = line: what is loaded by name, which no file shows the installed package of that name

The record leaves out what the package provides itself: a soname that is the name of one of its own files, an interpreter, a qmldir or a Python module (any .py or package directory, a vendored copy too) in its own manifest. The Python rules are conservative on purpose. An import inside try: or if TYPE_CHECKING: is indented, and that is what makes it optional; an import in a submodule runs only when a program asks for that submodule, and read, it would name every optional feature as a need (lxml.html.html5parser imports html5lib, urllib3.contrib imports cryptography); a test module and a file of the documentation facet are not read; and a module of the standard library, or one a program carries beside itself, is in no site-packages, so an edge to it is not recorded at all; nor is a module that reaches a program through a .pth file from a private prefix. A py edge to a module installed after the package is not seen either. What the record misses costs nothing for a port reached by an ordinary depends = edge, which a prebuilt install always follows; a port of ports/buildonly is followed only where the record names it (the binhost’s N: line, below), so a build-only port that a submodule imports at run time is named in the recipe’s runtime =, or a prebuilt install leaves it out (gnuradio’s python3-mako, spyder’s python3-sphinx, matplotlib’s fonttools). testing/pyimports.py reads every import of a built tree, guarded ones aside, and lists those, with the imports whose module is outside the importer’s depends closure; see Testing.

Command What it prints
kpkg needs [--root R] <pkg> The record
kpkg needs --resolve [--root R] <pkg> Each edge with the installed package providing it, (unowned) when a file no package claims does, (nothing) when nothing does; exit 1 when one is provided by nothing
kpkg needs --scan [--root R] <pkg> What the record would hold, measured from the installed files now; writes nothing

Present, even empty, means measured; absent means installed before needs were recorded, and every reader reports such a package as unmeasured, never as needing nothing. kpkg check, kpkg facets and an upgrade leave the record alone; every install replaces it and a removal deletes it.

The record is what proves the base image. script/lib/imageset.py --verify reads the records of the kept packages in a root and resolves each edge the way kpkg needs --resolve does: an edge met by the package itself, a kept package or a file no package owns passes; one met only by a package outside the base fails, naming it; and one nothing provides is counted, and listed with --all, because a module a host program registers in-process (KWin’s org.kde.kwin) and Qt’s Design Studio files under designer/ import what no package installs. On the image stage the dropped packages are gone, so 087_gates.sh passes --full /kdos/build/fs and an edge met only there fails as one “the image drops”. --needs DIR reads records from DIR, which is how a tree whose packages predate the records is measured:

for p in $(ls build/fs/var/lib/kpkg/db | grep -v '^\.'); do
    kpkg needs --scan --root build/fs "$p" > /tmp/needs/"$p"
done
python3 script/lib/imageset.py --root build/fs --verify --needs /tmp/needs --all

Files kpkg keeps to itself

The system Python’s site-packages belongs to kpkg. python3 ships the PEP 668 EXTERNALLY-MANAGED marker, so pip install outside a virtual environment is refused rather than allowed to replace a port’s files, which the next upgrade or removal of that port would delete or conflict with. To install Python software that is not a port, create an environment with python3 -m venv DIR; python3-pip ships the pip wheel that ensurepip installs into it.

/etc/localtime is kept out of every package for the same reason: a file the machine’s owner changes cannot also be a file an upgrade rewrites.

What a build verifies

The kpkgbuild command runs in the port directory. It parses the kpkgbuild file, checks every declared hash, unpacks the sources under WORK_DIR, sources build.sh in a subshell under set -e, and rolls whatever the build staged into a package in PACKAGE_DIR. The build sees these shell variables:

Variable Value
PKGNAME <name>-<version>-<release>.tar.xz
PORT_SRC The port directory
SRC_ROOT $WORK_DIR/<name>
SRC $WORK_DIR/<name>/<name>-<version>, the working directory when build.sh starts
PKG $WORK_DIR/<name>/pkg, where the build installs its files

name, version, release and every recipe-local helper key are defined too, because a recipe is never sourced and cannot define them itself. The first source is unpacked into $SRC with its top-level directory stripped; later tarballs are unpacked unstripped beside it in $SRC_ROOT, and any other file is copied into $SRC. A .zip or .tar.zst is copied, not unpacked, and the recipe unpacks it itself. Extraction runs as root with --no-same-permissions under a umask of 022, so no mode in an archive survives with group or world write: root’s tar otherwise restores every mode an archive carries, a tarball of -rw-rw-rw- files (gimp-help’s is one) becomes a tree of them, and make install copies those modes into the package. A tarball a recipe unpacks itself is outside this rule; the package lint still refuses what it would ship. Extraction also passes --warning=no-unknown-keyword: a tarball made by git archive or bsdtar carries pax keywords GNU tar does not know, and each would otherwise be a line in the build log about nothing that changes a file.

Between extraction and build.sh, every config.guess and config.sub under $SRC_ROOT whose timestamp='YYYY-MM-DD' line is older than the copy automake installs (/usr/share/automake-*/) is overwritten with automake’s, keeping its mode and adding the execute bits. An autotools release cut before musl was known to these scripts guesses the host as x86_64-pc-linux-gnu, and a configure that trusts the guess builds for a C library the tree does not have. A copy newer than automake’s, or one with no timestamp= line, is left as it is, and so is every file inside a vendored Rust crate: a directory holding .cargo-checksum.json records each file’s hash there, and cargo refuses the build when one differs. Before automake is installed, nothing is replaced. The refresh happens before build.sh, so a recipe that regenerates its build system with autoreconf -fi gets automake’s copies either way.

Before rolling the package, kpkgbuild deletes every libtool .la file, because each names build-time paths that do not exist on the target. It copies the licence texts: every regular file at the top of $SRC whose name starts, in any case, with LICENSE, LICENCE, COPYING, COPYRIGHT or NOTICE goes to usr/share/licenses/<name>/, and the files of a directory of such a name (REUSE’s LICENSES/) to a subdirectory there. Source files named like a licence (license.c, COPYING.in) are skipped, a symlink is followed only into the source tree or /usr/share, and whatever build.sh already put at a target name, file or symlink, is kept and never written through. A text the source keeps anywhere else (doc/COPYING, a README section, the comment in a header) is installed by build.sh, which copies a licence the source only names from a package already in the tree, and a public-domain or CC0 source, which holds none, installs none; 70image’s 087_gates.sh reports every package left with no usr/share/licenses/<name>. The ports of our own carry no copy of KDOS’s MIT text: 10bootstrap’s 000_file_system.sh installs the repository’s LICENSE as /usr/share/licenses/kdos/LICENSE, which no package owns, and for a recipe with no source whose license = names MIT kpkg makes the package’s usr/share/licenses/<name>/LICENSE a link to it, so a package of ours carries the link from the binhost as on the image. The recipe’s license = key states the SPDX expression the texts belong to, and kpkg info prints it. It then applies the size and language policy: HTML and PDF manuals under usr/share/doc and usr/share/texmf-dist/doc (except the HTML a program opens itself: mednafen’s manual, the book, R’s help index and style sheet, and the in-app manuals and About pages of geany, gimagereader, texstudio, wsjtx, Wireshark, hatari, FreeCAD and SMPlayer), every non-English message catalog, Qt translation, KDE handbook and manual-page directory, the section-8 manual pages of systemd units (*.service.8 and the other unit types; section 5 stays), and every directory that leaves empty are removed, and objcopy --strip-all --keep-section=.debug_* takes .symtab and .strtab out of each ELF executable or shared object over 32 MiB that carries nothing after its sections. usr/share/licenses is never pruned. These steps run on $PKG before the archive and its manifest exist, so a removed path is never owned by the package. It then deletes every *.dist-info/direct_url.json, which records the work directory pip installed from, and the __pycache__ directories under the bin directories, whose scripts are run and never imported. It compiles every .py the package ships outside the bin directories, etc and var into checked-hash bytecode in the package (python3 -m compileall -f --invalidation-mode checked-hash, recording the installed path rather than the work directory). The bytecode is then in the package and its manifest: /usr is read-only to a running program, so a module without it is compiled on every import and the cache is never written. A package that ships an interpreter’s own library (python3) is left as its install compiled it, and before python3 is installed nothing is compiled. Last, the package lint reads the staged tree.

The package is written as <name>-<version>-<release>.tar.xz.part and renamed to its final name only when the archive is complete; a failed or interrupted roll leaves no file under a package name. kpkg install and kpkg verify install or compare the exact file that build reports having written, never a file found in PACKAGE_DIR by name: with the cache kept, a search for foo- also matches foo-bar-1.0-1.tar.xz.

Before it touches the work directory, kpkgbuild hashes every file a sha256 = entry names that is present beside the recipe or in kpkg’s source directory (SOURCE_DIR, default /var/cache/kpkg/sources), and refuses on any mismatch. This is the only time a source’s bytes are read to be hashed; extraction looks in the same two places in the same order, so the file it unpacks is the file that was checked.

That is wider than the source = list on purpose, because of vendor bundles (see Where sources come from). 173 ports carry a vendor bundle, most of them Go, Rust, Python or Haskell programs, with pdfium among the rest, and each unpacks it in build.sh itself. A vendor bundle is declared with a hash but named by no source = line, so a check that walked source = alone would compile those ports from bytes nothing had looked at.

A declared file that is in neither place is skipped rather than refused. A source the build needs is caught when extraction cannot find it, and failing on a declared file the build never opens would refuse a port over a hash that cannot affect it.

Extraction then checks that every source it unpacks is declared. A source the recipe names with no sha256 = for it is a hard failure, not a warning. KDOS_ALLOW_UNVERIFIED=1 is the escape hatch for bringing up a new port before its hash is known, and testing/preflight.sh checks that no recipe in the tree needs it.

The first source = entry is looked for under the standard name <name>-<version>.<ext> (for example zlib-1.3.2.tar.gz), which is the name ports/fetch saves it under; later entries keep their URL’s basename, and file::url names a file explicitly.

The package lint

The last step before the roll reads the staged tree (src/system/kdos-kpkg/lint.c). Every rule below is a fact about the files a user’s machine receives, so a failure refuses the package: the build prints the first 20 failing paths with ERROR: lint: and a reason, then a count of the rest, and writes no package file. Paths are read with the merged-/usr aliases folded, so bin/x is checked as usr/bin/x.

Rule Fails Allowed
Layout A payload path outside bin, boot, etc, lib, sbin, usr and var; or under usr/lib64, lib64, usr/etc, usr/var, usr/doc, usr/com, usr/lib/systemd, lib/systemd, etc/X11, etc/grub.d or etc/bash_completion.d usr/local, run and var/run in a kdos-* package only
Readable A regular file without o+r that is neither setuid nor setgid etc/shadow*, etc/gshadow*, etc/sudoers, etc/sudoers.dist, etc/sudoers.d/*, etc/ppp/*-secrets, etc/cups/*.conf*, usr/lib/cups/backend/*, etc/freeipmi/*.conf, etc/fwupd/fwupd.conf, etc/mumble/mumble-server.ini, etc/skel/.msmtprc, etc/skel/.mbsyncrc
Executable A regular file under usr/bin or usr/sbin with no x bit Modules and data upstream installs beside its programs: icestorm’s icebox.py and iceboxdb.py, gmsh’s onelab.py, brltty’s brltty-prologue.* and brltty-config.sh, sdcc’s sdcdb*.el, wsjtx’s ALLCALL7.TXT and sounds/
World-writable A path with o+w and no sticky bit var/games/tetris-bsd.scores, 0666: the game is not setgid, so a score file it cannot write as any player saves no score
Patch leftovers A *.orig or *.rej file Cargo.toml.orig and package.json.orig, which are upstream content; Cargo lists the first in each vendored crate’s checksum file
pkg-config A .pc with no or an empty Version; /usr/local or /var/cache/kpkg anywhere in it; --sort-common, -z,now or pack-relative-relocs (the tree’s LDFLAGS) in a Libs line; a module pkgconf --cflags --libs cannot resolve A -f*prefix-map=/var/cache/kpkg/work= flag, which maps the work directory away
ELF An x86-64 executable or shared object with an executable stack, a TEXTREL, or an RPATH/RUNPATH entry under /var/cache, /workspace or /tmp, or neither absolute nor $ORIGIN-based; any ELF file naming /usr/etc or /usr/var as a path Objects under a testdata/ directory; whereis (a search-list entry), useradd (the --usr-skel default) and orca-slicer (a path on the printer) for the /usr/etc string

usr/lib64 and lib64 are refused because the database folds only top-level aliases (kp_canon_load, Who owns a file): with /usr/lib64 a link to lib, ./usr/lib64/x and ./usr/lib/x would be two ownership keys for one file, and neither install would see the other’s claim.

The pkg-config rule resolves every module the package ships with the package’s own pkgconfig directories searched first, as uid 65534 when kpkg runs as root, so a module whose file or whose Requires is unreadable to an ordinary user fails here rather than in that user’s build. A work directory uid 65534 cannot reach is resolved as root instead. Before pkgconf is installed, no module is resolved.

Four findings warn and do not fail, each printed once per build with a count and the first five paths: a group-writable path outside setgid paths and /var/games, an object without BIND_NOW, a plain /usr/lib RPATH entry, and an empty RPATH component, which musl’s loader skips. Writing ports says what a recipe does about each.

Deciding what to rebuild

The build must not recompile some 2,000 ports on every run, and must not skip one whose recipe changed. Two hashes decide, and they are the same two the binary host uses.

E: — the recipe hash

The recipe hash is SHA-256 over the kpkgbuild file, build.sh, postinstall.sh and every .patch file, sorted by name, each contributing its name, its length and its bytes. The length stops two files from hashing the same as one by moving the boundary between them. The result is an exact statement of what a package was built from.

For a port that names a source =, every other file in the directory, subdirectories included, is hashed after the recipe files, in the same sorted name-length-bytes form, except the files a sha256 = line names. A tarball or a vendor bundle is covered by its own sha256 = line, which kpkgbuild checks before it builds anything (see What a build verifies), so hashing it here as well would only change the key for nothing. A port holding only its recipe files and its named sources hashes exactly as its recipe files alone.

The files this reaches are the ones build.sh reads from $PORT_SRC and nothing else vouches for. linux starts its kernel configuration from kdos.config, signs modules under the identity in x509.genkey and copies in its panic-screen logo this way, and epy installs a .desktop file; editing one rebuilds the port. A stray file beside a recipe, such as an editor backup, a kpkgbuild.new or a fetched tarball no sha256 = line names any more, also changes the hash and rebuilds the port; make fetch removes the last kind when it is a hard link into ports/.srccache (see Archives preflight accepts). A directory named __pycache__ is skipped at every depth: it is bytecode Python writes beside a module it imports, and a port that links in a tree of scripts, as kdos-kfs links script/book, would otherwise hash whatever a host run happened to import.

The one file never hashed is kfs.md, the port’s note in the KDOS from Scratch book under docs/kfs. The port’s own build never reads it, so adding, editing or removing it leaves the hash, and the installed package, as they were; this holds for a port with or without a source =. It is skipped only directly beside the recipe: a file of that name in a subdirectory, such as a fork’s src/, is hashed like any other. The note still changes the book’s text, so the book keeps a stamp of its own, docs/kfs/data/recipes.stamp: script/book/kfsgen.py takes every port’s recipe hash by this rule, which must change with kp_hash.c’s, and then hashes every kfs.md, the phase lists and every other file the book reads that no recipe hash covers. A changed note stales the stamp, testing/kfscheck.py fails until make book-stamp rewrites it, and the rewritten stamp under docs/kfs changes the recipe hash of kdos-kfs, the port that ships the book, and of no other.

A port with no source = is different, and this is what keeps the rule true for this tree’s own code. Such a port builds out of its own directory: nothing names those files and no checksum covers them. If only the four recipe files were hashed, editing a .c file would change nothing the build can see. The port would report as installed and current, and the tree would keep the binary it already had. The symptom would never be a build error; it would be a shipped program behaving like an older one.

So a source-less port hashes its whole directory, sorted at every level. A port under src/ hashes all of src/libs with it: the library directory is found at ../../libs from the port, which from src/<area>/<name>/ is src/libs. Each build.sh names which libraries it compiles, and working that out would need a shell parser inside the package manager, so every library is included. The two source-less ports in ports/core, containers-common and musl-ldd, compile none of those libraries. From ports/core/<shelf>/<name>/, ../../libs is ports/core/libs, which does not exist, so their hash covers their own directory alone. This is why no shelf may be named libs: a shelf by that name would be hashed whole into both recipes, and preflight and the pre-push hook refuse it.

The cost is that editing one library rebuilds every port of KDOS’s own, not only the ones that use it. Upstream ports’ hashes are unaffected. Decisions weighs that cost.

B: — the build-config hash

The build-config hash is SHA-256 over the architecture, the C library (always musl), the target triple (KDOS_TARGET, or native), the compiler as $CC names it (cc when unset) with the version its -dumpversion prints, and the CFLAGS, CXXFLAGS and LDFLAGS. Two machines with the same B: produce comparable binaries; two with different B: do not, whatever the recipe says.

Every term but the architecture and the C library is read from the environment of the process running kpkg, not from any file. The build’s chroot phases set CC, CFLAGS, CXXFLAGS and LDFLAGS in script/env/chroot.env and script/env/common.env (CC=gcc, and flags that carry -ffile-prefix-map and -Wl,--build-id=sha1) and leave KDOS_TARGET unset; a shell on an installed machine sets none of them. The same compiler therefore hashes to a different B: at a login prompt than inside the build.

KPKG_CC_ID, when set, is the compiler field itself, and no compiler is run. The image’s stage step writes the build’s CC, CXX, flags and KDOS_TARGET into /etc/kdos/chroot.env with KPKG_CC_ID=<CC> <version>, asked of the compiler before the strip leaves gcc’s driver out, and kdos update loads that file before every kpkg it runs. A machine installed from the image has no compiler to ask, and without the record it would hash cc=unknown and match no prebuilt package. The same file carries what else a recipe’s result depends on and the hash does not name: the Rust -sys crate switches that link the system library instead of a crate’s own copy, CMAKE_BUILD_TYPE, the Cargo and Go settings and SOURCE_DATE_EPOCH, with CONFIG_SITE and KDOS_BUILD_PATH naming the build’s autoconf site file and its ninja and meson wrappers, copied to /usr/share/kdos/build. kdos update sets every line, and puts KDOS_BUILD_PATH first on PATH, so a port built on the machine is built as the binhost’s was.

Both hashes include their field names, because a hash over values alone collides the moment two fields swap.

The three states

With KPKG_STRICT_RECIPE=1, which script/env/common.env sets for every build phase, kpkg compares an installed package’s recorded recipe hash with the port as it stands. Without it, as in an interactive kpkg install, an installed package is skipped whatever its recipe says. With the check on:

State Result
Hashes match Skip
Hashes differ Rebuild
No recorded hash, or a corrupt one Skip

The third row makes the check safe on a tree that has packages without a record: absent reads as unknown, never as changed, so no package is rebuilt merely for lacking a record. A record that is not exactly 64 lowercase hex digits is treated the same way; reading it as a mismatch would rebuild that one package on every run, with nothing saying why. The price is that a package with no record is never rebuilt for a recipe change. Only a direct kpkgadd leaves a package without one, and it does so even over a package that had a record, since it removes the old record before it writes the entry; such a package stays as it is until kpkg install -f builds it again.

The hash is taken from the port directory when the build starts, and recorded in /var/lib/kpkg/db/.recipe/<name> after a successful install, never before. A record written ahead of a build that then fails would claim a recipe is installed that is not. Because the hash is of the recipe the build started from, an edit made to the port while it builds leaves a record that does not match the edited port, and the next strict run rebuilds it. It is a separate file rather than a field of the database entry, so the entry keeps the fixed shape given under Packages: the version and release on the first line, then the manifest.

The dependency solver applies the check, not the install loop. An installed and current package is dropped before the loop runs, so a check placed later would reach only packages named on the command line and miss every dependency whose recipe changed.

The build orchestrator asks the same question on the host before it enters the chroot. A package phase’s order is resolved against an empty database, so it names every port in the phase’s closure; kdosbuild calls the same kp_installed_current() for each, over build/fs/var/lib/kpkg/db and the phase’s repositories as the host sees them, once when the phase’s order is resolved and again when the run reaches the port, and a port that is still installed and current then never becomes a kpkg install step. A port the build plan forces, and one the host cannot find, still run, and kpkg applies the check again to every step that does. See How a phase runs.

The package store

A port whose recipe, environment and dependencies are exactly those of a package built before is installed from that package instead of being built. The store is build/pkgstore, it is off by default, and make build KDOS_PKG_STORE=1 turns it on (check builds anyway and compares; see below). Inside kpkg it is KPKG_STORE=<dir>, and it applies to kpkg install and to --build-only, after the installed-and-current skip and before the build. -f never reads it.

build/pkgstore/<key[0:2]>/<key>/
    <name>-<version>-<release>.tar.xz
    META        P: V: R: F: C:<sha256 of the file>, one X:<name> <pkgsha> per undeclared link

The key is SHA-256 over field=value lines:

Field Value
format KP_STORE_FORMAT in kpkg.h, raised whenever build.c, prune.c or lint.c changes what a package holds
recipe The port’s recipe hash, as .recipe/ records it
pack kept or transient, the xz setting the package carries
salt KPKG_STORE_SALT: kdosbuild hashes script/phases/00_cross, script/phases/10_bootstrap, script/lib, script/env, the recipe hash of every port those scripts build, and fs/etc/passwd, group and ld-musl-x86_64.path. With no salt the key is unknown, and every port builds without storing
env The sorted environment, less job counts (MAKEFLAGS, NINJAFLAGS, KDOS_JOBS, CMAKE_BUILD_PARALLEL_LEVEL, CARGO_BUILD_JOBS), the compiler cache (KDOS_CCACHE, CCACHE_*, the CMake launchers), every KPKG_*, the packaging and store switches, KDOS_PHASE_*, KDOS_SNAPSHOT_*, MARK, CHROOT, PORT_REPO, TERM, PWD, OLDPWD, SHLVL and _
dep <name> <pkgsha> for every port in the declared transitive closure and in KPKG_STORE_BASE (set in script/env/chroot.env: the toolchain and base userland), sorted; - for one not installed

<pkgsha> is the .pkgsha/ record: the hash of the package file, so a dependency rebuilt into different bytes changes the key of everything above it. An installed member with no .pkgsha makes the key unknown: the port builds and nothing is stored. The file hash depends on the xz setting, so a build that keeps its packages (KDOS_MAKE_BINHOST=1) and one that does not key every dependent port differently; that costs misses, never a wrong hit.

A hit prints Reusing <pkg> from the store (<key12>), installs the stored file, records the recipe hash, and marks the entry used. A miss builds, and once the package is installed it is stored under the key computed before the build. Each file is written under .tmp.<pid> and renamed, META last; a directory without META is not an entry. A stored file whose hash differs from its C: is a miss. No store failure fails an install.

X: lines cover what the key cannot see. After the install kpkg reads each ELF file the package owns (its DT_NEEDED, with no process per file), resolves each library in usr/lib, lib and usr/local/lib, and looks up the owner. An owner that is not the port and not in its closure is an undeclared link: <pkg> links <owner> without declaring it is printed and the entry gets X:<owner> <pkgsha>, which a lookup requires to match what is installed. They cannot see a library opened with dlopen, a header-only or static dependency, a tool the build ran, or a feature a configure script switched on because it found something; see Known gaps.

Check mode

KDOS_PKG_STORE=check (KPKG_STORE_CHECK=1) builds every hit anyway and compares the result with the stored file. A difference appends <pkg> <key12> stored=<sha> built=<sha> and the first members that differ to build/logs/pkgstore-check.log, and the entry is replaced; the install never fails. A port that shows up there is not reproducible, or reads an input the key does not cover.

Why the binhost’s identity is not reused

A binhost entry is matched on architecture, build-config hash and recipe hash (The binary host). That is enough for a finished system installing a finished package; it has no dependency term, so during a build it would install a package linked against a library that has since changed. The store key names every dependency’s exact bytes instead.

Eviction

kpkg store gc <dir> <max-size> deletes entries, least recently used first by META’s modification time, until the store fits. 70_image’s 015_pkgstore.sh runs it when the store is on, with KDOS_PKG_STORE_MAX (default 60G).

Reproducible packages

A package built twice from the same tree is byte-identical. That is a property of one function, the archive roller inside kpkg, rather than of some 2,000 recipes, which is why kpkg rolls the archive itself instead of letting each build.sh do it.

Each setting removes one source of difference between two builds:

Setting Without it
--sort=name Directory order is filesystem order, which is not stable even between two copies of the same tree
--mtime=@$SOURCE_DATE_EPOCH Every file carries the second it was installed; with the variable unset, kpkg uses 0
--owner=0 --group=0 --numeric-owner The builder’s user id, and its name as text in the header
--format=gnu Extended (pax) headers carry access and change times, which are wall clock; plain ustar cannot hold a path over 255 bytes, which some ports have
--use-compress-program=xz -9 -T0 --block-size=32MiB --no-adjust The compressed bytes depend on the preset and the block size, which are pinned; the thread count does not reach them
XZ_OPT and XZ_DEFAULTS held out of the environment while xz runs -e or --check in the environment changes the bytes, and a memory limit would lower the dictionary; every port’s build.sh, including the next one in the same kpkg install, still sees both
umask(022) before the build A file created without an explicit mode takes the builder’s umask: the one source of drift that is not in the archive call

Multi-threaded xz is deterministic: any -T of one or more in its multi-threaded mode writes the same bytes on one core or sixteen, which the self-test checks by recompressing a package with xz -9 -T+1 --block-size=32MiB and comparing. -T1 is a different encoder, the single-threaded mode, with different output, and is never used to compress a package; decoding takes -T1 (kpkgadd’s extraction), which bounds an install’s memory and changes no bytes. --no-adjust turns a memory limit that would lower the dictionary into a failure instead of a different package. Both xz builds in the tree are built with threads, which the multi-threaded mode needs.

Only a package that nothing reads after its install gets the cheap -0 preset: kpkg install without a kept cache, which deletes the file once kpkgadd has read it. kpkgbuild on its own, kpkg install --keep-cache (so every package of make build KDOS_MAKE_BINHOST=1), kpkg verify --repro and kpkg apply-delta all use the kept setting, so every package that can be published, compared or rebuilt from a delta has the same bytes. A change to the kept setting changes every package’s hash, so a published binhost and its deltas are regenerated together. kpkgbuild reports the time each package took to roll as Packaged <name>: <N> MB in <s> s, the size being the staged tree before compression.

The other half is five settings in script/env/common.env, which every phase’s environment sources:

Line Purpose
SOURCE_DATE_EPOCH=1735689600 A pinned epoch, not the current date and not derived from git: the build container mounts build, src, fs, script, ports, docs, testing, the Makefile, the Dockerfile and LICENSE, never the repository’s .git
TZ=UTC Dates formatted during the build do not depend on the builder’s zone
LC_ALL=C Sorting and formatting do not depend on the builder’s locale. The chroot phases replace it with C.UTF-8 in script/env/chroot.env; musl collates every locale byte by byte and formats dates in C.UTF-8 as in C, so the output is the same
-ffile-prefix-map=/var/cache/kpkg/work=/build, on CFLAGS and CXXFLAGS, and on FFLAGS and FCFLAGS where the phase sets them Rewrites the build directory out of __FILE__ and debug paths
-Wl,--build-id=sha1 The build identifier is a function of the contents, not random

The compiler cache never changes a byte. CMake ports in the chroot compile through ccache (see The compiler cache), and three settings in script/env/chroot.env make a cached object the one a compile would write: no base_dir, which would rewrite paths past -ffile-prefix-map; a compiler check that is a string of the compiler ports’ recipe hashes, gcc’s version and the epoch, never a modification time kpkg has pinned; and the compiler launched through CMake’s launcher variables rather than a masquerade directory, whose path CMake would record in shipped files. testing/preflight.sh fails when any of them changes.

ports/fetch rolls vendor bundles with the same tar settings and its own pinned xz -9 -T1, so regenerating a bundle reproduces the file its sha256 = names; that compressor is part of every vendor bundle’s hash and is not the package compressor.

The kernel takes four more values from the builder unless told otherwise, and linux’s build.sh pins them: KBUILD_BUILD_TIMESTAMP (SOURCE_DATE_EPOCH written as a date), KBUILD_BUILD_USER and KBUILD_BUILD_HOST (both kdos) and KBUILD_BUILD_VERSION (1). Left unset, uname -v and the boot banner carry the build container’s hostname and the second the build ran. Its module-signing key is pinned too, in build/keys/ (see Module signing). The linux package is still the one exception to byte-identical builds: an ECDSA signature uses a fresh random number each time it is made, so every module’s appended signature differs between two builds of the same tree (see Known gaps).

Reproducibility is what makes a signed binary host meaningful, what lets a delta rebuild a package that still verifies against the original signature, and what lets a rebuild be checked against what it was built from (kpkg verify --repro).

The binary host

A binary host (binhost) is a directory of prebuilt packages with a signed index. Everything in it can also be built from source on the machine; a binhost saves the compiling. kpkg binhost reads a directory: a USB stick, an NFS mount, or the cache kdos update downloads a release’s binhost into (see Updating a machine).

kpkg keygen builder                      # once, on the machine that builds
kpkg index /repo --sign builder.key      # PACKAGES + PACKAGES.sig + a sidecar per package
cp builder.pub /etc/kdos/keys/           # on every machine that should trust it
kpkg binhost /repo zlib                  # install it, or say why it will not

The index, PACKAGES, is a flat text file in the shape Alpine uses: single-character keys, one stanza per package, a blank line between stanzas. It parses in a few dozen lines of C and reads well in a pager. A header stanza (K:kdos-index-1, then the indexing machine’s A: and B:) opens the file. Each package stanza carries:

Key Value
P: V: R: Name, version, release
A: Architecture
F: The package file name
S: C: Its size and SHA-256
I: The bytes the package takes once installed: the larger of its tar’s unpacked size, read from the .xz file’s own stream index with nothing decompressed, and the disk its installed files take on the indexing machine when that machine holds the same version and release with a file record. The tar’s size alone undercounts a package of many small files, each taking a whole block on disk, and the measure alone undercounts on a filesystem that compresses. Absent when neither can be read; kpkg index says how many packages carry none. kdos update install sums it to refuse an install that would not fit on the root (kdos update install), and reads a stanza without it as unsized
B: The build-config hash of the machine that wrote the index
E: The recipe hash, taken from the ports tree on that machine; empty for a package whose port that tree does not have, or for a file whose version and release are not the ones its recipe there declares
T: The recipe’s description
N: Written by kpkg index --buildonly <file> only: the ports of that list the package needs at run time, space-separated, from its run-time needs record in the indexing machine’s database (empty: measured, none needed). Absent for a file whose version and release are not the installed ones or a package with no record, which a client reads as unmeasured

Three equality tests decide whether a prebuilt package is usable, and there is no “close enough”: the architecture, the build-config hash B:, and the recipe hash E:. Anything else builds from source. kpkg binhost says which test failed, and its exit status says what happened:

Exit Meaning
0 The prebuilt package was used, or under --dry-run would be
1 No match, so build it from source; also a usage error, or a matching package whose install failed
2 Refused: no index, no trusted key, or verification failed

Because B: is read from the environment (see B: — the build-config hash), the client must run kpkg binhost with the CC, CFLAGS, CXXFLAGS, LDFLAGS and KDOS_TARGET the indexing machine had. A binhost the build wrote was indexed under the chroot’s environment, so kpkg binhost typed at an ordinary shell reports different build config for every package in it.

The package goes in through kpkgadd, into --root or KPKG_ROOT when either is set. After a successful install kpkg binhost records the stanza’s E: as the package’s recipe hash, the way kpkg install records its own, since that E: equals this tree’s recipe hash (see The three states).

make build KDOS_MAKE_BINHOST=1 writes such a directory at build/binhost/: every kpkg install of the build keeps the package it made, and the image phase, 70_image, moves them there and indexes them with the key build/binhost-key/kdos-binhost.key, made on the first such run and never replaced; its public half is copied beside the index as kdos-binhost.pub. Beside them it writes swcatalog--xml--kdos-binhost.xml, signed with the same key: the AppStream catalogue of the applications those packages install, from which Discover offers ports to install. Its writer, kdos-discover-catalog, takes a metainfo component that names no desktop-id launchable to launch usr/share/applications/<id> (or <id>.desktop) when the same package owns that entry: the component is written with that launchable and, when it names no icon, the entry’s Icon=, and the entry is not written again as a component of its own. Every name in the directory is flat, because a release asset cannot sit in a directory, and the last thing the phase writes is the directory’s release index, kdos-update.idx, signed with the binhost key, which names each file at the path a client asks for (binhost/PACKAGES, binhost/<package>, binhost/swcatalog/xml/kdos-binhost.xml) with its size and SHA-256. The directory, copied to a stick or served as it is, is a place binhost = in update.conf can name. The directory accumulates: each run adds the packages it built and keeps the current ones earlier runs left, and --fresh removes nothing from it. kpkg index takes each package’s E: from the ports tree it runs on, looked up by package name, and writes it only for the file whose version and release are the ones that recipe declares. The step indexes with PORT_REPO set to every repository the build installs from, /ports/core and the four src/ areas, so a package of KDOS’s own carries its recipe hash like any other; a machine finds the same recipes under /ports/src/<area> and computes the same hash. A superseded file an earlier run left, or a file of a port the tree has no recipe for, gets an empty E:; the step moves each such file and its .sig to build/binhost-superseded/, outside the directory, and indexes again, so PACKAGES, the catalogue and the release index name the same files and a client is only ever handed the current recipe’s build. A delta (a stanza with O:) stays.

Each package’s N: line names the build-only ports it needs at run time. The step runs kpkg index --buildonly /ports/buildonly over the build tree’s database: for a file of the version and release installed there, kpkg index reads the package’s run-time needs record, resolves each edge to the installed package that provides it, and writes the ones ports/buildonly lists, in that file’s order, as N:<port> …. An empty N: says the package was measured and needs none of them; a stanza with no N: (a package installed with no needs record) is unmeasured. kcharselect’s line is empty, so a prebuilt install of it takes no cmake; wesnoth’s names boost. The record reads the run-time facet alone, so a program only a build runs, linked against a build-only port, belongs in the recipe’s facet_dev =: python3-pyside6 puts its shiboken6 binding generator there, the one file of the package that links libclang, and its N: line then names no clang, so a prebuilt Falkon or FreeCAD installs the bindings without the compiler. chromium’s line is empty, and ports/buildonly lists the compiler-rt, crubit, esbuild and typescript-go its build runs, so a prebuilt Chromium takes none of them, nor crubit’s rust. 70_image/087_gates.sh fails a KDOS_MAKE_BINHOST=1 build that leaves a current stanza (one with an E: and no O:) without an N: line.

The release index names what PACKAGES names. Both are written over the directory once the superseded files are out of it, so a release carries exactly its own tree’s packages and a client is never pointed by PACKAGES at a file no release holds. A package file larger than one release asset (KDOS_PART_SIZE, 1,900 MiB) fails the step, because kdos update install takes a package whole and the release could not carry it.

The binhost is the release’s package repository. It holds every port the release built, the ones its base image leaves out included, and a machine takes the binhost of the release its /ports/TREE names, so its packages are always the ones built against the base it runs. ports/publish --release publishes the directory with a release; see Publishing a release.

Gentoo solves the same problem by matching USE flags between the builder and the client. KDOS has no USE flags, so the whole question reduces to these equality tests. kdos update takes a release’s binhost as one of its lanes, and kpkg binhost is also a tool to run by hand; How KDOS differs sets this against other distributions’ update models.

Signing

Signatures are Ed25519, through Monocypher, a vendored implementation dual-licensed BSD-2-Clause and CC0, under src/libs/libksig/monocypher. See The C libraries.

One signature over the index covers every package, because the index carries each package’s hash. A per-package sidecar signature, <file>.sig, exists for the separate case of a package travelling on a stick with no index beside it. Signing the index, not every package gives the reasoning, and Signing and trust sets these keys beside the system’s other keyrings.

The scheme keeps these rules:

The trusted directory is the policy: every readable *.pub key file in it is a trusted key, up to 16, taken in name order; a seventeenth and any after it are not loaded, and the loader names each one on stderr (<dir>: a keyring holds at most 16 keys; <name> is not trusted). There is no revocation list and no online check: trusting a key is copying a file in, and removing trust is deleting it. The loader does not descend into subdirectories, which keeps /etc/kdos/keys (host packages), /etc/kdos/keys/packs (application packs) and /etc/kdos/keys/tree (the signed ports tree kdos update fetch takes) separate policies.

Ports built from source are not signed and need no signature. A port is compiled on the machine that installs it, and its integrity rests on the sha256 = lines in its recipe. A signature identifies who built a binary, which for a locally built package is the machine itself, so it adds nothing.

Deltas

kpkg delta zlib-1.3.1-1.tar.xz zlib-1.3.2-1.tar.xz
kpkg apply-delta zlib-1.3.1-1.tar.xz <delta> -o zlib-1.3.2-1.tar.xz

A delta is a binary difference between two packages, so a machine that already has the old version downloads kilobytes instead of the whole package. Without -o, kpkg delta names the file <new>--from--<old>.kdelta, which is the name kpkg index recognises. The engine is zstd --patch-from, with two design decisions around it.

The first is that the delta is taken over the uncompressed archives. Two compressed files built from nearly identical trees share almost no bytes, since removing repetition is what a compressor does, so a delta between them is as large as the package.

The second is that a delta is never trusted, and never needs to be. It is applied, and the result is hashed against the entry the signed index already carries. A tampered delta produces a package whose hash does not match, which is discarded; it cannot make a client install anything the index did not already name. So there is no delta signature and no second trust path.

A delta appears in the index as its own stanza: the P:, V:, R: and A: of the package it rebuilds, the F:, S: and C: of the delta file, and O: naming the package file it applies to. It has no B:, E: or T:. kpkg binhost uses one only when that old package file is still in PACKAGE_DIR; kpkg install deletes each package it builds unless given --keep-cache. kdos update’s binhost lane does the same against its own cache: when the signed index names a delta from a package file the cache still holds (the previous release’s, which the cache keeps while a delta names it), it downloads the delta from where the release index says it is, checks it against its own hash in both indexes, and rebuilds the package with kpkg apply-delta --expect. Any failure along the way, a delta that does not match the index, does not apply, or rebuilds the wrong bytes, falls back to the full package.

Slot images

A slot image is a whole root filesystem as a release built and tested it, signed, in a form a machine can write into the inactive one of its two A/B root slots. It is the first way a release reaches a machine (see Updating a machine), and kdos image is the one program that both makes and reads one, so the format has one reader and one writer:

kdos image make ROOT OUTDIR --version V [--key FILE] [--prev DIR [--prev-root DIR]]... [--exclude PATH]...
kdos image verify DIR|URL [--keys DIR]
kdos image unpack DIR|URL TARGET [--seed ROOT] [--keys DIR]
kdos image carry RUNNING SLOT

An image is a manifest and the objects it names. The manifest, kdos-image.manifest, is text, signed with the release key like a binhost index, and lists every directory, regular file, symbolic link and hard link of the root with its mode, owner, modification time and, for a file, its size and SHA-256, in a strict order with every entry’s parent before it; a path outside printable ASCII is escaped as %XX. An object is the content of a regular file, named by its hash. The objects travel in bundles, each one zstd stream of records:

Bundle Holds
kdos-image-<V>.full.NNN Every object once, cut into parts under 2 GiB, the limit of one release asset
kdos-image-<V>.from-<P>.delta One per earlier release P a machine may still run: the objects P lacks, each whole or as a zstd --patch-from patch against the file the same path held in P, and every object under etc/ and var/, which a running machine has usually edited

Nothing in a bundle is trusted. Every object, whole or patched, is hashed after it is written and kept only when the hash is the one the signed manifest gives, so a bundle carries no signature of its own and a tampered one costs a download, never a file. The manifest is verified against the host keyring, /etc/kdos/keys, before a byte of it is read.

The patches are per file. zstd --patch-from needs a window covering the whole reference, and its window stops at 2 GiB; a slot holding Plasma and all of KDE Gear is several times that. A patch per file stays inside the window, and the manifest says which files changed at all, so most of a slot is copied from the root the machine is running and only what changed is downloaded. A base too large for the window is shipped whole.

A slot is synchronised, not formatted. kdos image unpack keeps a file the target already holds with the right hash, copies one the running root (the seed) holds, takes the delta for the release the running root was written from, and reads the full bundle only for what is still missing. Entries the manifest does not name are removed, except lost+found and anything on another filesystem. The slot keeps its filesystem and its UUID, whichever filesystem the installer gave it. A root written from an image records the manifest it was written from at /var/lib/kdos/image/MANIFEST, which is how the next update picks its delta.

What an image leaves out: the kernel’s filesystems and what exists only at run time (dev, proc, sys, run, tmp, mnt, media), the shared home and the pack store (packs and boxes are never in a slot image), and the image record itself; under var/log, var/cache and var/tmp it keeps the directories, which packages own, and none of the files. A file carrying a file capability or an ACL is refused rather than carried without it.

The system’s trees have one owner. A slot is written with the owners its manifest gives, so a builder’s uid recorded on / or /ports would hand the root directory and the recipe tree to the machine’s first account. kdos image make and kdos image verify (exit 3) refuse a manifest in which ., a top-level entry, or anything under etc/, usr/, boot/ or ports/ has an owner other than the root directory’s, and make run as root, and a root slot fill, refuse one where that owner is not root. Elsewhere (var, root’s home) other owners are the system’s own.

Every file is found through the release index. kdos image make writes kdos-update.idx beside the manifest, signed with the same key, naming the manifest, its signature, every part and every delta at image/<name> with its size and SHA-256 (see The release index). kdos image unpack and kdos update read that index first, take the manifest only when it hashes as the index says and names the index’s version, and read each bundle from the URL the index gives.

script/release-image.sh is the release step that runs kdos image make over the root the ISO is squashed from, with this checkout’s own kdos-tools, and verifies the result against the key’s public half before it ends. It always works in a mount namespace of its own, over a read-only overlay whose top layer is the run’s own: /mnt and /media (0755, root’s), as 110_iso.sh adds them, an empty /boot/efi (0755, root’s), and whiteouts over /kdos and /build, which the ISO excludes. The image must name /boot/efi because a machine running KDOS 0.2 applies it with that release’s kdos update, which deletes every path the manifest does not name and creates no fstab mount points; without the entry the slot would boot with no EFI system partition mounted and roll back. With --upper the layers below are the image stage’s upper layer and build/fs, and the top layer also holds a copy of the recipe tree 105_ports.sh staged (build/image-ports, or --ports), owned by root as the ISO’s /ports is, since build/image-ports belongs to the builder. That is what the ISO carries: its /ports is appended to the squashfs after the stage, so an image of the stage alone would boot a slot with no recipes, and would carry no TREE time for a machine to judge it newer by. ports/publish --release publishes the directory it wrote; see Publishing a release.

The release index

A published release’s updates are flat files spread over several GitHub releases, so no client can spell a file’s URL from its name. kdos-update.idx says where each one is, and kdos update takes no file it does not name:

# kdos-update-index 1
version 0.3.1
releases https://github.com/kunaldawn/kdos/releases/download
<sha256> <size> binhost-0.3.1-01 zlib-1.3.2-1-x86_64.tar.xz binhost/zlib-1.3.2-1-x86_64.tar.xz
<sha256> <size> image-0.3.1 kdos-image.manifest image/kdos-image.manifest

One line per file, sorted by path. The path is the name a client asks for: binhost/<file> for the binhost’s index, packages, sidecars and deltas, binhost/swcatalog/xml/kdos-binhost.xml for its catalogue, image/<file> for a slot image’s manifest, parts and deltas. The asset is the flat name the file is stored under, the path below its lane with every / written --, and the release is the GitHub release that holds it, joined to the releases root. A release of - is a file beside the index, which is how a producer lays out its own directory (build/binhost, a slot image’s output directory, a stick); such an index has no releases line.

The index is verified before a line of it is read, against the host keyring (/etc/kdos/keys), the ring the binhost index and the image manifest are verified against. Every file it names is downloaded to a temporary name and kept only when its size and SHA-256 are the ones its line gives; the binhost index and the image manifest are then verified by their own signatures as well. A cached binhost index or manifest is believed only beside the cached index that names it, which is the one an apply downloads by, and an index whose version is not the release of the tree in place (for the binhost) or of the image it names is refused. Each refusal is recorded as unverified. The writer is ports/releaselib.sh, shared by 010_binhost.sh and ports/publish; kdos image make writes the same format, and src/system/kdos-tools/relidx.c reads it.

Publishing a release

ports/publish --release <tag> puts a system release on GitHub: the ISO, the sources list, the signed recipe tree and SHA256SUMS in the release <tag> (see Writing ports for the sources side), and its updates beside them, published the way the source archive is:

Release Holds
<tag> The ISO, sources.sha256, kdos-ports.tar.xz and its signature, SHA256SUMS and its signature, kdos-release.pub, and kdos-update.idx with kdos-update.idx.sig
binhost-<tag>-01, -02, … The binhost (--binhost, default build/binhost): every file its release index names, sorted by path and split into releases of at most 1,000 assets, GitHub’s limit
image-<tag> The slot image (--image, default build/release/<tag>/image), which script/release-image.sh makes for version <tag>

Each lane is taken from its directory’s own kdos-update.idx, and every file is hashed against it before anything is sent; a directory without one publishes no lane. The update releases are public pre-releases, never Latest, so their assets download without a token while the system release is still a draft. Every upload is append-only and resumable, as for sources; a lane directory that changed between two runs for one tag shards differently, and a run that would then leave a release holding more than 1,000 assets stops before uploading to it. The release’s own kdos-update.idx is written from the names GitHub reported storing, with a releases line naming the repository’s download root, and signed with the release key and, when build/binhost-key/kdos-binhost.key is there, with the binhost key as a second line, so a machine trusting either verifies it. The recipe tree kdos-ports.tar.xz carries the tag’s ports/RELEASE as /ports/RELEASE beside its TREE, and the tag’s ports/buildonly and ports/buildheaders beside them, which kdos update reads to cut a prebuilt plan and to install the header ports a build needs; its TREE carries version <tag>, which is how a machine holding the tree finds the release’s index again. --dry-run prints every release, its asset count and size, and the index, hashing every file and touching no network.

A release image must name its release. Before it hashes or uploads anything, --release reads the ISO’s /ports/TREE and /ports/RELEASE out of its system.sfs (with xorriso and unsquashfs, which it needs with xxd) and refuses an ISO whose TREE names another commit, has no version <tag> or names another release, and one that carries no /ports/RELEASE; it refuses a tag that has no ports/RELEASE, or one over 16 KiB, the most kdos update notes reads. A real run then stops with <iso> is not a release image of <tag>; build the ISO from a clean checkout of the tag, then run again; a dry run prints each as a FAILED line and exits 1. A machine installed from a released image therefore always finds its release’s binhost.

The release’s notes are written from the tag: About this release (the tag’s ports/RELEASE, each of its headings moved one level down so its sections sit inside that one); the live ISO and its kdos account, password kdos, also root’s; what it needs (x86-64, UEFI or BIOS firmware, 4 GB of memory, Secure Boot off), what the image carries and the medium to write it to. The tag’s ports/RELEASE says what the image carries, so its notes leave that sentence out, and a ports/RELEASE with a What it needs section of its own names the live account and the requirements, so its notes keep only the medium line under Download and leave out the account, the machine and the disk sentences; each fact is stated once. The disk sentence gives the disk two system slots need, worked out from the ISO’s system.sfs and the tag’s kinstall-core figures (kinstall-core.h’s limits, KI_DISK_MARGIN and KI_ROOT_FREE_MB, conf.c’s KI_VOLUME_META_MB and default cfg.swap_mb), with and without the default swap, and the smallest disk one slot takes. The notes end with links to the tag’s Getting started and Installation pages and how to check SHA256SUMS and, with OpenSSL 3 and xxd on a system that is not KDOS, its signature. A figure the tag’s sources do not give, or give twice, leaves the disk sentence out with a FAILED line rather than a guess. --dry-run writes the notes to build/release/<tag>/notes.md.

Updating a machine

kdos update is the command a person types, and the one Discover drives through kdos-sysupdated. It fetches a signed recipe tree and the release that goes with it, and drives kpkg, kdos image and the tool that manages the A/B root slots (an installed disk’s two root filesystems, one running and one receiving updates; see Boot and init).

Command Does
kdos update check Compare what is installed with what the tree on this machine pins and what the fetched release offers, and report the last problem; exit 1 when something is behind. --fetch fetches first; --json and --out FILE write the update document
kdos update fetch Replace /ports with the newest signed tree, and fetch the release’s signed release index and, through it, the binhost index and slot-image manifest; --binhost-only fetches only the release index and binhost index of the tree in place
kdos update apply Write the newer release into the inactive slot, as its slot image or from its binhost, and arm the slot to be tried; --source builds it on the machine instead
kdos update install <port\|group> Install one port or group, and every package it lacks, into the running root, prebuilt from the release binhost or built here; see Installing more software
kdos update remove <port> Remove one port somebody installed and nothing installed needs, with what it brought that nothing else needs, and their cached packages; --dry-run lists what it would remove
kdos update removable List the installed ports remove takes, and those left behind by earlier removals; --json for a program
kdos update groups List every group, whether it is installed, and what installing it would add
kdos update notes Print the release notes of the running slot, from the /ports/RELEASE its tree carries; --json for a program; exit 1 when the slot carries none
kdos update theme Re-apply the accent to the home directory after an update

New versions arrive with the ports tree, because a recipe pins its version. Every image carries the recipe-only tree at /ports, without the source archives; see How KDOS is built. A newer one arrives over the network: ports/publish --release puts the tree of the release’s commit beside the ISO as kdos-ports.tar.xz, with a TREE stamp naming the commit, its time and the release, signed with the release key as kdos-ports.tar.xz.sig.

The image’s own tree names its release when the build was a release build. 105_ports.sh writes /ports/TREE with kdos-tree 1, commit and time, and adds version <tag> only when KDOS_GIT_RELEASE is set. script/chroot/exec.sh sets it, when the checkout is clean (untracked files included), to the one release tag on HEAD: KDOS_GIT_TAG, which the Makefile takes from git tag --points-at HEAD --list 'v[0-9]*', so an archive tag such as sources-N never names a release. When HEAD carries several release tags the build stops until one is named with make build KDOS_GIT_TAG=<tag>, and KDOS_GIT_TAG=none builds with no release. On any other checkout KDOS_GIT_RELEASE is empty. The build’s log says /ports/TREE names release <tag>, or why it does not.

/ports/RELEASE holds the release’s notes, copied from ports/RELEASE, which kdos update notes and What’s New read; the build fails without it, or with one over 16 KiB.

What kdos update fetch does:

  1. It downloads the tree and its signature from the latest release, unless --from, KDOS_UPDATE_TREE or tree = in /etc/kdos/update.conf names another place.
  2. It verifies the signature against /etc/kdos/keys/tree, which holds the public half of the release key the image was built with, and only then unpacks the tree and exchanges it with /ports. A tree older than the installed one is refused.
  3. It takes the release’s release index and, through it alone, the binhost index (PACKAGES and PACKAGES.sig) into /var/lib/kdos/binhost and the slot-image manifest into /var/lib/kdos/image/offer.

The binhost’s index is read from binhost = in update.conf, KDOS_UPDATE_BINHOST, or the release <version> that the tree’s TREE names. When the tree names a release, the release index must be for that version. A build/binhost carries the build’s KDOS_GIT_RELEASE as its index version on a clean tagged build, and otherwise the commit cut to twelve characters, so it serves the tree the same build wrote, named or not. The image’s manifest is read from image =, KDOS_UPDATE_IMAGE, or the latest release.

When no binhost can be found, fetch --binhost-only exits 1 and a full fetch prints the same line and keeps its own exit status. The line says why:

Situation Message
The tree names no release and nothing else names a binhost kdos update: no binhost is named: <root>/TREE names no release and /etc/kdos/update.conf has no `binhost =` line; `sudo kdos update fetch` takes a published tree that names its release
The last fetch refused the published tree as older than this machine’s, as it does for a build newer than the release, so fetching again would not help kdos update: no binhost is named: <root>/TREE names no release, and the published tree is older than this machine's; name one with `binhost =` in /etc/kdos/update.conf; check’s binhost: line says the same
The named place publishes no binhost kdos update: no binhost is published at <base>
binhost = or $KDOS_UPDATE_BINHOST names a binhost the last fetch did not see (in the refusals and hints of other commands) <base> names a binhost the last fetch did not see; `sudo kdos update fetch --binhost-only` takes its signed index

Each index is verified against /etc/kdos/keys, each file it names is kept only with the size and hash it gives, and the binhost index and manifest are verified by their own signatures too. Everything lands under a new/ directory first and replaces the cached set only once all of it holds. Every download is HTTPS or a local path, with no redirect to plain HTTP: everything is verified by a signature or a signed hash anyway, but a fetch an observer can read says which release a machine is taking.

A package is behind when its installed version, or at an equal version its release, is older than what its recipe pins. A recipe changed without a version = or release = bump is not an update.

The three lanes

apply writes the inactive slot by the first lane that can do it, and --image, --binhost or --source names one:

Lane Used when What it writes
Image A verified manifest of a newer release than the one running, for this architecture, is in the cache The slot image, through its delta from the running release, then the world set from the same release’s binhost
Binhost No newer image, and the signed binhost index covers every package that is behind and was installed prebuilt Each package from the binhost (or rebuilt from a delta), installed into the slot by the slot’s own kpkg binhost; a package built here is built in the slot again
Source Only when asked for with --source Each package built from source, as below

An image is newer when its release time is later than the running root’s (TREE_TIME in /etc/kdos-release, else the time of the image the root was written from); with no time known on either side the versions decide, so a signed manifest of an older release is never offered.

The VERSION a filled slot’s /etc/kdos-release records has one form, the image build’s and kdos update’s alike: a release gives its number without its tag’s v (0.2), anything else os-release’s VERSION_ID, + and the commit as the tree’s TREE file records it, twelve characters (0.2+4dc1f7f826a3: the image build’s short hash, with -dirty from an image built from a tree git had not recorded). The tree’s version line keeps its tag (v0.2), the name the binhost index is found by.

An update keeps the route each package arrived by. /var/lib/kdos/origin holds one <package> prebuilt|source line for every package an install or an update added, and a package with no line is prebuilt, which is how everything the image brought arrived. In the binhost lane a package whose origin is source is fetched with kpkg fetch and built in the slot’s chroot with kpkg install; every other package comes from the binhost. kpkg’s three equality tests decide each prebuilt one, under the build environment recorded in /etc/kdos/chroot.env, and one that fails refuses the whole binhost lane before the slot is touched, with N packages need a source build: a package somebody chose to take prebuilt is not silently compiled. Every source and every package file is fetched and checked before the first package is installed. check runs the same tests against the cached index, so what it offers is exactly what apply will take, and the update document counts the packages the update will build here as builds.

A prebuilt apply carries what the world packages run with, not what they were built with. The binhost lane and the image lane’s world step take every package that is behind, every world package the slot lacks, and the dependencies of those, cut the way a prebuilt kdos update install cuts one port’s, from all of them at once: an edge into a port ports/buildonly lists is followed only where the package’s N: line in the index names that port, or where the package’s origin is source and it is compiled in the slot, whose own edges are all followed. kmines and micro from the binhost bring openal-soft and libkdegames and no CMake, Ninja, Go, pip or Python build backend. A stanza with no N: line keeps every edge, and the source lane keeps them all, because it compiles.

A slot image is the base alone, so the image lane carries the world set over itself. After it writes the slot, apply installs every package of /var/lib/kdos/world the image lacks, with every dependency it needs, from the same release’s binhost, building the ones whose origin is source. A port built here gets what it compiles against first: the build tools, the build-only header ports its dependencies’ headers include (ports/buildheaders), the development files of what it builds with, and, under build-deps = prebuilt (the default), every package of its own dependency closure the slot lacks and the binhost covers, prebuilt. The base leaves ports/buildonly out, so without that last part kpkg install would build such a package from source in the slot (doxygen, which libxml2 names, under llvm, under rust, under bat). Whether it can is decided before the slot is written: the world set and every dependency of it the world step installs, walked through the tree’s recipes over the same cut edges, must be built here or covered by the signed index, or the image lane is refused with N package(s) of what was installed on purpose is/are not in release X's binhost, naming the first few, and nothing is written. A machine with no world set takes no world step.

What the running root keeps whole stays whole. A slot image’s packages carry the records of the stripped base, and the world step installs under the slot’s FACETS=run, so each package the running root keeps whole is put back whole in the slot: one the world step installs goes in under KPKG_FACETS=all, and one the image brought stripped is installed again whole after the world step, from the binhost or built here again by its origin, its file fetched with the rest before anything is installed. Whether the release can is decided with the world set’s coverage, before the slot is written: one by the prebuilt route the index does not cover refuses the image lane with N package(s) this system keeps whole is/are not in release X's binhost. A binhost apply into a slot does the same for the slot’s own stripped copies.

The source lane fetches every source of every package that is behind with kpkg fetch, stopping before any build when one cannot be had, and builds each package with chroot <slot> kpkg install -f, in dependency order: the build runs on the slot’s own compiler, headers and libraries, so a package whose dependency was upgraded earlier in the run links the copy just installed. Into the chroot it binds /proc, /sys, /dev, the ports tree, the running root’s source cache that the fetch filled (named to the slot’s kpkg as SOURCE_DIR) and /etc/resolv.conf when the slot has a regular file there, each made a slave of the running root’s mounts before anything runs in the chroot, and it unmounts them all before checking the slot; the unmount leaves the running root’s /dev/pts, /dev/shm, /sys/fs/cgroup and efivarfs in place. A bind that cannot be made a slave stops the apply with cannot make <dir> private after a second try. That bind stays mounted, and so does the slot unless nothing holds it: the apply says slot stays mounted at <dir> and unmounts neither lazily, since a lazy unmount of a shared copy would take those mounts with it. It needs the network for the sources, and compiles on the machine, for hours on a large set. --root DIR does none of the slot handling: it points KPKG_ROOT at DIR, which moves only the installs and the package database, and builds on the running root. --in-place updates the running root instead of a slot, which gives up the rollback.

Acquire, then arm

An update is two steps, because Discover shows progress for the first and not the second, and apply with neither flag does both:

  1. Acquire (apply --acquire) does all the long work: the download, the write or install into the slot, and kpkg check --all on the slot, which leaves it unarmed on a missing file or a changed one outside /etc. It refuses on a boot that is itself running a slot on trial. Before the first byte of the slot is rewritten, in every lane, it cancels any trial of the slot and runs kdos-bootctl unfill <x>, which marks the slot incomplete until the arm’s deploy clears it: a slot an update stopped writing is neither tried nor offered on the boot menu (see kdos-bootctl). A mark that cannot be written stops the update as a failed build, with slot <x> could not be marked as being written (the source-build lane says the slot could not be marked as being written). With --progress FD it writes one line per event for a program to read; --mount mounts an inactive slot nobody mounted at /run/kdos/slot-<x> for the run, and unmounts it at the end of the run whichever way it ends, a stop by SIGTERM, SIGINT or SIGHUP included (a group signal such as Ctrl-C also kills the install in flight, and the run ends as a failed install), and --dry-run --mount on an unmounted slot says what it would mount and exits 0.
  2. Arm (apply --arm) takes only a slot an acquire of this tree or image filled. It carries this machine’s configuration into the slot, copies /ports into it unless an image brought its own tree, records its version, puts the slot’s kernel on the ESP, and asks kdos-bootctl to try it on the next boot. The slot is confirmed only after a desktop session on it has answered; see Counting and confirming.

A slot is a whole root, and a machine’s configuration is not in the image. Only /home is shared between the slots, with the pack store bound from /home/.kdos/packs; the accounts, the network, the host keys and every other edit under /etc live in the root the machine runs. The arm carries them into the slot, by one rule per file:

File Rule
A file a package installed and nobody edited (its hash is the one the running root’s package database recorded) The slot keeps its own copy, the newer default
A file somebody edited, or one no package owns (the hostname, fstab, the machine id, the host keys, network profiles) The running root’s copy wins, and a different copy the slot held is kept beside it as <file>.kdos-new; inside a directory whose name ends in .d it is kept as the dotfile .<file>.kdos-new, because a program that reads such a directory whole (SDDM’s sddm.conf.d, cron.d) skips a hidden file and would otherwise read the slot’s copy too, after the machine’s
passwd, group, shadow, gshadow, subuid, subgid Merged by name: every running entry, then every entry only the slot has, so an account made since and a system account the new release adds both survive
fstab The running root’s, with the slot’s own root line, from the boot state. Every absolute mount point it names that the slot lacks is created (mode 0755, owned by root), at every arm and without following a symbolic link, because a slot written from an image holds only what the image names, and an image need not name every mount point the machine’s fstab adds
kdos-release, mtab, ld.so.cache, udev/hwdb.bin The slot’s own, never carried

Machine state under /var follows as whole trees: the world set, the origin file, the pending boxed applications, the D-Bus machine id, and the state of Bluetooth, AccountsService, SDDM, ALSA, NetworkManager and cron, with root’s home; so do the paths named by carry = lines in /etc/kdos/update.conf. The configuration is carried at the arm and not the acquire, so what a person changes between the download and the restart, a password or a network, is in the slot that boots. The pack manifest is not carried: it lives in the shared pack store, and the pack daemon grafts whatever it names into the slot it starts in (see Packs and boxes).

What a surface reads

What went wrong is recorded in /var/lib/kdos/update.state (no tree, no network, a fetch that failed, a release index, binhost index or image manifest that does not verify or that no key on the machine could verify, a build, an install or an image write that failed), and kdos update check reports it. check --json is the update document: what is behind, the version on offer and its lane (image, binhost or none), the size to download, how many packages the update builds here (each counts as covered, so the update is still offered), the date of the release, the key that signed it, the origins the image and the binhost are read from (image and binhost, which decide whether Discover says the size is “to copy” or “to download”), and the last problem. The update-check timer writes it nightly to /var/lib/kdos/update.json from the tree, index and manifest already in place, without fetching; the network is reached only when somebody asks, through Discover’s Refresh on its Updates page (check --fetch, run by kdos-sysupdated; on a machine with no second root slot, the live medium among them, fetch --binhost-only alone) or kdos update fetch. Discover’s update notifier and kdos-sysupdated read the document. With no binhost index, check names the next step: kdos update apply --source when something is behind, sudo kdos update fetch --binhost-only when update.conf, $KDOS_UPDATE_BINHOST or a tree that names its release gives a binhost, and otherwise that the tree names no release and sudo kdos update fetch takes one that does; its tree line shows (<version>) only for a tree that names a release. The update path has not been run against a published release; see Known gaps. Every option is in the kdos command.

Installing more software

What the base image does not carry, a machine installs from the binhost of its own release, or builds itself:

kdos update install [--dry-run] [--prebuilt | --source] [--build-deps=prebuilt|source] [--root DIR] <port|group>
kdos update install [--dry-run] [--prebuilt | --source] --pending
kdos update install [--dry-run] --dev [--deps] [--root DIR] <port|group>...
Route What it does
--prebuilt The port and every package it lacks from the release binhost kdos update fetch keeps in /var/lib/kdos/binhost, each through kpkg binhost under KPKG_REQUIRE_SIG. A package the signed index does not cover refuses the whole install before anything is fetched, naming kdos update install --source <port>. With no signed index on the machine it refuses with kdos update: no signed binhost index is on this machine, followed by the step that gets one: the no-binhost-named line of Updating a machine when the last fetch found none, otherwise `sudo kdos update fetch --binhost-only` fetches the release's signed index
--source The port built here: kpkg fetch of every source first, then kpkg install under /etc/kdos/chroot.env, so the package’s B: is the binhost’s. Each package it lacks is downloaded (--build-deps=prebuilt, and one the index does not cover is built instead) or built too (--build-deps=source)

With neither flag, install = in /etc/kdos/update.conf names the route and build-deps = the dependencies’ (both prebuilt by default, and any other word is a usage error); a prebuilt install takes its dependencies prebuilt whatever build-deps = says. A recipe’s build.sh runs as root on the machine in a source install; see The security model.

The rules every install keeps:

Discover offers the same two routes for a port that is not installed, as two origins of one application; see Discover.

Building here

A machine installed from the image has FACETS=run, so its packages lack the files a compile reads, and its base carries no build tools (build-tools is a group): gcc is there for its run-time libraries, with its compiler in its dev facet. Before the first build of a run, a source install does three things, and prints each as it does it:

The room the builds need is checked before the first of them, by kdos update install and by both lanes of kdos update apply that build. A run’s builds go one after another, and each that succeeds removes its tree, so the work directory holds one tree at a time. The run is reckoned at six times the source archives of its largest build, plus each other distinct archive once for the package and installed files every earlier build leaves, plus 512 MiB once for a build’s scratch. Ports that build from one archive (openmp, clang and lld from llvm-project) count it once. An archive not on the machine yet counts at the size kpkg fetch --size reads for it, one call for the run, and one no server gave a size for counts nothing and is named on a dry run’s stderr. A run that the filesystem of /var/cache/kpkg/work cannot hold is refused, once before anything is fetched and again once every source is. The figures are an estimate, not a bound: a build can outgrow them, and a run they refuse might have fitted. So every build kdos update starts runs under KPKG_CLEAN_FAILED=1, which has kpkg remove a failed build’s work directory and record in /var/cache/kpkg/work/.kpkg-failed the free space it measured before the removal; from that record kdos update tells a root that filled up from any other failure. A build that is stopped or killed removes nothing: its directory stays until it is deleted or the port is built again. Without the variable, as in the tree’s own build, a failed build keeps its directory for the developer to read.

Everything a run that builds installs, it installs whole (KPKG_FACETS=all), so a port built later in the run finds what an earlier step placed, and each such package stays whole across updates. The same plan runs before the source items of an A/B update, in the binhost lane and the source lane, inside the slot. --dry-run lists it first: <pkg> prebuilt <file> <bytes> for a build tool, <pkg> dev <file> <bytes> for a restore, <pkg> dev-source <version>-<release> for a package built again, each counted in the total line.

The build dependencies a source-built package’s own recipe names stay with it and go with its removal. The removal graph keeps every recipe edge of a package whose origin is source, its ports/buildonly edges among them, since the next update builds it here again against the same dependencies; the index’s N: line measures the binhost’s build, not this one. After kdos update install --source kcolorchooser, removable lists kcolorchooser, then cmake and ninja, which its recipe names, under kept, needed by an installed package: as (needed by kcolorchooser), and nothing left by removals; and kdos update remove kcolorchooser takes the prebuilt extra-cmake-modules its build brought, when nothing else installed needs it. A build-only port brought for a dependency the same plan installs prebuilt is held by neither: that dependency’s N: line cuts its edge, so it is listed under left by removals: and remove takes it by name.

kdos update install --dev <port|group>... is the restore asked for by name: each named port, or every installed member of a group, is installed again whole, prebuilt from the binhost (built again here when its origin is source), and stays whole across updates. A port not installed is named and skipped (and fails the command when it was named directly), one installed whole prints every file of <port> is installed, and one older than its recipe refuses. --dry-run prints the dev lines and a total line. --dev --deps adds, for each named port, the set the second step above restores before building it (kpfacetwanted: its declared closure, musl, linux and gcc), so a project built against qt6-qtbase finds the libglvnd and mesa headers Qt’s CMake files look for.

kdos update install build-tools installs the toolchain without a build: each member it adds goes in whole, and it then restores the dev facet of every installed member and of musl, linux and gcc that lacks it, as --dev does, the kernel package among them. Afterwards cc builds a C program against the C library’s and the kernel’s headers.

Groups

A group is a named set of native applications installed in one step. ports/groups lists them, a group <id> <title> line and then its member ports, and the image stages it at /ports/groups, where a machine reads it:

Group Members
kde-games, kde-education, kde-pim, kde-multimedia, kde-graphics, kde-utilities, kde-devtools The kde-gear-* meta of the same subject
kde-network ktorrent, krdc, krfb, kio-gdrive, kaccounts-providers, kdenetwork-filesharing
kde-system filelight, sweeper, kfind, ksystemlog, kwalletmanager, kcharselect, khelpcenter
kde-artwork plasma-workspace-wallpapers, oxygen
office libreoffice, calibre, texstudio
graphics gimp, krita, inkscape, darktable, blender
internet thunderbird, chromium, librewolf
multimedia vlc, mpv, obs-studio, audacity, shotcut, handbrake, kodi
games supertuxkart, wesnoth, xonotic, luanti, scummvm, retroarch
science octave, qgis, stellarium, freecad, kicad, openscad
development rust, go, nodejs, zig, gdb, valgrind, strace, lldb
windows wine
build-tools gcc, binutils, make, cmake, meson, ninja, pkgconf, autoconf, automake, libtool, bison, flex, fortify-headers (the overlay headers chroot.env’s -D_FORTIFY_SOURCE=2 needs on musl)
lang-zh, lang-ja, lang-ko fcitx5-chinese-addons, fcitx5-anthy or fcitx5-hangul, with fcitx5-gtk, noto-cjk and noto-cjk-prefer-zh, -ja or -ko

A group is no package. kdos update install <id> installs each member as the port it is, with the same flags, and each member joins the world set by its own name, so a member a later tree drops from the group stays installed and one it adds arrives with the next install of the group. It works on an installed machine and on the live ISO, where the packages go into the RAM overlay and are gone at the restart. kdos update groups [--json] lists every group, installed or not, how many of its members are missing, how many packages installing it would add, and their download size from the cached index; the size is not shown (null in the JSON) without an index or when some of those packages are not prebuilt. A group id is a port-name word that is no port’s name, and a member must be a port; imageset.py --check refuses either.

The installer offers every group (see The installer). With the network up it fetches its own release’s binhost index (kdos update fetch --binhost-only, into the new disk’s /var/lib/kdos/binhost, since the live cache is in RAM) and runs kdos update install --prebuilt --root <target> <id> for each chosen group. A group that does not install, and every group when the index cannot be had, is written to the new disk’s /var/lib/kdos/groups-pending with a warning, never a failure; kdos update install --pending installs each id there, removing it from the file once it is in, and prints nothing is pending when the file names nothing.

Vulnerability tracking

kdos cve              # every package
kdos cve openssl      # one package
kdos cve --json       # the same, as a document

kdos cve compares versions and does not scan files: a package is reported when its version is older than the version the database gives as fixing an issue. On a running system the versions are those in the installed package database; with no database, as in a checkout, they are the versions the ports tree pins, and the report says which it used. The comparison is the package manager’s own version comparison, shared with the upstream-version checker (ports/update), so the two cannot disagree about what “newer” means.

The data is a vendored, pruned copy of Alpine’s security database, installed as /usr/share/kdos/secdb.txt from src/system/kdos-tools/secdb/secdb.txt; KDOS_SECDB names another file. It is a committed, diffable text file generated by vendor.py beside it and merged from twelve Alpine branches (main and community for v3.19 to v3.24), so the answer needs no network. Alpine is a close proxy for KDOS because it is also a musl distribution building the same upstream tarballs. See Decisions for why Alpine rather than a larger source.

Five details each change the answer:

A package the database does not carry is reported as UNKNOWN, never as clean. A large part of the tree is in that state and the summary says so. A fix Alpine never shipped is invisible to the check. The database’s age is printed with every run, with a warning once it is more than 180 days old.

Bundled copies

A library compiled into a program from a vendored crate has a version of its own that no package records. Two libraries are compiled in this way in the tree. The first is AWS-LC, the TLS library under rustls’ default crypto provider, which aws-lc-sys builds into the binary. The second is hidapi’s hidraw backend, which the hidapi crate compiles into a helper of kdeplasma-addons rather than linking the hidapi port (see kdeplasma-addons’ note). A port whose crate offers a TLS backend on the system OpenSSL takes it instead: xh builds with native-tls, and its build.sh stops unless the binary NEEDs libssl.so. The rest offer no such feature, and switching would mean patching their manifests and regenerating their vendor bundles, so their copies are listed in an inventory instead: src/system/kdos-tools/secdb/bundled.txt, installed as /usr/share/kdos/bundled.txt, one row <port> <crate> <component> <version> per copy.

Port Crate Component Version
iamb aws-lc-sys 0.45.0 AWS-LC 5.7.0
termusic aws-lc-sys 0.38.0 AWS-LC 1.69.0
chess-tui aws-lc-sys 0.40.0 AWS-LC 1.72.0
mqttui aws-lc-sys 0.44.0 AWS-LC 5.5.0
surfer aws-lc-sys 0.39.0 AWS-LC 1.71.0
sniffnet aws-lc-sys 0.43.0 AWS-LC 5.2.0
kdeplasma-addons hidapi 2.6.7 hidapi 0.15.0

kdos cve checks each row whose port it checks under the component’s name, reports a version behind a recorded fix as <port>/<component>, and lists every row under bundled copies. The version is the one the vendored sources state (for AWS-LC, AWSLC_VERSION_NUMBER_STRING in aws-lc/include/openssl/base.h), so a bump that regenerates a port’s vendor bundle rewrites its row in the same change; a stale row reports the old copy’s version. Alpine’s database carries neither an aws-lc nor a hidapi package, so every row is listed as not in the database.

ports/update --cve is the online cross-check: it asks repology (repology.org, a service that tracks package versions across distributions) whether each pinned version is flagged vulnerable, one request per port against a rate-limited service. That cost is why the vendored table is the everyday answer.

See also


Part III — Architecture, chapter 15. Previous: 14. The session · Contents · Next: 16. Packs and boxes