Daan De Meyer [Mon, 18 Nov 2024 20:06:17 +0000 (21:06 +0100)]
Also fail early if default tools tree is out of date without --force
We fail early if the tools tree does not exist and build or --force
was not specified, let's do the same if the tools tree is incremental
and the cache is out-of-date.
Daan De Meyer [Sat, 16 Nov 2024 14:47:43 +0000 (15:47 +0100)]
Add ToolsTreePackageDirectories=
Sometimes, we want to add locally built rpm packages to the default
tools tree. For example, systemd-repart depends on mkfs binaries that
might not be available on the host system, so the only way to run it
is from within the tools tree, which means we need a way to install
systemd-repart built from source within the tools tree.
Daan De Meyer [Fri, 15 Nov 2024 15:24:18 +0000 (16:24 +0100)]
Use passwd symlinks instead of bind mounts
Bind mounts don't reflect changes to the original files if they're
replaced instead of modified. Let's use symlinks instead so that
changes to the original files are always reflected.
Daan De Meyer [Fri, 15 Nov 2024 11:51:19 +0000 (12:51 +0100)]
Add --debug-sandbox
This will help in debugging sandbox related issues. We run the sandbox
with strace and detach on execve() so we don't strace the command that
we're running.
Davide Cavalca [Wed, 13 Nov 2024 02:41:12 +0000 (18:41 -0800)]
fixup: GitHub Action: Install all required mkosi dependencies
8505a5303bb0c65991faf59a45409330e0c16a92 lost the --assume-yes
--no-install-recommends. While the former seems to be implicit in the
GitHub runner environment, the latter isn't, and it seems best to leave
both in place.
Michael Ferrari [Mon, 11 Nov 2024 01:18:22 +0000 (02:18 +0100)]
Refactor resolve_deps and reorder after configure
As a configure script can modify the config in nearly any way it pleases
it is not impossible that dependencies may be resolved at runtime. So
just rerun dependency resolution after all configure scripts have done
their stuff.
Daan De Meyer [Sun, 3 Nov 2024 19:18:39 +0000 (20:18 +0100)]
Remove sandbox verb from needs_build()
It's not a clear cut case whether the sandbox needs a build or not.
The needs_build() method was originally intended for verbs that need
a full image build but the sandbox build only needs the tools tree.
Also, the tools tree is only built if ToolsTree=default and not if
set explicitly.
More practically, we don't want the JSON history from .mkosi-private
to be used when using mkosi sandbox, and that's the only usage of
the needs_build() method, so to fix that problem let's remove the sandbox
verb from needs_build().
Daan De Meyer [Fri, 1 Nov 2024 18:50:10 +0000 (19:50 +0100)]
Set up a private session keyring for engine pin caching
If we're using an engine as a key source, let's set up a private
session keyring and configure systemd tooling to store pins in the
session keyring with infinite lifetime. This means systemd will only
prompt for a pin once per key and reuse the cached pin from the session
keyring from that point onwards. The session keyring is automatically
removed when mkosi exits.
Daan De Meyer [Sat, 2 Nov 2024 17:57:31 +0000 (18:57 +0100)]
Add sandbox verb
In systemd, to run the integration tests, we need to run meson on
the host which will itself invoke mkosi to run the integration tests.
This means all the dependencies to run meson need to be installed on
the host. This doesn't just mean meson needs to be installed, but also
a compiler and various required build dependencies of systemd to allow
building tools invoked by mkosi to build the image.
To avoid having to install these dependencies on the host system, let's
introduce a sandbox verb which runs a command in the mkosi sandbox that's
also used by other verbs such as boot, qemu and shell. This then allows
extra required tools to be installed in the tools tree via ToolsTreePackages=
to allow running these commands without having to install them on the host
system.
Daan De Meyer [Sat, 2 Nov 2024 15:11:07 +0000 (16:11 +0100)]
Add PATH entries beneath the user's home to PATH in relaxed sandbox
This handles the case where a user adds ~/.local/bin to the PATH.
Let's make sure we use that even when running with a tools tree.
This might not work for binaries that are built against libraries
from the user's host /usr but there's lots of tools that will either
be statically compiled or written in an interpreted language like
python that will still work even when we switch out /usr from underneath
them.
Daan De Meyer [Sat, 2 Nov 2024 15:09:29 +0000 (16:09 +0100)]
Ignore crypto mount if it only contains empty directories
Let's beef up the crypto mount check and check if there are only
empty directories in the mount and ignore it if that's the case.
This handles the case where e.g. on Arch installing pesign leads
to /etc/pki containing only /etc/pki/pesign as an empty directory.
Daan De Meyer [Sat, 2 Nov 2024 15:08:05 +0000 (16:08 +0100)]
Don't remove default tools tree when mkosi -ff is used
Generally when -ff is specified users won't want to remove the
default tools tree if they're using one, so let's stop doing that.
The default tools tree is still removed when mkosi -f clean is invoked.
Daan De Meyer [Sat, 2 Nov 2024 15:06:42 +0000 (16:06 +0100)]
Make default tools tree output name distribution independent
We included the distribution name when we first added this because
the tools tree distribution was different depending on which distribution
we were building. Now that we choose the tools tree distribution based on
the host distribution, this doesn't make much sense anymore, so get rid
of the distribution in the default tools tree output name and name it just
"tools" instead.
Michael Ferrari [Fri, 1 Nov 2024 12:24:21 +0000 (13:24 +0100)]
Remove BuildDirectory= from PrepareScripts=
The BuildDirectory= is meant for files which are non-essential and can
be recreated during the build process of the image, so source files that
need to be acquired should be saved somewhere within the $BUILDROOT to
be cached for runs when PrepareScripts= aren't run (assuming incremental
builds).
Daan De Meyer [Thu, 31 Oct 2024 10:58:28 +0000 (11:58 +0100)]
Map current user to root in subuid user namespace
By mapping the current user to root in the subuid user namespace,
we don't have to change the ownership of all the files in the directory
tree to root in the subuid uid/gid range. This means that on btrfs
filesystems, we can do a subvolume snapshot instead of an expensive
full tree recursion to copy each file individually.
Daan De Meyer [Thu, 31 Oct 2024 11:36:09 +0000 (12:36 +0100)]
Bind /run when an engine might be used instead of only /run/pcscd
It's not guaranteed that the engine will be the pkcs#11 one so let's
bind the entirety of /run in case another daemon might be used with
a socket elsewhere in /run.
Daan De Meyer [Wed, 30 Oct 2024 09:38:05 +0000 (10:38 +0100)]
Never clean output directory when Format=none
If Format=none no outputs can be produced at all so let's make sure
we always keep the previous outputs intact when Format=none regardless
of whether -f is specified or not.
Check if firmware subdirectory still exists before trying to remove it
Detected with `mkosi-initrd`:
```
Calculating required kernel modules and firmware
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mkosi/run.py", line 64, in uncaught_exception_handler
yield
File "/usr/lib/python3.11/site-packages/mkosi/run.py", line 105, in fork_and_wait
target(*args, **kwargs)
File "/usr/lib/python3.11/site-packages/mkosi/__init__.py", line 4450, in run_build
build_image(
File "/usr/lib/python3.11/site-packages/mkosi/__init__.py", line 3668, in build_image
run_depmod(context)
File "/usr/lib/python3.11/site-packages/mkosi/__init__.py", line 2721, in run_depmod
process_kernel_modules(
File "/usr/lib/python3.11/site-packages/mkosi/kmod.py", line 248, in process_kernel_modules
p.rmdir()
File "/usr/lib64/python3.11/pathlib.py", line 1156, in rmdir
os.rmdir(self)
FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/mkosi-workspace-9r8egfmc/root/usr/lib/firmware/yamaha'
```
Daan De Meyer [Mon, 28 Oct 2024 20:27:30 +0000 (21:27 +0100)]
Remove access to the output directory in build scripts
With mkosi -t none, we can rerun the build script without cleaning
the output directory. This creates an awkward situation, as the build
script might create new outputs but is unable to remove previous ones,
which could lead to weird situations where the output directory contains
artifacts from multiple builds.
Let's tighten this up by disallowing access to the output directory in
build scripts. Users can still copy from the build script to the output
directory by doing the copy from a post-installation script which is not
invoked when we run mkosi -t none so it only runs when we've cleaned up
the output directory.
`less` had hard requirements on `which` and `file` (so also `file-magic` and
`libmagic1`), reworked via packaging in Tumbleweed (
https://build.opensuse.org/request/show/1218137) and available since snapshot 20241025.
```
‣ /tmp/tmpgpvfc6y8/initrd.cpio.zst size is 44.9M, consumes 44.9M.
‣ Copying /tmp/tmpgpvfc6y8/initrd to /tmp/kernel-install.staging.KXnXSC/initrd
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mkosi/run.py", line 64, in uncaught_exception_handler
yield
File "/usr/lib64/python3.11/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/kernel/install.d/50-mkosi.install", line 167, in main
shutil.move(next(context.staging_area.glob("initrd*.cpio*")), context.staging_area / "initrd")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration
/usr/lib/kernel/install.d/50-mkosi.install failed with exit status 1.
```
Daan De Meyer [Tue, 22 Oct 2024 17:40:10 +0000 (19:40 +0200)]
Use virtio-blk-pci unless scsi-hd is really needed
https://www.qemu.org/2021/01/19/virtio-blk-scsi-configuration/
mentions that for performance critical use cases, virtio-blk should
be preferred so let's use virtio-blk unless we actually need scsi-hd.
We don't currently have a way to enable the epel repositories when
using mkosi-initrd, because it always uses the exact same repositories
as the host system. However, erofs-utils can still be installed by just
including it using /usr/lib/mkosi-initrd/mkosi.conf without a match
section.