430. kpkg
kpkg is the package manager of KDOS. The build uses it to make every package from its port, and the same program is on every installed system and on the live medium, where it lists what is installed, checks the installed files against what was installed, removes packages, and builds and installs a port from the recipe tree at /ports. This page is about that second use, on a running machine. Updating the whole system is Updating; rebuilding a port with a recipe of your own is Local rebuilds and kdos march. What kpkg install does step by step is Anatomy of a kpkg install.
Installation
kpkg is not a port, because building a port needs it. The bootstrap step 120_kpkg.sh compiles it from src/system/kdos-kpkg and three of KDOS’s own libraries, and installs it into the root as /usr/bin/kpkg with four symbolic links to it; kpkg in Part III describes the step. No later phase rebuilds it, and no package database entry owns it, so kdos why /usr/bin/kpkg reports that no package provides it.
The five names, each dispatching on the name it was run under:
| Name | Does |
|---|---|
kpkg |
The front end: every command below |
kpkgadd |
Installs a package file that is already built |
kpkgbuild |
Builds the port in the current directory into a package, and installs nothing |
kpkgdel |
Removes packages |
kpkgdepends |
Prints the resolved install order, and nothing else |
Every image carries the recipe tree at /ports: each port’s kpkgbuild, build.sh and patches, ports/shelves, ports/sources.idx, ports/groups, and KDOS’s own programs under /ports/src, with no upstream source archive in it (105_ports stages it). The trust ring for prebuilt packages, /etc/kdos/keys/, comes from the base filesystem, fs/etc/kdos/keys/.
kpkg needs no service. It downloads sources with curl, which the curl port installs.
Configuration
/etc/kpkg.conf
Where kpkg finds ports and keeps its trees. The bootstrap step copies it into the root:
cp "$SRC"/kpkg.conf $SYSROOT/etc/kpkg.conf
script/phases/10_bootstrap/120_kpkg.sh, lines 66–66
The file is src/system/kdos-kpkg/kpkg.conf:
# Port repositories: the recipe tree every image carries at /ports, and the
# areas of src/ under it that hold ports of our own
PORT_REPO="${PORT_REPO:-/ports/core /ports/src/system /ports/src/art /ports/src/desktop /ports/src/daemons}"
# Package cache directories
SOURCE_DIR="${SOURCE_DIR:-/var/cache/kpkg/sources}"
PACKAGE_DIR="${PACKAGE_DIR:-/var/cache/kpkg/packages}"
WORK_DIR="${WORK_DIR:-/var/cache/kpkg/work}"
# Package database
PKGDB_DIR="${PKGDB_DIR:-/var/lib/kpkg/db}"
# Which files of a package an install places: `all`, every file (the build
# chroot, which compiles against the headers and libraries it installs), or
# `run`, the package without its development and documentation files, each
# left out listed in $PKGDB_DIR/.facets/<name>. The image's copy says `run`
# (70_image/017_stage.sh); `kdos update install --dev <port>` installs a port
# whole again
FACETS="${KPKG_FACETS:-all}"
src/system/kdos-kpkg/kpkg.conf
Every line is NAME="${VARIABLE:-default}", the variable named after the key but for FACETS, whose variable is KPKG_FACETS. kpkg reads it as a key and a value without running a shell, and the variable wins over the file, so one command can point kpkg somewhere else without editing anything:
PORT_REPO="/home/kdos/ports /ports/core" kpkg info foo
Each directory PORT_REPO names is searched for a port at <name>/ and one shelf down at <shelf>/<name>/, and the first directory holding the name wins. The keys and their limits are in /etc/kpkg.conf.
The file above says FACETS="${KPKG_FACETS:-all}", which is what the build uses. The image’s copy says run (The image stage): an install on the medium, or on a machine installed from it, leaves out each package’s headers, static libraries, CMake and pkg-config files, man sections 0, 2 and 3 and its manuals under /usr/share/doc, info and gtk-doc. See Development files.
The package database
/var/lib/kpkg/db/ is written only by kpkg itself, as it installs and removes packages. Do not edit it by hand. For each installed package it holds <name> (the version and release, then every path the package owns), and .recipe/<name>, .pkgsha/<name>, .files/<name> and .needs/<name> (what its files need at run time) beside it, and .facets/<name> for a package installed without its development and documentation files; The database entry shows the five files of one package, and /var/lib/kpkg/ says what each file and the lock beside them hold.
/etc/kdos/keys/
The keys kpkg accepts a signature from, for a binary host’s index and for a package’s own .sig. The image ships the directory with no key in it, only its description:
Trusted package-signing keys.
Every `*.pub` in this directory is a key this machine will accept a signature
from — for the binhost index (PACKAGES.sig) and for a package's own `.sig`
sidecar. Adding a key is copying a file in; removing trust is deleting one.
There is no revocation list and no online check: the directory IS the policy.
kpkg keygen builder # on the machine that builds
cp builder.pub /etc/kdos/keys/ # on every machine that should trust it
A key id (16 hex characters, printed by kpkg) identifies a key. It is NOT a
credential: a signature file names the id so a person can be told which key
signed, and verification always uses the key from THIS directory.
THE IMAGE SHIPS ITS OWN BUILD'S TWO KEYS HERE: kdos-binhost.pub, which signs
its release's binhost, and kdos-release.pub, which signs the release index
and the slot image. Both come from the same build that made this image, so
trusting them is trusting whoever built the image, which booting the image
already is. They verify the release index, the binhost index (PACKAGES.sig),
each prebuilt package's .sig and the slot image's manifest, and nothing from
another builder. Delete them and this machine takes no prebuilt package and
no slot image; it still builds every port from source, whose integrity comes
from the `sha256 =` lines of its recipe. Add another builder's .pub to trust
that binhost too.
`packs/` IS SHIPPED WITH A KEY, and it is a different question. kdos-packd
checks an application pack's own signature, or a signed pack index (PACKAGES)
beside the packs being imported, against it. Nothing the build makes is signed
with that key and the build does not hold its secret half, so on a fresh system
it verifies nothing; add the `.pub` from `kdos-pack keygen` to trust packs you
sign yourself. It is a subdirectory because a keyring is a flat read of
`*.pub`: a key that vouches for a pack must not thereby vouch for a package
repository.
`tree/` holds the key that signs a published ports tree, which
`kdos update fetch` installs as /ports. The build puts its release key's public
half there; tree/README says how. It is a subdirectory for the same reason.
The two subdirectories, packs/ and tree/, are separate rings that kpkg does not read; they belong to Packs and Updating.
Environment variables
The settings that change what kpkg does, rather than where its trees are, are read from the environment only. Two matter on a running machine: KPKG_FETCH=1, which lets a build download the sources it lacks, and KPKG_REQUIRE_SIG=1, which refuses any package file without a good signature. KPKG_CONF names another configuration file and KPKG_KEYRING another trusted-key directory. kpkg binhost also reads the compiler variables CC, CFLAGS, CXXFLAGS, LDFLAGS and KDOS_TARGET; see Using a binary host. Every variable is in the table under kpkg; the image sets none of them.
Usage
Every command that changes the root runs as root. The ones that only read it do not, except where a file they read is root’s own.
Seeing what is installed
List every installed package with its version and release:
kpkg list kpkg list --jsonShow one package. For an installed package this is its version, release, licence and file count; for one that is not installed, the recipe’s description, licence and
depends =list, andStatus: not installed:kpkg info zlibPackage: zlib Version: 1.3.2-1 License: Zlib Files: 19Find the package that owns a file.
kdos whyreads the database’s own file lists and prints the package, its version and its recipe, then any reason the system records for that path:kdos why /usr/bin/xzA path no package owns is reported as
none — provided by fs/ or 10_bootstrap, or not installed: the base filesystem is copied into the image rather than installed by a package, andkpkgandkinstallare compiled by10_bootstrapand are not packages either. The manifest itself can be searched too:grep -lx './usr/bin/xz' /var/lib/kpkg/db/*Print a recipe’s metadata as shell assignments, expanded:
kpkg meta xz
Checking the installed files
kpkg check compares the root with what was installed: every path a package’s manifest lists, and the SHA-256 and mode of every regular file it placed.
Check one package, or all of them:
sudo kpkg check openssh sudo kpkg check --allRead the findings.
missing,changedandmodelines are faults and make the exit status 1; aconfigline is a file under/etcthat someone edited, and anunownedline (with--all) is a file under/usror/optthat no package claims. Neither of the last two changes the exit status. A package that is not installed, or a usage error, exits 2. Every line but anunownedone names the package first, and the last line counts them:libvirt: config ./etc/libvirt/qemu/networks/default.xml unowned ./usr/bin/kpkg 2107 packages checked: 0 missing, 0 changed, 0 mode, 25 config, 73 unownedThat is the freshly booted image, and it exits 0. The image leaves out the build’s logs and caches but carries every directory a package claims under
/var/logand/var/cache, empty (110_iso), so none of them ismissing. Itsconfiglines are libvirt’s network and filter files under/etc/libvirt, whichlibvirtdrewrites at its first start, so they differ from their recorded hashes; theunownedones includekpkgandkinstallthemselves. The meaning of each line is in Checking an installed root.Check another root, such as a mounted second slot, with
--root:sudo kpkg check --all --root /mnt/slot-bPrint only the faults and the summary with
--brief, and keep every line in a file with--log <file>.--briefleaves theconfigandunownedlines off the terminal and still counts them in the summary; neither option changes the exit status.kdos update applychecks a slot this way, with its list in/var/log/kdos-update-check.log:sudo kpkg check --all --brief --log /tmp/check.log --root /mnt/slot-b
Development files
The image installs each package without the files only a build or a reader of manuals uses, and lists what it left out of each one.
See what a package was installed without:
kpkg facets --list zlibdev ./usr/include/zconf.h dev ./usr/include/zlib.h dev ./usr/lib/libz.a dev ./usr/lib/libz.so dev ./usr/lib/pkgconfig/zlib.pc dev ./usr/share/man/man3/zlib.3A package installed with every file prints
zlib: every facet installed.Bring them back.
kdos update install --devinstalls the package again, whole, from the release’s binary host, and it stays whole across updates; a group name restores each member:sudo kdos update install --dev zlibStrip them again, from one package or, with no name, from every package:
sudo kpkg facets --strip zlib==> zlib: 6 files left out, 261K ==> facets: 1 package stripped, 267579 bytes (261K) freed
The rules, and the files each keeps a running program from losing, are in Facets.
What a package needs at run time
Each install records what the package’s files need at run time: the libraries its programs link, the interpreters its scripts name, the QML modules and Python packages they import, and what its recipe’s runtime = line names.
Print the record, and which installed package provides each line:
kpkg needs --resolve kirigamiqml QtQuick qt6-qtdeclarative qml org.kde.kitemmodels kitemmodels so libQt6Core.so.6 qt6-qtbase so libc.so muslA line ending
(nothing)is an edge nothing installed provides, and the command then exits 1;(unowned)is a file no package claims.A package installed before records were kept prints
no run-time needs recorded; measure it from its installed files, writing nothing:kpkg needs --scan zlib
What each kind of line is found in, and how the image uses the records to prove its base, is in Run-time needs.
Building and installing a port
On a running machine a port is built from /ports with its sources fetched over the network, because /ports holds no source archive. This needs the network, and it compiles on the machine against the headers and libraries of what it depends on, which the image left out (Development files): restore them first, as step 2 does.
The image carries only the base, and pv is not in it, so these steps work as written. An image built with KDOS_IMAGE=full carries every port, pv among them: remove it first with sudo kpkg remove pv. For a port that is installed, step 1 prints an empty line and step 4 prints Nothing to do. These steps are kpkg alone; kdos update install --source <port> does the same build and also records the port in the world set and its route in /var/lib/kdos/origin, so updates keep it and build it here again (see Installing software).
Look at what would be built.
kpkgdependsprints the install order, leaving out every package that is already installed, so withncursespresent it printspvalone:kpkgdepends pvInstall the build tools the base does not carry,
binutilsandmakeamong them, and restore the development files of whatpvcompiles against:ncurses, which its recipe names, andmusl,linuxandgcc, which every compile reads.kpkg installrefuses until they are back, and names them.--dev --deps pvrestores that closure thoughpvitself is not installed:sudo kdos update install build-tools sudo kdos update install --dev --deps pvkdos update install --source pvdoes this step itself.Fetch the sources of the port.
kpkg fetchtakes each file the recipe hashes and the machine lacks from the KDOS source archive first and from the recipe’s own URL second, and keeps a copy in/var/cache/kpkg/sourcesonly when it matches the recipe’ssha256 =:sudo kpkg fetch pv==> Fetching pv-1.12.0.tar.gz from the archive (sources-1)It exits 0 when every source is present, 1 when one could not be had, and 3 when nothing could be reached at all. See Fetching sources on a machine.
Build and install it. With
KPKG_FETCH=1the port, and each dependency built on the way, fetches whatever sources are still missing askpkgreaches it:sudo env KPKG_FETCH=1 kpkg install pvThe build’s output scrolls past, then
==> Package created: /var/cache/kpkg/packages/pv-1.12.0-2.tar.xz,==> Installing pv-1.12.0-2, and==> Package 'pv' installed successfully. On an eight-thread virtual machine this takes about 12 seconds.--keep-cachekeeps the package file for a laterkpkgadd.Confirm the result:
kpkg info pv kpkg check pv1 package checked: 0 missing, 0 changed, 0 mode, 0 config
On a running system an installed package counts as current whatever its recipe says, so kpkg install of an installed port prints Nothing to do and builds nothing. -f rebuilds the named ports; a dependency is built only when it is not installed, and the walk stops at an installed package, so nothing beneath one is built:
sudo env KPKG_FETCH=1 kpkg install -f pv
Removing a package
sudo kpkg remove pv
kpkg remove is kpkgdel. It removes the files in the package’s manifest that no other package claims, and every directory of it that is left empty. It also drops the package’s lines from the world set and the origin record, /var/lib/kdos/world and /var/lib/kdos/origin, so the next kdos update does not install it again. The removal reaches only the running root: if an update is already waiting in the other A/B slot, the package is still installed there, so run kpkg remove again after booting into it. It does not check reverse dependencies: kpkg remove bash removes bash. Before removing a library, list the recipes whose depends = names it:
awk '$1 == "depends" { for (i = 3; i <= NF; i++) if ($i == "zstd") print FILENAME }' \
/ports/core/*/*/kpkgbuild /ports/src/*/*/kpkgbuild
Installing a prebuilt package
A package file built elsewhere, by kpkgbuild or kept in /var/cache/kpkg/packages by kpkg install --keep-cache, is installed with kpkgadd. Its name is <name>-<version>-<release>.tar.xz:
sudo kpkgadd /media/stick/pv-<version>-<release>.tar.xz
When a .sig file lies beside the package and /etc/kdos/keys/ holds a key, kpkgadd verifies it and refuses a package whose signature does not verify. A package with no .sig, or a .sig with no key in the ring to check it, is installed, unless KPKG_REQUIRE_SIG=1 is set, when it is refused with <file>: signature check FAILED — not installing.
Using a binary host
A binary host is a directory of prebuilt packages with a signed index, PACKAGES. A release’s binhost is the package repository of that release, and kdos update install installs from it with every dependency, recording what it installed (see Installing software); this section uses a binary host by hand, with kpkg alone. A build machine writes one to build/binhost/ with make build KDOS_MAKE_BINHOST=1, which 010_binhost indexes and signs, putting the public key beside the index as kdos-binhost.pub. A medium built with KDOS_ISO_SOURCES=1 as well carries that directory at /mnt/iso/sources/binhost.
Have a public key for the index. For a binary host the build wrote, it is
kdos-binhost.pubin the same directory. For a directory of packages of your own, make a key once and sign the index with it;kpkg keygenwritesbuilder.key, mode0600, andbuilder.pubinto the current directory and prints the key’s id:kpkg keygen builder kpkg index /mnt/binhost --sign builder.keyOn each client, trust the key by copying its public half into the ring (
builder.pubfor a key of your own):sudo cp /mnt/binhost/kdos-binhost.pub /etc/kdos/keys/Check the index:
kpkg verify-index /mnt/binhostInstall a package from it, with the compiler variables the index was written under. The build-configuration hash
kpkg binhostcompares is taken fromCC,CFLAGS,CXXFLAGS,LDFLAGSandKDOS_TARGETin its own environment, with the version$CC -dumpversionprints. A binary host the build wrote was indexed underscript/env/chroot.envof the tree that built it, which setsCC=gccand the three flag variables and leavesKDOS_TARGETunset. Export those values, copied from that file, and pass them throughsudo:sudo env CC="$CC" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" \ kpkg binhost /mnt/binhost zlibTyped at a shell with none of them set, every package is answered with
==> <name>: different build config (<hash>... vs <hash>...) — build from source.
kpkg binhost uses a package only when its architecture, its build-configuration hash and its recipe hash all equal this machine’s. It installs the one package named and nothing it depends on, and records the recipe hash it matched, as kpkg install records the hash of what it built. The full form is kpkg binhost [--root <path>] <dir> <port> [--dry-run] [--insecure]; --root installs into another root, as it does for kpkg install. An option it does not know, or a second port, is refused with exit 1. It exits 0 when it used the package, 1 when nothing matched (build from source instead), and 2 when it refused: no index (ERROR: no index at <dir>/PACKAGES), no trusted key, a failed verification, or a package whose checksum does not match the index. --dry-run says what it would do. As shipped the ring is empty, so until step 2 kpkg verify-index answers ERROR: no trusted keys in /etc/kdos/keys and exits 2. See The binary host and B: — the build-config hash.
On the live medium
kpkg works the same on the live medium, but the root it installs into is an overlay held in RAM, so everything it installs or removes is gone at power-off unless the medium has a persistence store (kdos persist; see kdos persist). A large build on the live medium also compiles into RAM: /var/cache/kpkg/work is on the same overlay.
Tips
kpkg helpprints the full command list.kpkghas no update command; the system is updated, and software the base leaves out installed, withkdos update(Updating).kpkg install --root DIR <port>installs into another root, such as a mounted target or a second slot, andkpkg list --root DIRlists one. The usage iskpkg [--root <path>] <command> [options]:--rootmay come before the command word or among its options, and a-word before the command thatkpkg helpdoes not list under Options printskpkg: unknown option '<word>' — try: kpkg helpand exits 1. Onlyinstall,remove,list,info,check,facets,needsandbinhostread a root; a leading--rootbefore any other command printskpkg: option '--root' is not for '<command>'and exits 1, and an install-only option before a command other thaninstallis refused the same way.kpkg checkreads the record taken after the package’s install hook ran, so a mode a hook sets is not a finding.- A failed
kpkgbuild leaves its work directory,/var/cache/kpkg/work/<name>, for you to look at. The next build of the same port empties it; delete it yourself to reclaim the space. A buildkdos updatestarts, forinstall --source,install --devor anapplythat builds, removes it instead (KPKG_CLEAN_FAILED; see Installing host software). A build stopped or killed keeps it either way. - Python software that is not a port goes in a virtual environment,
python3 -m venv DIR. The system’ssite-packagesbelongs tokpkg, andpip installoutside an environment is refused witherror: externally-managed-environment, whose text suggestspython3 -m venv ~/.venvs/NAME. kpkg checkrun as an ordinary user cannot read a file only root may read, and reports it aschanged:openssh: changed ./usr/lib/openssh/ssh-keysignis that, not a fault. Run it withsudobefore believing achangedline./var/cache/kpkgdoes not exist on a fresh image; the firstkpkg fetchor build makes it.
Troubleshooting
sha256 MISMATCH for <file>-
The copy of a source does not hash to the recipe’s
sha256 =. Delete it from/var/cache/kpkg/sourcesand fetch it again withsudo kpkg fetch <port>. A second mismatch means the archive and upstream both serve a different file from the one the recipe names. ERROR: Source not found: <file> (checked /ports/core/<shelf>/<name> and /var/cache/kpkg/sources)-
The build reached a port whose source is not on the machine, and
KPKG_FETCH=1was not set, so it did not download it. Runsudo kpkg fetch <name>, or repeat the install withsudo env KPKG_FETCH=1. A dependency that has to be built on the way, for example under--rootinto an empty root, stops the same way. No sha256 for <file> in the recipe-
The recipe names a source it gives no hash for, and
kpkgrefuses to unpack it. The recipe is wrong; see Checksums. kpkg fetchexits 3-
Nothing could be reached. Check the network with
nmcli general statusand try again. kpkg fetchexits 1-
Neither the archive nor the recipe’s upstream URL gave a copy with the recipe’s hash. The file has to come from somewhere else, such as a medium built with
KDOS_ISO_SOURCES=1, which holds every source beside its recipe under/mnt/iso/sources/ports/core/<shelf>/<name>/; copy it into/var/cache/kpkg/sources. ERROR: File conflict detected-
The package holds a path another installed package owns.
kpkgtakes such a path only when the recipe names the owner inreplaces =; see Who owns a file. Find the owner withkdos why <path>. Nothing to do-
Every port named is installed, and on a running system that is enough. Add
-fto rebuild it. ERROR: <port> builds against <pkg>, installed without its development files-
The image left out the headers and libraries the build needs. Run the
sudo kdos update install --dev <pkg>...the message names, then the install again. See Development files. ERROR: Build failed-
Read the build’s output above the line; the unpacked source is still in
/var/cache/kpkg/work/<name>/. A build on a running machine does not get the compiler flags the tree’s build sets; see Local rebuilds and kdos march. kpkg checkreportschangedfiles under/usr-
Something wrote over a package’s file. Rebuild that package with
sudo env KPKG_FETCH=1 kpkg install -f <name>, and find what wrote it before trusting the root. - A
kpkg installorkpkg removewaits and never finishes -
Another
kpkgaddorkpkgdelholds the database’s lock,/var/lib/kpkg/db/.lock. Find it withpgrep -a kpkg. An install hook that runskpkgitself waits on its own installer for ever.
Known gaps
- No published release’s update has been applied to an installed machine
kpkghas noupdatecommand:kpkg updateprintskpkg: unknown command 'update' — try: kpkg helpand exits 1. Updating iskdos update; see Packaging in the command index.
See also
- Packaging: ports, packages, the solver, the recipe hash and the binary host
- Anatomy of a kpkg install: one
kpkg installfollowed from start to finish - kpkg: how the bootstrap compiles it
- /etc/kpkg.conf: every key
- Updating, Local rebuilds and kdos march: the two wiki pages built on it