]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
apt: Set "Dir" instead of "Dir::Etc" and set it via APT_CONFIG 1625/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 11 Jun 2023 19:55:06 +0000 (21:55 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 11 Jun 2023 20:05:10 +0000 (22:05 +0200)
We need to use APT_CONFIG to set "Dir" as otherwise the value of "Dir"
won't be taken into account by apt when looking for configuration files
as options set via the CLI are applied last after parsing the apt
configuration files.

mkosi/distributions/debian.py

index c318a6c6e3030c082b01928ecb22e1558d08b100..4b294402b2542da21b3d3fb8fe609bb29fbccd2c 100644 (file)
@@ -172,6 +172,20 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
     state.root.joinpath("var/lib/dpkg").mkdir(mode=0o755, exist_ok=True)
     state.root.joinpath("var/lib/dpkg/status").touch()
 
+    # We have a special apt.conf outside of pkgmngr dir that only configures "Dir" that we pass to
+    # APT_CONFIG to tell apt it should read config files in pkgmngr instead of in its usual locations. This
+    # is required because apt parses CLI configuration options after parsing its configuration files and as
+    # such we can't use CLI options to tell apt where to look for configuration files.
+    config = state.workspace / "apt.conf"
+    if not config.exists():
+        config.write_text(
+            dedent(
+                f"""\
+                Dir "{state.pkgmngr}";
+                """
+            )
+        )
+
     config = state.pkgmngr / "etc/apt/apt.conf"
     if not config.exists():
         # Anything that users can override with dropins is written into the config file.
@@ -197,7 +211,7 @@ def invoke_apt(
     apivfs: bool = True,
 ) -> CompletedProcess:
     env: dict[str, PathString] = dict(
-        APT_CONFIG=state.pkgmngr / "etc/apt/apt.conf",
+        APT_CONFIG=state.workspace / "apt.conf",
         DEBIAN_FRONTEND="noninteractive",
         DEBCONF_INTERACTIVE_SEEN="true",
         KERNEL_INSTALL_BYPASS="1",
@@ -223,7 +237,6 @@ def invoke_apt(
         "-o", f"Dir::Cache={state.cache_dir}",
         "-o", f"Dir::State={state.pkgmngr / 'var/lib/apt'}",
         "-o", f"Dir::State::status={state.root / 'var/lib/dpkg/status'}",
-        "-o", f"Dir::Etc={state.pkgmngr / 'etc/apt'}",
         "-o", f"Dir::Etc::trusted={trustedkeys}",
         "-o", f"Dir::Etc::trustedparts={trustedkeys_dir}",
         "-o", f"Dir::Log={state.pkgmngr / 'var/log/apt'}",