]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Parse both mkosi.local.conf and mkosi.local/
authorSeptatrix <24257556+Septatrix@users.noreply.github.com>
Sun, 2 Mar 2025 20:53:09 +0000 (21:53 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 3 Mar 2025 19:29:00 +0000 (20:29 +0100)
This aligns more with what the users expects
and allows working around some limitations of the config system
(esp. regarding the interplay of `Include=` and `Profiles=`).

mkosi/config.py
mkosi/resources/man/mkosi.1.md
tests/test_config.py

index 82d5a5e65f3c77d6d13fc78ebd2e5c9c9dac2889..2cd7e680e792e703b2e28f98be12e6ff8bec24de 100644 (file)
@@ -4561,11 +4561,10 @@ class ParseContext:
 
     def parse_config_one(self, path: Path, parse_profiles: bool = False, parse_local: bool = False) -> bool:
         s: Optional[ConfigSetting[object]]  # Hint to mypy that we might assign None
-        extras = path.is_dir()
-
         assert path.is_absolute()
 
-        if path.is_dir():
+        extras = path.is_dir()
+        if extras:
             path /= "mkosi.conf"
 
         if not self.match_config(path):
@@ -4573,10 +4572,10 @@ class ParseContext:
 
         if extras:
             if parse_local:
-                if (
-                    ((localpath := path.parent / "mkosi.local") / "mkosi.conf").exists()
-                    or (localpath := path.parent / "mkosi.local.conf").exists()
-                ):  # fmt: skip
+                for localpath in (
+                    *([p] if (p := path.parent / "mkosi.local").is_dir() else []),
+                    *([p] if (p := path.parent / "mkosi.local.conf").is_file() else []),
+                ):
                     with chdir(localpath if localpath.is_dir() else Path.cwd()):
                         self.parse_config_one(localpath if localpath.is_file() else Path.cwd())
 
index 34650c932e8a63ee325f86d344cf8804cc32fd8b..b503b967fe41924c42b225185eacf987133bc8bc 100644 (file)
@@ -326,9 +326,9 @@ grouped by section below.
 Configuration is parsed in the following order:
 
 * The command line arguments are parsed.
-* `mkosi.local.conf` or `mkosi.local` is parsed if it exists. This file or
-  directory should be in `.gitignore` (or equivalent) and is intended for local
-  configuration.
+* `mkosi.local.conf` and `mkosi.local/` are parsed if they exists (in that order).
+  This file or directory should be in `.gitignore` (or equivalent)
+  and is intended for local configuration.
 * Any default paths (depending on the option) are configured if the
   corresponding path exists.
 * `mkosi.conf` is parsed if it exists in the directory configured with
@@ -346,7 +346,7 @@ Note that settings configured via the command line always override
 settings configured via configuration files. If the same setting is
 configured more than once via configuration files, later assignments
 override earlier assignments except for settings that take a collection
-of values. Also, settings read from `mkosi.local` or `mkosi.local.conf` will
+of values. Also, settings read from `mkosi.local.conf` or `mkosi.local/` will
 override settings from configuration files that are parsed later, but not
 settings specified on the CLI.
 
index bb28843f390b8747b64c8e412b63e3a884bbbe96..46c32c12e1b9a3cd6641e9dc8edcdfa1b6c17620 100644 (file)
@@ -460,6 +460,8 @@ def test_local_config(tmp_path: Path) -> None:
 
         [Content]
         WithTests=yes
+        Environment=FOO=override
+        Environment=BAZ=normal
         """
     )
 
@@ -475,6 +477,8 @@ def test_local_config(tmp_path: Path) -> None:
 
         [Content]
         WithTests=no
+        Environment=FOO=normal
+        Environment=BAR=normal
         """
     )
 
@@ -491,6 +495,20 @@ def test_local_config(tmp_path: Path) -> None:
     assert config.distribution == Distribution.fedora
     assert not config.with_tests
 
+    (d / "mkosi.local/mkosi.conf.d").mkdir(parents=True)
+    (d / "mkosi.local/mkosi.conf.d/10-test.conf").write_text(
+        """\
+        [Content]
+        Environment=BAR=override
+        Environment=BAZ=override
+        """
+    )
+
+    with chdir(d):
+        _, [config] = parse_config()
+
+    assert config.environment == {"FOO": "override", "BAR": "override", "BAZ": "override"}
+
 
 def test_parse_load_verb(tmp_path: Path) -> None:
     with chdir(tmp_path):