]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Parse setting paths before parsing main config file
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Oct 2023 11:30:19 +0000 (13:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Oct 2023 12:03:47 +0000 (14:03 +0200)
Currently, paths either configure default values or append to a
list (When path_default is False, it's always a list based setting).

When paths are configuring default values, it makes more sense for
default values set in the mkosi.conf file to override path based
default values.

When appending to a list, (e.g. ExtraTrees=), it makes more sense
for the trees configured in the mkosi.conf to come after the tree
from the path (mkosi.extra).

Both these goals are achieved by parsing the path based values before
parsing the main mkosi.conf file.

mkosi/config.py

index 6150a0db1083b6a4cdd041518e522db497cc09b5..b91de042f32d9841851d102f01cd47b232c572e5 100644 (file)
@@ -2187,6 +2187,7 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
         return triggered is not False
 
     def parse_config(path: Path, namespace: argparse.Namespace, defaults: argparse.Namespace) -> bool:
+        s: Optional[MkosiConfigSetting] # Make mypy happy
         extras = path.is_dir()
 
         if path.is_dir():
@@ -2195,6 +2196,22 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
         if not match_config(path, namespace, defaults):
             return False
 
+        if extras:
+            for s in SETTINGS:
+                ns = defaults if s.path_default else namespace
+                for f in s.paths:
+                    p = parse_path(
+                        f,
+                        secret=s.path_secret,
+                        required=False,
+                        resolve=False,
+                        expanduser=False,
+                        expandvars=False,
+                    )
+                    if p.exists():
+                        setattr(ns, s.dest,
+                                s.parse(p.read_text() if s.path_read_text else f, getattr(ns, s.dest, None)))
+
         if path.exists():
             logging.debug(f"Including configuration file {Path.cwd() / path}")
 
@@ -2215,27 +2232,11 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
                 with parse_new_includes(namespace, defaults):
                     setattr(ns, s.dest, s.parse(v, getattr(ns, s.dest, None)))
 
-        if extras:
-            for s in SETTINGS:
-                ns = defaults if s.path_default else namespace
-                for f in s.paths:
-                    p = parse_path(
-                        f,
-                        secret=s.path_secret,
-                        required=False,
-                        resolve=False,
-                        expanduser=False,
-                        expandvars=False,
-                    )
-                    if p.exists():
-                        setattr(ns, s.dest,
-                                s.parse(p.read_text() if s.path_read_text else f, getattr(ns, s.dest, None)))
-
-            if (path.parent / "mkosi.conf.d").exists():
-                for p in sorted((path.parent / "mkosi.conf.d").iterdir()):
-                    if p.is_dir() or p.suffix == ".conf":
-                        with chdir(p if p.is_dir() else Path.cwd()):
-                            parse_config(p if p.is_file() else Path("."), namespace, defaults)
+        if extras and (path.parent / "mkosi.conf.d").exists():
+            for p in sorted((path.parent / "mkosi.conf.d").iterdir()):
+                if p.is_dir() or p.suffix == ".conf":
+                    with chdir(p if p.is_dir() else Path.cwd()):
+                        parse_config(p if p.is_file() else Path("."), namespace, defaults)
 
         return True