Daan De Meyer [Mon, 22 Jan 2024 19:51:00 +0000 (20:51 +0100)]
Only use tools trees for verbs that need a build
Currently we try to use a tools tree that isn't there for verbs
that don't need a build. Let's instead opt to not use one altogether
since building an entire image just to run ssh is kind of overkill.
Daan De Meyer [Mon, 22 Jan 2024 14:17:01 +0000 (15:17 +0100)]
Allow including builtin configs
Let's make it possible to include builtin configurations using
e.g. Include=mkosi-initrd. This allows building the default initrd
or default tools tree independently whereas currently these can only
be built as part of another image.
Daan De Meyer [Mon, 22 Jan 2024 13:23:16 +0000 (14:23 +0100)]
Extract mkosi.resources once
Instead of extracting individual files and directories when we need
them, let's extract the resources once and pass the extracted path
around so that we don't have to deal with context managers every time
we want to use resources.
Daan De Meyer [Thu, 18 Jan 2024 08:56:45 +0000 (09:56 +0100)]
Don't mount /srv and /mnt read-only
It seems there are use cases where users expect to write their output
to a directory in /srv or /mnt so let's make that writable. This should
be safe as we set up a custom sandbox now so none of the tools we run
will have access to /srv and /mnt in the first place.
Daan De Meyer [Thu, 18 Jan 2024 09:24:45 +0000 (10:24 +0100)]
Don't preserve timestamps when copying skeleton/extra trees
If timestamps should be preserved, a tar archive should be used.
Timestamps in directories are very likely to be arbitrary and there's
no point in preserving them. This doesn't impact reproducible builds
as we have SourceDateEpoch= for that.
Daan De Meyer [Wed, 17 Jan 2024 09:34:08 +0000 (10:34 +0100)]
Revert "Don't include root password in /usr/lib/credstore"
If /etc/shadow is included in the image this is just as safe/unsafe
as including the hashed root password in /usr/lib/credstore. We'll
deal with including the plaintext root password in the next commit.
Daan De Meyer [Tue, 16 Jan 2024 20:28:41 +0000 (21:28 +0100)]
Clarify that --build-in-place sets _builddir to the CWD
This isn't exactly obvious, so let's mention that --build-in-place
configures _builddir to the current working directory which explains
why we need to change directory to the upstream sources before
invoking rpmbuild.
Daan De Meyer [Tue, 16 Jan 2024 15:39:05 +0000 (16:39 +0100)]
Cache depmod again
Let's run depmod before we cache our images so that we can skip it
when doing incremental builds for kernels installed with the package
manager. depmod is noticeably slow so this speeds up kernel builds a
bit.
Daan De Meyer [Tue, 16 Jan 2024 13:49:20 +0000 (14:49 +0100)]
kernel-install: Build microcode initrd
Let's make sure we build a microcode initrd as well in the
kernel-install plugin. It's a bit too complicated to reuse
the build_microcode_initrd() function we have already due to
sandboxing so we opt to duplicate it instead.
Daan De Meyer [Mon, 15 Jan 2024 21:24:08 +0000 (22:24 +0100)]
Add PackageDirectories=
Let's make it possible to serve local packages as a local repository
so that users don't have to put local paths in their Packages= setting.
We'll also allow adding more packages to this local repository in the
build script so that these can be installed in the initrd when we build
it or in a postinst or finalize script.
Daan De Meyer [Mon, 15 Jan 2024 19:59:03 +0000 (20:59 +0100)]
Fix --mirror for CentOS and Fedora
Let's unify the interface for --mirror and only require users to
specify a url and add the entire path ourselves in mkosi. This is
required to use EPEL repositories with --mirror= as the epel
repositories are mirrored under <url>/fedora/epel whereas the CentOS
Stream repositories are under <url>/centos-stream
Daan De Meyer [Sun, 14 Jan 2024 20:53:06 +0000 (21:53 +0100)]
Run systemd-tmpfiles as part of the build
Let's make sure we take user provided tmpfiles snippets into account
as well. Since systemd now mounts the initramfs read-only by default,
we need to make sure all tmpfiles snippets that copy to /etc have
already been processed during the image build itself as they won't be
able to run during the initramfs stage.
Daan De Meyer [Sun, 14 Jan 2024 17:02:39 +0000 (18:02 +0100)]
Make sure /etc/mtab exists in sandbox
Required for pacman's CheckSpace option. To avoid messing with the
package manager tree /etc too much, we bind mount individual
subdirectories of it instead of the entire directory.
Daan De Meyer [Sun, 14 Jan 2024 16:16:05 +0000 (17:16 +0100)]
Make sure we don't build the same tools tree more than once
We can do this by simply checking if the output path already exists
instead of relying on needs_build(). This allows us to refactor
needs_build() to needs_clean(). We also move some prechecks into
run_build() and run_clean() so as to not duplicate them and improve
the logging messages in run_clean().
Daan De Meyer [Fri, 12 Jan 2024 14:28:41 +0000 (15:28 +0100)]
Add BuildSources=. to the default image configuration
If we enable the rpm build, we set BuildSources= which means we
override the default build sources. However we still want the source
directory to be used as BuildSources= as well, so configure it explicitly.
Daan De Meyer [Fri, 12 Jan 2024 11:30:41 +0000 (12:30 +0100)]
Verify that output path is not a symlink in needs_build()
Otherwise if we first build a disk image and then try to run
"mkosi -t directory qemu" we won't actually rebuild the image as it
will think the output already exists and we'll try to boot a disk
image as a directory.
Daan De Meyer [Fri, 12 Jan 2024 09:15:53 +0000 (10:15 +0100)]
Improve SELinux binary policy selection
Let's deal with the possibility that there might be more than one
policy in the binary policy directory. Let's also make sure that we
consider other files in the directory that might not be policies.
Daan De Meyer [Thu, 11 Jan 2024 13:07:20 +0000 (14:07 +0100)]
Use grub binaries from tools tree instead of from image
Let's give this another try and use grub tools from the tools tree
instead of from the image.
We also hardcode the grub prefix per distribution because if we use
grub binaries from the tools tree there might not be any installed
in the image itself which means we can't derive the prefix from the
binaries in the image.
Daan De Meyer [Wed, 10 Jan 2024 15:47:58 +0000 (16:47 +0100)]
Check for all required setfiles inputs in want_selinux_relabel()
On Debian when policycoreutils is installed a policy is configured
without a matching binary policy being installed, so we have to
check that all parts are there.
Daan De Meyer [Wed, 10 Jan 2024 09:58:29 +0000 (10:58 +0100)]
Copy nspawn settings to the output directory again
machinectl pull-tar looks for a settings file so let's make sure
the output directory can be used directly for this purpose by copying
the nspawn settings file to the output directory again.
Daan De Meyer [Tue, 9 Jan 2024 19:22:59 +0000 (20:22 +0100)]
Use the directory mkosi was invoked in as the default for BuildSources=
While parsing config, we use chdir(). Also, when a BuildSources=
match is found, BuildSources= is initialized to its default value
which is Path.cwd(). However, we want the default value to be the
top level directory that mkosi was invoked in, not the current working
directory that we happen to be in while parsing configuration. Let's
fix this by using the directory mkosi was invoked in instead of Path.cwd().