Skip to content

Commit

Permalink
Fail when trying to change universal settings in subimages
Browse files Browse the repository at this point in the history
Let's error out when users try to configure universal settings in
subimages since these will always be overridden.
  • Loading branch information
DaanDeMeyer committed Jul 17, 2024
1 parent 7e97595 commit 18dc79b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3663,6 +3663,12 @@ def parse_config_one(path: Path, profiles: bool = False, local: bool = False) ->

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")

Expand Down
8 changes: 6 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ 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}
"""
)

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
Expand All @@ -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
Expand Down

0 comments on commit 18dc79b

Please sign in to comment.