Joerg Behrmann [Wed, 15 Nov 2023 11:23:36 +0000 (12:23 +0100)]
Post-release NEWS updates
This moves a few things further up to make them more prominent, like the
renaming of presets and the addition of profiles and also adds a the new esp
output format and a note about resolv.conf now needing WithNetwork=true to be
mapped during script runtime.
This is always a bit subjective, but I find a NEWS file much easier to read if
it's thematically organized. I think support for a new distro is important, so
put that first, then new verbs and options, then new configuration features,
and then all the other smaller changes.
Daan De Meyer [Thu, 9 Nov 2023 18:30:39 +0000 (19:30 +0100)]
Set ESP output minimum size based on sector size
Based on the sector size, a minimum size is required for FAT32 to
be bootable by OVMF. Instead of wasting space by always using 512MB,
let's set the minimum size based on the given sector size.
Daan De Meyer [Sun, 5 Nov 2023 13:00:59 +0000 (14:00 +0100)]
Add kernel-install plugin from mkosi-initrd
Let's support kernel-install natively in mkosi. This commit moves
the kernel-install plugin from mkosi-initrd into mkosi itself with
a few adaptations:
- We look for initrd configuration in /usr/lib/mkosi-initrd and
/etc/mkosi-initrd using "--include"
- We always include the host's kernel modules using --extra-tree
- We skip the mkosi-initrd plugin unless initrd_generator is
explicitly set to "mkosi-initrd". This allows the mkosi package
to be installed without also using it as the initrd generator if
initrd_generator is not configured explicitly.
This commit also extends the default fedora image to build the mkosi
rpm if the spec sources are mounted at rpm/ using BuildSources=. We
also configure the default image to use mkosi-initrd as the initrd
generator and ukify as the uki generator, so that running kernel-install
in the booted image will build a UKI using mkosi-initrd and ukify.
Daan De Meyer [Wed, 8 Nov 2023 12:37:33 +0000 (13:37 +0100)]
building rpms from source doc improvements
- Use env --chdir= instead of spawning a shell
- Document that scripts are executed in the same directory that
mkosi is running in and get rid of all uses of $SRCDIR and
$CHROOT_SRCDIR in favor of relative paths. We have to use $PWD
when actually building the rpm as some macros expect the topdir
to be an absolute path.
Daan De Meyer [Wed, 8 Nov 2023 11:29:39 +0000 (12:29 +0100)]
Use package manager specific subdirectories in the cache directory
We want to be able to set --cache-dir=/var/cache to automatically
reuse the system cache for each installed package manager, so let's
make sure we use the right subdirectories for each package manager
to make that work properly.
Daan De Meyer [Tue, 7 Nov 2023 21:10:47 +0000 (22:10 +0100)]
Add QemuDrives= option
This option allows specifying extra qemu drives to pass to qemu.
mkosi will create a file (optionally in the given directory) of
the given size and pass it to qemu via -drive, optionally with some
extra options.
Doing this in mkosi allows mkosi to automatically manage the lifetime
of the file backing the drive. We can create it as needed and remove it
when we exit.
Daan De Meyer [Tue, 7 Nov 2023 08:43:13 +0000 (09:43 +0100)]
Add BuildSourcesEphemeral= to the rpms from source doc.
rpmbuild with --build-in-place is a top offender when it comes to
writing files to the source directory, so let's suggest enabling
BuildSourcesEphemeral= in the building rpms from source doc.
Daan De Meyer [Mon, 6 Nov 2023 20:35:09 +0000 (21:35 +0100)]
Add BuildSourcesEphemeral=
Unfortunately there are use cases where it's useful to persist
changes to the source directory. A prime example is projects with
Makefile that do not provide a properly functioning `make install`.
The only way to use those with mkosi build scripts is to do an
in-tree build in the build script and then mounting the source
directory into the VM or container when booting it. For this to work
we need changes to the source directory to be persisted. To support
this use case, let's gate the ephemeral source directories behind an
option that's disabled by default (for backwards compatibitity reasons).
Daan De Meyer [Mon, 6 Nov 2023 13:04:26 +0000 (14:04 +0100)]
Make source directories ephemeral when running scripts
Various tools like to write to the source directory, which we want
to avoid. Let's make source directories ephemeral when running scripts
so tools can write to it as much as they want but we can throw away all
those changes when we're done running scripts.
Specifically, this makes running rpmbuild as documented in
docs/building-rpm-from-source.md a lot nicer as the source directory won't be
polluted with all manner of temporary files anymore.
Daan De Meyer [Mon, 6 Nov 2023 12:58:56 +0000 (13:58 +0100)]
Stop using workspace directories in source directories
Preparation for making source directories volatile while running
scripts. Overlapping overlayfs directories cause massive mayhem so
to keep our sanity, let's make sure the workspace directory is never
a subdirectory of any source directories.
XDG doesn't provide an equivalent of /var/tmp but when running in /home
we really want the workspace to be located in /home as well so we can use
reflinks if /home is a separate partition so we opt to use XDG_CACHE_HOME
or $HOME/.cache instead.
Daan De Meyer [Mon, 6 Nov 2023 10:28:16 +0000 (11:28 +0100)]
Fix mount_overlay() with multiple lowerdirs
Multiple lower directories are specified by delimiting with colons,
not by specifying the lowerdir= option multiple times. Also, the
lowerdirs are stacked right to left so make sure we reverse the given
list.
Daan De Meyer [Mon, 6 Nov 2023 14:40:19 +0000 (15:40 +0100)]
Fix RuntimeTrees=
We previously made the target path non-optional but this doesn't actually
work for RuntimeTrees=, where we need optional paths. So instead, let's
introduce ConfigTree to abstract the tree concept and have a class where
we can define methods on to make working with trees easier.
Daan De Meyer [Sun, 5 Nov 2023 12:15:50 +0000 (13:15 +0100)]
Use rpm to install rpms in building rpms from source doc
Let's get rid of an unnecessary indirection and just use rpm directly
to install the rpms we built in the previous step as all the dependencies
will be installed already and as such we don't need dnf.
Sharing of a directory for the (package) cache seems fine. The package manager
shall use subdirectories and/or unique file names, so there should be no
accidental conflict, and using the same cache directory allows the cache to be
reused when possible. OTOH, sharing of the directory for the build directory is
unlikely to be useful (since at least the configuration will usually be
different, so the build would generally mean rebuilding anything anyway), but
also the build system might not do cache invalidation strongly enough, leading
to inadvertetent sharing of build artifacts. Let's avoid the issue completely
but not sharing the build directory between different distributions releases or
architectures.
dnf5 is nice, but it has some issues, for example installation of rhel9
currently fails with some error about signature. Using dnf instead works around
the problem. Allow the user to override the selection using an environment
variable (or Environment=).
(We have the tools directory, but it doesn't help here because we want to use
'dnf' instead of 'dnf5' and not a different version of 'dnf5'.)
Daan De Meyer [Wed, 1 Nov 2023 11:49:52 +0000 (12:49 +0100)]
Fix incremental caching
- Make sure the distribution, release and architecture are also part
of the cache manifest
- Remove the output name from the cache key and use the distribution,
release, architecture and optionally image name instead.
- Use MkosiEncoder to serialize the cache manifest.
Rework the interface of finalize_host_scripts() to take a dictionary
We would create <chroot> in the calling function, then pass it to
finalize_host_scripts(), which would rename it during installation to "mkosi-chroot".
This is too much magic: when looking for 'mkosi-chroot' in the code, the name appears
in one place, and the definition in a completely different place. It's also hard to
extend with other commands in the future. Let's use the proper name from the
beginning and switch to a dictionary, so we can add other helpers in the future.
Backslashes were required in old python versions, but thankfully they are not
anymore. Even though we used the continuation backslashes, we already had
parenthesis everywhere, so let's just drop the backslashes, and also use a
trailing comma per the usual style.
(https://github.com/python/cpython/issues/56991 says that this happened in
Python 3.10, but it also works with Python 3.9.18 here. I guess the CI will
provide the definite confirmation.)
mkosi-chroot: just run shell if no arguments are specified
chroot(1) is documented to run "$SHELL -i" as the default command. Let's do
something similar and call "sh -i". When a user is using '--debug-shell' and one
of the scripts fails, the mkosi-chroot can be used to chroot into the image.
I think this is what users expect, based on the 'chroot' in the name.
(I don't think using $SHELL makes sense. It could either be set to 'sh', or to
something from the outside, which might not even be installed in the chroot. We
call 'sh' ourselves, so we know it must be there, so let's just call that
uncoditionally.)
Daan De Meyer [Sat, 28 Oct 2023 19:38:37 +0000 (21:38 +0200)]
Don't mount our own passwd when building images
It's much more important that we use the image's /etc/passwd instead
of our own. Both inside and outside the image so that UIDs/GIDs get
resolved correctly.
Daan De Meyer [Sat, 28 Oct 2023 15:49:14 +0000 (17:49 +0200)]
Extend README instructions
Let's make sure we have complete copy-paste shell commands for
all the different installation methods. Let's also avoid confusion
and always use python3 in the example commands.
Daan De Meyer [Sat, 28 Oct 2023 10:42:58 +0000 (12:42 +0200)]
Add BuildSources= match
One pattern I've started using a lot when I have to build multiple
projects from source in a build script is to check if a source tree
has been mounted at some location using BuildSources= and to only
build the project if that's the case.
The problem with this is that this only allows me to skip the build,
it doesn't allow me to skip installing the necessary build and runtime
packages for that particular project.
Let's add a BuildSources= match so that everything related to the
project can be skipped if the project is not configured to be mounted
at some location using BuildSources=.
Daan De Meyer [Sat, 28 Oct 2023 11:33:40 +0000 (13:33 +0200)]
Make sure the chroot scripts dir variable is not overwritten
We used `d` for both the chroot scripts dir and the host scripts dir,
which means the host scripts dir overwrites the chroot scripts dir
variable. This isn't a problem when there's only one script, but
becomes an issue when there's multiple scripts of the same type.
Daan De Meyer [Fri, 20 Oct 2023 19:21:18 +0000 (21:21 +0200)]
Stop using subdirectories of cache and build dirs automatically
In some cases, for example mkosi-initrd running as a kernel-install
script, we want to reuse the system package cache. Currently this is
impossible as we unconditionally create a subdirectory beneath the
provided cache directory. Let's stop doing that, as users can now
explicitly configure this behavior themselves by specifying the
cache directory or build directory as follows:
Additionally, make sure the default tools tree only reuses the same
cache as the preset it's used for when the distribution, release and
architecture are the same as the preset's.
Daan De Meyer [Fri, 27 Oct 2023 19:17:27 +0000 (21:17 +0200)]
Parse mkosi.local.conf before parsing any other files
Currently extra local configuration is a bit implicit, users have
to add a drop-in in mkosi.conf.d/ named 00-local.conf or so and add
that to the gitignore. This file will then unconditionally override
settings from mkosi.conf even if that's not intended.
Let's make local configuration a bit more explicit by parsing
mkosi.local.conf in a directory first before parsing anything else.
This makes local configuration easy to detect and grep for, and
makes sure that local configuration is by default overridden by
non-local configuration.
Daan De Meyer [Fri, 27 Oct 2023 12:22:09 +0000 (14:22 +0200)]
Make mkosi.repart/ append to the default value for RepartDirectories=
While for other list based settings that have a canonical path, we
generally want to append them all to the user provided values, for
RepartDirectories=, it probably makes more sense that if the user
specifies it explicitly, it overrides all the directories defined by
the project in mkosi.repart/ directories. Let's accomodate this by
having mkosi.repart/ modify the default value for RepartDirectories=
which is only used if the setting is not set explicitly.
Daan De Meyer [Fri, 27 Oct 2023 13:41:41 +0000 (15:41 +0200)]
Fail when CLI configuration is not applied to any image
Currently we silently ignore settings configured via the CLI that
are overridden by image configuration files. Let's instead fail with
a descriptive error message when this happens, indicating users that
they should use '@' in their configuration files to set the default
value for the setting if they want to allow overriding it from the
command line.
Daan De Meyer [Fri, 27 Oct 2023 09:19:27 +0000 (11:19 +0200)]
Don't use configured default value when empty string is assigned
Currently, if a setting is assigned the empty string on the CLI, any
default value configured in the config file is still used. Let's change
this and not use any configured default value when the empty string is
assigned so that default values configured in config files can be
overridden from the CLI.
Daan De Meyer [Thu, 26 Oct 2023 14:04:36 +0000 (16:04 +0200)]
action: Make logic for unprivileged KVM access more robust
- Copy static-nodes-permissions.conf to /etc before modifying so our
modifications don't get overwritten if systemd is updated.
- Add udev rules to set the permissions correctly as well
Daan De Meyer [Mon, 23 Oct 2023 20:33:32 +0000 (22:33 +0200)]
Fix missing build overlay
We also need a build overlay if there are prepare scripts but no
build packages, so let's replace need_build_packages() with a new
function need_build_overlay() that also checks for that.
Daan De Meyer [Sun, 22 Oct 2023 18:26:12 +0000 (20:26 +0200)]
Rename Presets to Images
Presets doesn't really have any meaning without searching up its
definition. By just using mkosi.images/, it's much clearer that the
directory contains image definitions compared to mkosi.presets/.
The old names are kept intact for backwards compatibility.
Daan De Meyer [Sun, 22 Oct 2023 13:53:22 +0000 (15:53 +0200)]
Add support for profiles
A profile is a set of configuration options that represents a known
variant of the given image. Its primary purpose is to allow grouping
known useful derivatives of the current image under a recognizable
identifier.
The difference with presets is that presets represent the individual
images that might need to be built to complete the final image, whereas
profiles change how the individual presets are built. Specifically, only
ever one profile can be selected, while it's perfectly valid to build
many presets.
We parse the specified profile after mkosi.conf but before
mkosi.conf.d to allow configuring the profile to build in mkosi.conf.