refactor: style pass, tools tree and fixes from a test build
os / os (push) Canceled after 0s

- Follow AGENTS.md style: headers start with the file's name, short
  notes are full sentences, comments within 80 columns.
- Build with mkosi's tools tree, pinned to the image's release
  (ToolsTreeRelease=%r): rawhide's repositories made the image rawhide.
- Incremental builds with mkosi.cache/ for faster local rebuilds.
- Hostname= instead of systemd.hostname= on the kernel command line.
- mkosi.finalize: bash, no cd, and L+ for /etc/systemd. PID 1 applies
  the presets at first boot and made /etc/systemd/system, which blocked
  the link, so /etc/systemd/user (the user's D-Bus) was missing.
- Disable homed, userdbd and nsresourced with presets instead of
  deleting their units. Drop modules the kernel has built in.
- mkosi.version adds the git commit to the version.
- One dev container per worktree or session in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-21 20:37:26 +01:00
1 parent c80e843cb5
commit 5255656258
26 files changed
+205 -243

No files matched your search

+57 -94
View File
@@ -1,66 +1,54 @@
# Agent image
# mkosi.conf builds a Fedora VM image that runs Claude Code in the background.
# /usr is read-only and replaced whole by updates. The root filesystem holds
# the state.
#
# A Fedora VM image that runs Claude Code in the background. mkosi.extra/ is
# copied to /, mkosi.repart/ defines the disk and mkosi.sandbox/ adds the
# Claude Code package repository. /usr is read-only and replaced whole by
# updates. The root filesystem holds the state: /var, and an /etc that is
# mostly links into /usr (mkosi.finalize). Claude can't change the OS, so it
# runs its tools in containers.
# mkosi.extra/etc/claude-code/ sets Claude Code up for that:
# managed-settings.json lets it run without permission prompts, and CLAUDE.md
# tells it about this machine.
# The other parts of the build:
# - mkosi.extra/ is copied to /.
# - mkosi.repart/ defines the disk image: the ESP and the /usr partitions.
# - mkosi.extra/usr/lib/repart.d/ makes the root partition at first boot.
# - mkosi.finalize keeps /etc in /usr, and links it into /etc at boot.
# - mkosi.sandbox/ adds the Claude Code package repository.
# - mkosi.version gives each build its version.
[Distribution]
Distribution=fedora
Release=45
[Build]
# ToolsTree builds with mkosi's own Fedora tools, the same on every host,
# so the host needs only mkosi and git (for mkosi.version). The tools land in
# mkosi.tools/.
ToolsTree=yes
ToolsTreeRelease=%r
Incremental=yes
CacheDirectory=mkosi.cache
[Output]
Format=disk
ImageId=agent
OutputDirectory=mkosi.output
SplitArtifacts=uki,partitions
# ManifestFormat lists the packages and versions in the image, to tell which
# builds a CVE affects. .gitea/workflows/os.yml publishes it with the image.
ManifestFormat=json
[Content]
Bootable=yes
Bootloader=systemd-boot
# Packages is systemd with its network services, plus:
# - kernel-core has no drivers or firmware beyond what VMs need.
# - systemd-container has systemd-pull, which systemd-sysupdate downloads with.
# - gnupg2 checks the signature of updates.
# - systemd-boot-unsigned is the boot loader, which mkosi signs.
# - util-linux and shadow-utils give the console login, the setup and
# newuidmap for rootless podman.
# - systemd-pam gives login sessions: Claude's user manager and its D-Bus,
# which rootless podman needs.
# - openssh-server lets you log in with ssh keys.
# - zram-generator-defaults sets up compressed swap in RAM.
# - podman and podman-docker run Claude's toolchains in containers.
# - claude-code comes from mkosi.sandbox/etc/yum.repos.d.
# - git-core and openssh-clients let Claude Code use git and push over ssh.
# - The rest are basic command-line tools Claude uses on the host.
Packages=
kernel-core
systemd
dbus-broker
systemd-udev
systemd-networkd
systemd-resolved
systemd-container
gnupg2
systemd-boot-unsigned
util-linux
shadow-utils
systemd-pam
openssh-server
zram-generator-defaults
podman
podman-docker
claude-code
git-core
openssh-clients
kernel-core # It has no drivers or firmware VMs don't need.
systemd # It is the init and service manager.
dbus-broker # It is D-Bus, for the user manager and podman.
systemd-udev # It has udev, sysupdate, repart and cryptsetup.
systemd-networkd # It runs DHCP on every network card.
systemd-resolved # It resolves DNS names.
systemd-container # It has systemd-pull and gnupg2 for sysupdate.
systemd-boot-unsigned # It is the boot loader, which mkosi signs.
util-linux # It has login, for the console login.
shadow-utils # It has newuidmap for rootless podman.
systemd-pam # It gives logins a session and user manager.
openssh-server # It lets you log in once there is a key.
zram-generator-defaults # It sets up compressed swap in RAM.
podman # It runs Claude's tools in containers.
claude-code # It comes from mkosi.sandbox/etc/yum.repos.d.
git-core # It brings openssh-clients to push over ssh.
# The rest are basic command-line tools Claude uses on the host.
curl
tar
gzip
@@ -72,48 +60,37 @@ Packages=
iproute
WithDocs=no
Locale=C.UTF-8
# UnifiedKernelImageFormat names UKIs the way systemd-sysupdate names the ones
# it installs.
# Hostname is agent- and four hex digits of the machine ID.
Hostname=agent-????
# UnifiedKernelImageFormat names the UKI in the ESP agent_<version>.efi, which
# matches the MatchPattern= of mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer.
UnifiedKernelImageFormat=%i_%v
# KernelCommandLine sets:
# - console= shows the console on the serial port and the screen. The last
# one, the screen, is /dev/console, where systemd-firstboot asks for the root
# password at first boot.
# - rw mounts the root filesystem writable. The initrd finds it by its
# partition type (mkosi.extra/usr/lib/repart.d/50-root.conf).
# - systemd.hostname= names each machine agent- and four hex digits from its
# machine ID, from the initrd on. It wins over /etc/hostname, so hostnamectl
# renames only until the next boot.
# - systemd.image_policy= makes the initrd use only an encrypted root
# filesystem (or none yet, at first boot) and a verity-checked /usr.
# Otherwise someone with the disk could put in a plain root filesystem with
# their own /etc. Our UKI would boot it, and with PCR 11 unchanged, their
# code could unseal the key of the real one.
# - SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST lets systemd handle more mount
# changes per second. At the default of 5, it holds back mounts at boot and
# delays / and /usr by up to a second each. The kernel passes it to systemd
# as environment.
KernelCommandLine=
# The console shows on the serial port and the screen. The screen
# comes last, so systemd-firstboot asks for the root password there.
console=ttyS0,115200n8
console=tty0
quiet
# The initrd finds the root filesystem by its partition type
# (mkosi.extra/usr/lib/repart.d/50-root.conf) and mounts it writable.
rw
systemd.hostname=agent-????
# The image policy only accepts an encrypted root filesystem (or none,
# at first boot) and a verity-checked /usr. Otherwise someone with the
# disk could swap in a plain root filesystem. Our UKI would boot it, and
# their code could unseal the key of the real one.
systemd.image_policy=root=encrypted+absent:usr=verity:esp=unprotected
# The mount rate limit is raised from 5, which holds back mounts at
# boot and delays / and /usr by up to a second each.
SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50
# KernelInitrdModules are the modules the initrd needs to find the disks of a
# VM, mount /usr and make, unlock and mount the root filesystem.
# VM, mount /usr and unlock the root filesystem. The kernel has virtio_blk,
# sd_mod, the TPM drivers and btrfs built in.
KernelInitrdModules=
virtio_blk
virtio_scsi
sd_mod
nvme
tpm_tis
tpm_crb
dm-verity
dm-crypt
erofs
btrfs
# KernelModules keeps all modules but the hardware drivers, then the drivers a
# VM needs (disks, network, screen) and those of rootless podman's networks
# (pasta). The last matching line wins. Keyboard, USB and a basic screen are
@@ -126,7 +103,6 @@ KernelModules=
/drivers/md/*
nvme
virtio_scsi
sd_mod
virtio_net
qemu_fw_cfg
bochs
@@ -135,42 +111,29 @@ KernelModules=
tun
# RemoveFiles drops what the image doesn't use:
# - System.map is only for debugging the kernel.
# - The udev hwdb holds hardware names and quirks, nothing a VM needs.
# - homed, userdbd and nsresourced are unused services.
# - The udev hwdb holds hardware names and quirks, nothing a VM needs. Without
# hwdb.d, systemd-hwdb-update can't build it again at boot.
RemoveFiles=
/usr/lib/modules/*/System.map
/usr/lib/udev/hwdb.bin
/usr/lib/udev/hwdb.d
/usr/lib/systemd/system/systemd-homed*
/usr/lib/systemd/system/systemd-userdbd.*
/usr/lib/systemd/system/systemd-nsresourced.*
[Validation]
# SecureBoot signs systemd-boot and the UKI, and puts our keys on the ESP.
# systemd-boot enrolls them at first boot if the firmware is in setup mode (no
# keys enrolled; in Proxmox, an EFI disk without pre-enrolled keys). mkosi.key
# is the SECUREBOOT_KEY secret, which .gitea/workflows/os.yml writes.
# keys enrolled).
SecureBoot=yes
SecureBootKey=mkosi.key
SecureBootCertificate=mkosi.crt
# SignExpectedPcr signs the PCR 11 values that each UKI will measure, with
# mkosi.key. The TPM then unlocks the root filesystem only for UKIs we signed,
# also after updates (mkosi.extra/usr/lib/repart.d/50-root.conf).
SignExpectedPcr=yes
[Runtime]
# Runtime sets up the test VM of mkosi vm (AGENTS.md). Ephemeral boots a copy,
# so test runs don't change the built image. Credentials sets the root
# password, and systemd.firstboot=no skips the questions at first boot, such
# as the offer of a recovery key. mkosi ssh logs in as root with mkosi.key,
# which mkosi also authorizes for root in the VM.
# Runtime sets up the test VM of mkosi vm.
Ephemeral=yes
CPUs=4
RAM=8G
RAM=4G
RuntimeSize=40G
# QemuArgs joins the serial port to the console mkosi vm shows (hvc0). The UKI
# doesn't use hvc0: with Secure Boot, systemd-stub ignores the console= mkosi
# passes.
QemuArgs=-serial chardev:console
Credentials=passwd.plaintext-password.root=root
KernelCommandLineExtra=systemd.firstboot=no