173.1. kdos-pack-0.1.0
Build, sign, index and delta packs
| Version | 0.1.0, release 1 |
| Source tree | src/system/kdos-pack/ |
| Phase | 41_system (System), 960 of 1047 in build order |
| Licence | MIT AND (BSD-2-Clause OR CC0-1.0) |
| Homepage | https://github.com/kunaldawn/kdos |
| Build time | 0.2 SBU |
| Installed size | 235.0 KiB in 2 files |
| Recipe | src/system/kdos-pack/kpkgbuild |
About
kdos-pack builds, inspects, signs, indexes and diffs packs: the filesystem images, signed or unsigned, that the import lane installs applications from.
It is installed on every machine, at /usr/bin/kdos-pack, because kdos-appbox runs it on the machine itself: kdos-box freeze captures a working box’s writable layer as a pack, and exporting a set of applications packs each one and indexes the result. The kdos-tools port depends on it. Its commands are in Building a pack and the format it writes in A pack is an image with parts appended.
It links nothing beyond the C library. The file system image is made by running mkfs.erofs from erofs-utils, and deltas by running zstd --patch-from from zstd, each through an argument vector and never a shell; those two programs are why the port depends on them, not anything it links.
Sources
None: the port builds from its own directory, /kdos/src/system/kdos-pack.
Dependencies
Depends on: erofs-utils, zstd.
Required by (2): kdos-discover, kdos-tools.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install kdos-pack'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/system/kdos-pack.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/kdos-pack
SRC=$SRC_ROOT/kdos-pack-0.1.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
LIBS="$PORT_SRC/../../libs"
gcc $CFLAGS -O2 -std=gnu11 -D_GNU_SOURCE -Wall -Wextra \
-I"$LIBS/libkbase" -I"$LIBS/libksig" -I"$LIBS/libkpkg" \
-I"$LIBS/libkpack" \
-o kdos-pack "$PORT_SRC"/main.c \
"$LIBS"/libkbase/*.c "$LIBS"/libksig/*.c \
"$LIBS"/libksig/monocypher/*.c "$LIBS"/libkpkg/*.c \
"$LIBS"/libkpack/*.c $LDFLAGS
install -Dm755 kdos-pack "$PKG/usr/bin/kdos-pack"
install -Dm644 "$LIBS/libksig/monocypher/LICENCE.md" \
"$PKG/usr/share/licenses/$name/monocypher-LICENCE.md"
The switches, and why each is set:
-std=gnu11,-D_GNU_SOURCE— The C dialect, which the tree’sCFLAGSalready names, and the macro that exposes the C library’s GNU and POSIX extensions.-I"$LIBS/libkbase",-I"$LIBS/libksig",-I"$LIBS/libkpkg",-I"$LIBS/libkpack"— The headers of the four libraries it is built from.$LIBSissrc/libs."$LIBS"/libkbase/*.c,"$LIBS"/libksig/*.c,"$LIBS"/libkpkg/*.c,"$LIBS"/libkpack/*.c— Compile the libraries into the binary, which is how everylibk*library is used; see How the libraries are built. libkpack is the pack format, libksig the signatures and keyring, and libkpkg the version comparison kpkg uses as well."$LIBS"/libksig/monocypher/*.c— Monocypher, the Ed25519 implementation libksig signs with, vendored verbatim underlibksig; it is the reason for theBSD-2-Clause OR CC0-1.0in the licence line. See libksig.-O2,-Wall,-Wextra— The tree’s optimisation level, named again, and the compiler’s common and extra warnings.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kdos-pack, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf kdos-pack-0.1.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kdos-pack, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: main.c.
Contents
Installed programs: kdos-pack.
Installed directories: /usr/share/licenses/kdos-pack.
Notes
A pack built twice from the same tree must be the same bytes, or a delta between two releases means nothing and a second builder cannot be checked against the first. main.c passes mkfs.erofs a set time (SOURCE_DATE_EPOCH), set owners (uid and gid 1000), a 4096-byte block size and a UUID derived from the pack’s id, and each of those is a source of drift if it is removed; see Reproducibility.
The span the pack digest covers is set by the footer’s format number. Widening it without a new format number makes every pack already in use fail its hash check, so no box composes. Each pack is verified by the format it declares, and kdos-pack restamp raises an older pack to the current format, dropping its signatures, which then have to be made again. See Rules the format keeps.