]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Do not allow configuring universal collection based settings in subimages
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 23 Aug 2024 17:00:09 +0000 (19:00 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 23 Aug 2024 19:44:13 +0000 (21:44 +0200)
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
mkosi/config.py
mkosi/initrd/__main__.py
mkosi/resources/mkosi-initrd/mkosi.conf
mkosi/resources/mkosi.md
tests/test_config.py

diff --git a/NEWS.md b/NEWS.md
index 4090bab2db2aa9b7b9938679fe62b0c9ead303a2..45d7de84b50060c36c706df312fc32c1ae8d9737 100644 (file)
--- 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
index 30d0f21bb6d78d65d99476071b0c271b1e691526..4210e8f77f5077600e1fe199f1a6f8a7c679edec 100644 (file)
@@ -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)
index cc966bcd80c21cdd46368fce70789af5cff1a33a..4e42a6acf2f9b2f45335666d220c061417b97e39 100644 (file)
@@ -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",
     ]
 
index a8d473561a189a5a31b8ef9a131261c38b0ddbdd..d4d5a5045fa59515d2d95d43d3f8970408f24be8 100644 (file)
@@ -6,7 +6,6 @@ Format=cpio
 ManifestFormat=
 
 [Content]
-BuildSources=
 Bootable=no
 MakeInitrd=yes
 CleanPackageMetadata=yes
index 852b9081bee340daf7be8b4e1ff41ff78165d410..e80b6cf0ba22a59158c977b71d5a874b361f9e4a 100644 (file)
@@ -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=`
index 0bdfbe5c3369c074734b26f0f098dea878de8ec3..3abb21a16d01fa32e9cc5a554bc6ef62c071879a 100644 (file)
@@ -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"])