From: DaanDeMeyer Date: Thu, 8 Jan 2026 17:06:16 +0000 (+0100) Subject: Make sure we pass the right context to finalize_default_initrd() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4229f5bf5bae29264ffeed8bb347a85ca725899;p=thirdparty%2Fmkosi.git Make sure we pass the right context to finalize_default_initrd() We mess around with the context object to make it for for use when reading the subimages. But we need the full context again for parsing the default initrd later on, so make a copy before we delete stuff and pass that to finalize_default_initrd() Fixes #4114 --- diff --git a/mkosi/config.py b/mkosi/config.py index 5e5574c1c..f90fcff4a 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -5333,6 +5333,8 @@ def parse_config( context.parse_config_one(configdir, parse_profiles=True, parse_local=True) config = context.finalize() + # Keep a copy around for passing to finalize_default_initrd() later. + maincontext = copy.deepcopy(context) if config["history"] and want_new_history(args): Path(".mkosi-private/history").mkdir(parents=True, exist_ok=True) @@ -5428,7 +5430,7 @@ def parse_config( subimages = [Config.from_dict(ns) for ns in images] if any(want_default_initrd(image) for image in subimages + [main]): - initrd = finalize_default_initrd(context, config, resources=resources) + initrd = finalize_default_initrd(maincontext, config, resources=resources) if want_default_initrd(main): main = dataclasses.replace( diff --git a/tests/test_config.py b/tests/test_config.py index 20b5ecd40..2468236c9 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1652,3 +1652,34 @@ def test_assert(tmp_path: Path) -> None: parse_config(["--image-id", "abcde", "--environment", "ABC=QED"]) parse_config(["--image-id", "abcde", "--environment", "DEF=QEE"]) + + +def test_initrd_packages(tmp_path: Path) -> None: + d = tmp_path + + (d / "mkosi.conf").write_text( + """\ + [Content] + InitrdPackages=package1 + InitrdPackages=package2 + + [Content] + Bootable=yes + """ + ) + + with chdir(d), resource_path(mkosi.resources) as resources: + _, _, [initrd, _] = parse_config(resources=resources) + + assert "package1" in initrd.packages + assert "package2" in initrd.packages + + # Make sure the InitrdPackages= are also picked up when a subimage is defined. + (d / "mkosi.images").mkdir() + (d / "mkosi.images/subimage.conf").touch() + + with chdir(d), resource_path(mkosi.resources) as resources: + _, _, [_, initrd, _] = parse_config(resources=resources) + + assert "package1" in initrd.packages + assert "package2" in initrd.packages