]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Read paths after parsing configuration files
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 28 Aug 2023 09:35:23 +0000 (11:35 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 08:28:25 +0000 (10:28 +0200)
Let's first take into account the main configuration file before parsing
any configured paths. This allow the main configuration files to reset
any configured settings without resetting its own defaults configured via
paths.

mkosi/config.py

index d36631254973226646b07ba13973389ae33ea0ee..81b57c756a7c5cee2e7736f011507d4793795414 100644 (file)
@@ -1649,6 +1649,15 @@ class MkosiConfigParser:
 
         parser.remove_section("Match")
 
+        for section in parser.sections():
+            for k, v in parser.items(section):
+                ns = defaults if k.startswith("@") else namespace
+
+                if not (s := self.settings_lookup_by_name.get(k.removeprefix("@"))):
+                    die(f"Unknown setting {k}")
+
+                setattr(ns, s.dest, s.parse(v, getattr(ns, s.dest, None)))
+
         if extras:
             for s in self.SETTINGS:
                 ns = defaults if s.path_default else namespace
@@ -1666,20 +1675,11 @@ class MkosiConfigParser:
                         setattr(ns, s.dest,
                                 s.parse(p.read_text() if s.path_read_text else f, getattr(ns, s.dest, None)))
 
-        for section in parser.sections():
-            for k, v in parser.items(section):
-                ns = defaults if k.startswith("@") else namespace
-
-                if not (s := self.settings_lookup_by_name.get(k.removeprefix("@"))):
-                    die(f"Unknown setting {k}")
-
-                setattr(ns, s.dest, s.parse(v, getattr(ns, s.dest, None)))
-
-        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()):
-                        self.parse_config(p if p.is_file() else Path("."), namespace, defaults)
+            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()):
+                            self.parse_config(p if p.is_file() else Path("."), namespace, defaults)
 
         return True