]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fail when trying to change universal settings in subimages
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 16 Jul 2024 09:48:04 +0000 (11:48 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 17 Jul 2024 08:43:02 +0000 (10:43 +0200)
Let's error out when users try to configure universal settings in
subimages since these will always be overridden.

mkosi/config.py
tests/test_config.py

index ae66728cbca66c5f7400d3ed974f9561ee9e1e12..c4dde5bfde14a86440644cd5aeb8018e3e079b3a 100644 (file)
@@ -3663,6 +3663,12 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
 
                 if not (s := SETTINGS_LOOKUP_BY_NAME.get(name)):
                     die(f"Unknown setting {name}")
+                if (
+                    s.universal and
+                    not isinstance(s.parse(None, None), (list, set, dict)) and
+                    (image := getattr(ParseContext.config, "image", None)) is not None
+                ):
+                    die(f"Setting {name} cannot be configured in subimage {image}")
                 if name in ParseContext.immutable:
                     die(f"Setting {name} cannot be modified anymore at this point")
 
index 692c6cccbde8b074417e05b31b4ccd5ef474fcb4..0f7ae270309265585a70c911ddb026807dff8ebe 100644 (file)
@@ -255,7 +255,7 @@ def test_parse_config(tmp_path: Path) -> None:
         (d / "mkosi.images" / f"{n}.conf").write_text(
             f"""\
             [Distribution]
-            Release=bla
+            Repositories=append
 
             [Content]
             Packages={n}
@@ -263,7 +263,7 @@ def test_parse_config(tmp_path: Path) -> None:
         )
 
     with chdir(d):
-        _, [one, two, config] = parse_config(["--package", "qed", "--build-package", "def"])
+        _, [one, two, config] = parse_config(["--package", "qed", "--build-package", "def", "--repositories", "cli"])
 
     # Universal settings should always come from the main image.
     assert one.distribution == config.distribution
@@ -281,6 +281,10 @@ 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"]
+
 
 def test_parse_includes_once(tmp_path: Path) -> None:
     d = tmp_path