From e98ca7a888eefacfe7dc1b0f052d985f1ca1b105 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 Aug 2024 19:00:09 +0200 Subject: [PATCH] Do not allow configuring universal collection based settings in subimages For the next commit, we want to enforce all subimages to use the same package manager trees, repositories and package directories, so let's not allow adding any extra of those in subimages anymore. --- NEWS.md | 7 +++++++ mkosi/config.py | 20 +++++++------------- mkosi/initrd/__main__.py | 1 + mkosi/resources/mkosi-initrd/mkosi.conf | 1 - mkosi/resources/mkosi.md | 4 +--- tests/test_config.py | 14 ++------------ 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4090bab2d..45d7de84b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # mkosi Changelog +## v25 + +- Universal settings that take a collection of values cannot be + appended to anymore in subimages. Usage of package manager trees in + subimages will have to be moved to the top level image. Similarly, + repositories will have to be enabled in the top level image. + ## v24 - The default kernel command line of `console=ttyS0` (or equivalent for diff --git a/mkosi/config.py b/mkosi/config.py index 30d0f21bb..4210e8f77 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -3662,6 +3662,12 @@ class ParseContext: delattr(self.config, s.dest) for s in SETTINGS: + if ( + s.scope == SettingScope.universal and + (image := getattr(self.config, "image", None)) is not None + ): + continue + for f in s.paths: extra = parse_path( f, @@ -3696,7 +3702,6 @@ class ParseContext: die(f"Unknown setting {name}") if ( s.scope == SettingScope.universal and - not isinstance(s.parse(None, None), (list, set, dict)) and (image := getattr(self.config, "image", None)) is not None ): die(f"Setting {name} cannot be configured in subimage {image}") @@ -3823,18 +3828,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu # were specified on the CLI by copying them to the CLI namespace. Any settings # that are not marked as "universal" are deleted from the CLI namespace. for s in SETTINGS: - if ( - s.scope == SettingScope.universal and ( - # For list-based settings, don't pass down empty lists unless it came - # explicitly from the config file or the CLI. This makes sure that default - # values from subimages are still used if no value is explicitly configured - # in the main image or on the CLI. - not isinstance(getattr(config, s.dest), (list, dict, set)) or - getattr(config, s.dest) or - hasattr(context.cli, s.dest) or - hasattr(context.config, s.dest) - ) - ): + if s.scope == SettingScope.universal: setattr(context.cli, s.dest, copy.deepcopy(getattr(config, s.dest))) elif hasattr(context.cli, s.dest): delattr(context.cli, s.dest) diff --git a/mkosi/initrd/__main__.py b/mkosi/initrd/__main__.py index cc966bcd8..4e42a6acf 100644 --- a/mkosi/initrd/__main__.py +++ b/mkosi/initrd/__main__.py @@ -76,6 +76,7 @@ def main() -> None: "--remove-files=/usr/lib/firmware/*-ucode", "--kernel-modules-exclude=.*", "--kernel-modules-include=host", + "--build-sources", "", "--include=mkosi-initrd", ] diff --git a/mkosi/resources/mkosi-initrd/mkosi.conf b/mkosi/resources/mkosi-initrd/mkosi.conf index a8d473561..d4d5a5045 100644 --- a/mkosi/resources/mkosi-initrd/mkosi.conf +++ b/mkosi/resources/mkosi-initrd/mkosi.conf @@ -6,7 +6,6 @@ Format=cpio ManifestFormat= [Content] -BuildSources= Bootable=no MakeInitrd=yes CleanPackageMetadata=yes diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 852b9081b..e80b6cf0b 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -2475,9 +2475,7 @@ configuration (configuration outside of the `mkosi.images/` directory), followed by the image specific configuration. Several "universal" settings apply to the main image and all its subimages and cannot be configured separately in subimages. The following settings are universal -and cannot be configured in subimages (except for settings which take a -collection of values which can be extended in subimages but not -overridden): +and cannot be configured in subimages: - `Profile=` - `Distribution=` diff --git a/tests/test_config.py b/tests/test_config.py index 0bdfbe5c3..3abb21a16 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -253,9 +253,6 @@ def test_parse_config(tmp_path: Path) -> None: (d / "mkosi.images/one.conf").write_text( """\ - [Distribution] - Repositories=append - [Content] Packages=one """ @@ -265,9 +262,6 @@ def test_parse_config(tmp_path: Path) -> None: (d / "mkosi.images/two/mkosi.skeleton").mkdir() (d / "mkosi.images/two/mkosi.conf").write_text( """ - [Distribution] - Repositories=append - [Content] Packages=two @@ -295,17 +289,13 @@ def test_parse_config(tmp_path: Path) -> None: assert config.packages == ["qed"] assert config.build_packages == ["def"] - # list based settings should be appended to in subimages - assert one.repositories == ["append", "epel", "epel-next", "cli"] - assert two.repositories == ["append", "epel", "epel-next", "cli"] - # Inherited settings should be passed down to subimages but overridable by subimages. assert one.image_version == "1.2.3" assert two.image_version == "4.5.6" - # Default values from subimages should be picked up. + # Default values from subimages for univeral settings should not be picked up. assert len(one.package_manager_trees) == 0 - assert len(two.package_manager_trees) == 1 and two.package_manager_trees[0].source.name == "mkosi.skeleton" + assert len(two.package_manager_trees) == 0 with chdir(d): _, [one, two, config] = parse_config(["--image-version", "7.8.9"]) -- 2.47.3