]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Do not overwrite package manager config files if they exist
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 11 Jun 2023 18:10:53 +0000 (20:10 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 11 Jun 2023 18:10:53 +0000 (20:10 +0200)
Let's allow users to override mkosi's default package manager
settings by providing their own package manager config file. This
is especially important for distributions built using dnf as dnf
does not yet have support for dropins.

mkosi/distributions/arch.py
mkosi/distributions/debian.py
mkosi/distributions/fedora.py

index 0e06557cf7aee432280b8e646e2757e7363c5db0..c669d5f4f7fe96b624493c4be49902b0b55a4fce 100644 (file)
@@ -63,6 +63,9 @@ def setup_pacman(state: MkosiState) -> None:
     state.root.joinpath("var/lib/pacman").mkdir(mode=0o755, exist_ok=True, parents=True)
 
     config = state.pkgmngr / "etc/pacman.conf"
+    if config.exists():
+        return
+
     config.parent.mkdir(mode=0o755, exist_ok=True, parents=True)
 
     with config.open("w") as f:
index 980262ddf6ee216bbe013af7cf768077c0d6211e..c318a6c6e3030c082b01928ecb22e1558d08b100 100644 (file)
@@ -173,17 +173,17 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
     state.root.joinpath("var/lib/dpkg/status").touch()
 
     config = state.pkgmngr / "etc/apt/apt.conf"
-
-    # Anything that users can override with dropins is written into the config file.
-    config.write_text(
-        dedent(
-            """\
-            APT::Install-Recommends "false";
-            """
+    if not config.exists():
+        # Anything that users can override with dropins is written into the config file.
+        config.write_text(
+            dedent(
+                """\
+                APT::Install-Recommends "false";
+                """
+            )
         )
-    )
 
-    sources = state.pkgmngr.joinpath("etc/apt/sources.list")
+    sources = state.pkgmngr / "etc/apt/sources.list"
     if not sources.exists():
         with sources.open("w") as f:
             for repo in repos:
index a57d90f9b763ba8aa85b8a14f93c1a49beecfd8d..5d8301c2d140f7a348bb972535c5016f1622f8ea 100644 (file)
@@ -121,8 +121,14 @@ class Repo(NamedTuple):
 
 
 def setup_dnf(state: MkosiState, repos: Sequence[Repo]) -> None:
-    state.pkgmngr.joinpath("etc/dnf").mkdir(exist_ok=True, parents=True)
-    with state.pkgmngr.joinpath("etc/dnf/dnf.conf").open("w") as f:
+    config = state.pkgmngr / "etc/dnf/dnf.conf"
+
+    if config.exists():
+        return
+
+    config.parent.mkdir(exist_ok=True, parents=True)
+
+    with config.open("w") as f:
         for repo in repos:
             f.write(
                 dedent(