Skip to content

Commit

Permalink
Rework configuration parsing (again)
Browse files Browse the repository at this point in the history
As explained in #2846, there are multiple issues with the current
implementation of mkosi.images. Let's take what we learned from the
default initrd and the default tools tree and apply it mkosi.images.

Specifically, all issues arise from the fact that we apply every option
from the global configuration (including CLI arguments) to the images
from mkosi.images/. To avoid the issues that arise from this (e.g --package
abc installing abc in all images), we made configuration values override
CLI arguments again so that we could override faulty CLI arguments again
in subimages so that they would only apply to the main image (e.g. set
Format= explicitly for each subimage so that --format on the command line
only applies to the main image).

Because we still wanted to allow configurable settings that can be modified
via the command line, we introduced the default specifier '@' which can be
prefixed to a setting to set a default value instead of overriding the value.
The '@' specifier is generally used in the global image independent
configuration to specify default values that can be overridden from the command
line. This specifier has led to a lot of confusion, along with the behavior that
the CLI does not override the configuration.

From the default tools tree and default initrd, we learned that what works
very well is to only have specific settings from the main image configuration
apply to the default tools tree and default initrd. For example, the distribution,
release, mirror and architecture should be the same for the main image and the
initrd, but the packages from the main image should not all be installed in the
initrd.

We can apply this idea to the images from mkosi.images/ as well, if we
introduce the assumption that all images defined in mkosi.images are
subimages intended to be included in some way or form in the main image.
This assumption allows us to divide all settings into either image specific
settings or "universal" settings that should apply to the main image and all
its subimages. The universal settings are passed on to each subimage. The image
specific settings are not.

This idea also allows us to define the "main" image outside of mkosi.images
again. Since only "universal" settings are passed on, we can safely define
an output format and such again in the global configuration, as we know this
won't be passed on to subimages.

It also allows us to make CLI arguments override configuration again. Since
there is no need anymore for subimages to override the CLI configuration as
inappropriate CLI configuration such as extra packages will only apply to the
main image and not any subimages from mkosi.images/. Because CLI configuration
overrides file configuration again, we also don't need the '@' specifier anymore,
as default values can simply be set without '@', since the CLI will override
the configuration file values by default.

We also lose the need for --append, because the sole use for --append was again
to override file based configuration.

This commit implements all of what's mentioned above, specifically:

- CLI configuration now always trumps file based configuration.
- The '@' specifier is dropped automatically during parsing
- The main image is now always added from global configuration, even
if there are images in mkosi.images/. The main image is always built
last, and cannot be used as a dependency in the Dependencies= setting
for images defined in mkosi.images/.
- The Dependencies= setting for the main image now is used to specify
which subimages from mkosi.images/ to build. By default all subimages
are built.
- A universal tag is introduced for settings and appropriate settings
are marked as universal. Universal settings are passed on from the
main image configuration to subimage configuration.
- The Images= setting is removed, as it's role is replaced by
Dependencies=.
- The old name mkosi.presets and the Preset section name are removed
as they have been deprecated for a long time now.
- The config parsing tests are extended to cover more cases.
- All builtin configuration is adapted to stop using the '@' specifier.
- The documentation is updated in accordance with the changes.
  • Loading branch information
DaanDeMeyer committed Jul 8, 2024
1 parent c4a41f6 commit 811138c
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 249 deletions.
17 changes: 8 additions & 9 deletions docs/sysext.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ BaseTrees=%O/base
Packages=btrfs-progs
```

`BaseTrees=` point to our base image and `Overlay=yes` instructs mkosi
`BaseTrees=` points to our base image and `Overlay=yes` instructs mkosi
to only package the files added on top of the base tree.

We can't sign the extension image without a key, so let's generate one
Expand All @@ -72,20 +72,19 @@ key will need to be loaded into your kernel keyring either at build time
or via MOK for systemd to accept the system extension at runtime as
trusted.

Finally, you can build the base image and the extensions by running
Finally, you can build the base image and the extension by running
`mkosi -f`. You'll find `btrfs.raw` in `mkosi.output` which is the
extension image.
extension image. You'll also find the main image `image.raw` there but
it will be almost empty.

If you want to package up the base image into another format, for
example an initrd, we can do that by adding the following to
`mkosi.images/initrd/mkosi.conf`:
What we can do now is package up the base image as the main image, but
in another format, for example an initrd, we can do that by adding the
following to `mkosi.conf`:

```conf
[Config]
Dependencies=base
[Output]
Format=cpio
Output=initrd
[Content]
MakeInitrd=yes
Expand Down
12 changes: 6 additions & 6 deletions mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
[Output]
# These images are (among other things) used for running mkosi which means we need some disk space available so
# default to directory output where disk space isn't a problem.
@Format=directory
@CacheDirectory=mkosi.cache
@OutputDirectory=mkosi.output
Format=directory
CacheDirectory=mkosi.cache
OutputDirectory=mkosi.output

[Content]
Autologin=yes
@SELinuxRelabel=no
@ShimBootloader=unsigned
SELinuxRelabel=no
ShimBootloader=unsigned
BuildSources=.
BuildSourcesEphemeral=yes

Expand All @@ -36,4 +36,4 @@ RemoveFiles=
KernelCommandLine=enforcing=0

[Host]
@QemuMem=4G
QemuMem=4G
2 changes: 1 addition & 1 deletion mkosi.conf.d/15-bootable.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Architecture=|x86-64
Architecture=|arm64

[Content]
@Bootable=yes
Bootable=yes
2 changes: 1 addition & 1 deletion mkosi.conf.d/15-memory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Format=|uki
Format=|cpio

[Host]
@QemuMem=8G
QemuMem=8G
2 changes: 1 addition & 1 deletion mkosi.conf.d/15-x86-64.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Architecture=x86-64
ToolsTreeDistribution=!opensuse

[Content]
@BiosBootloader=grub
BiosBootloader=grub
4 changes: 2 additions & 2 deletions mkosi.conf.d/20-centos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Distribution=|alma
Distribution=|rocky

[Distribution]
@Release=9
Release=9

[Content]
# CentOS Stream 10 does not ship an unsigned shim
@ShimBootloader=none
ShimBootloader=none
Packages=
linux-firmware
2 changes: 1 addition & 1 deletion mkosi.conf.d/20-debian/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Distribution=debian

[Distribution]
@Release=testing
Release=testing
Repositories=non-free-firmware

[Content]
Expand Down
2 changes: 1 addition & 1 deletion mkosi.conf.d/20-fedora/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Distribution=fedora

[Distribution]
@Release=rawhide
Release=rawhide

[Content]
Packages=
Expand Down
4 changes: 2 additions & 2 deletions mkosi.conf.d/20-opensuse/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Distribution=opensuse

[Distribution]
@Release=tumbleweed
Release=tumbleweed

[Content]
# OpenSUSE does not ship an unsigned shim
@ShimBootloader=none
ShimBootloader=none
Packages=
bash
diffutils
Expand Down
2 changes: 1 addition & 1 deletion mkosi.conf.d/20-rhel-ubi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Distribution=rhel-ubi

[Distribution]
@Release=9
Release=9

[Content]
Bootable=no
2 changes: 1 addition & 1 deletion mkosi.conf.d/20-ubuntu/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Distribution=ubuntu

[Distribution]
@Release=noble
Release=noble
Repositories=universe

[Content]
Expand Down
Loading

0 comments on commit 811138c

Please sign in to comment.