From: Daan De Meyer Date: Sun, 11 Jun 2023 19:55:06 +0000 (+0200) Subject: apt: Set "Dir" instead of "Dir::Etc" and set it via APT_CONFIG X-Git-Tag: v15~115^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1625%2Fhead;p=thirdparty%2Fmkosi.git apt: Set "Dir" instead of "Dir::Etc" and set it via APT_CONFIG 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. --- diff --git a/mkosi/distributions/debian.py b/mkosi/distributions/debian.py index c318a6c6e..4b294402b 100644 --- a/mkosi/distributions/debian.py +++ b/mkosi/distributions/debian.py @@ -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'}",