]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Prefer configuration via CLI over configuration via config file 1620/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 8 Jun 2023 15:42:35 +0000 (17:42 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 8 Jun 2023 16:55:14 +0000 (18:55 +0200)
This makes it easier to debug things with --debug as all the options
used will be logged instead of having to go and figure out what's in
the config file.

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

index c8c6d1166aae0ed6f87347ceceab062216bf8780..6265ceef41673658836853b4206030fcc7e7de4e 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 from collections.abc import Sequence
+from pathlib import Path
 from textwrap import dedent
 
 from mkosi.architecture import Architecture
@@ -65,20 +66,11 @@ def setup_pacman(state: MkosiState) -> None:
     config.parent.mkdir(mode=0o755, exist_ok=True, parents=True)
 
     with config.open("w") as f:
-        gpgdir = state.pkgmngr / "etc/pacman.d/gnupg/"
-        gpgdir = gpgdir if gpgdir.exists() else "/etc/pacman.d/gnupg/"
         f.write(
             dedent(
                 f"""\
                 [options]
-                RootDir = {state.root}
-                LogFile = /dev/null
-                CacheDir = {state.cache_dir}
-                GPGDir = {gpgdir}
-                HookDir = {state.root}/etc/pacman.d/hooks/
                 HoldPkg = pacman glibc
-                Architecture = {state.installer.architecture(state.config.architecture)}
-                Color
                 CheckSpace
                 SigLevel = {sig_level}
                 ParallelDownloads = 5
@@ -115,9 +107,19 @@ def setup_pacman(state: MkosiState) -> None:
 
 
 def invoke_pacman(state: MkosiState, packages: Sequence[str], apivfs: bool = True) -> None:
+    gpgdir = state.pkgmngr / "etc/pacman.d/gnupg/"
+    gpgdir = gpgdir if gpgdir.exists() else Path("/etc/pacman.d/gnupg/")
+
     cmdline: list[PathString] = [
         "pacman",
         "--config", state.pkgmngr / "etc/pacman.conf",
+        "--root", state.root,
+        "--logfile", "/dev/null",
+        "--cachedir", state.cache_dir,
+        "--gpgdir", gpgdir,
+        "--hookdir", state.root / "etc/pacman.d/hooks",
+        "--arch",  state.installer.architecture(state.config.architecture),
+        "--color", "auto",
         "--noconfirm",
         "--needed",
         "-Sy", *sort_packages(packages),
index e5d54b3ab58ff86b1288f03808af8ec09c3e54a3..77fe4019bb7ccdda7a99834f61c439354e0812f8 100644 (file)
@@ -173,42 +173,12 @@ def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
     state.root.joinpath("var/lib/dpkg/status").touch()
 
     config = state.pkgmngr / "etc/apt/apt.conf"
-    debarch = state.installer.architecture(state.config.architecture)
-
-    trustedkeys = state.pkgmngr / "etc/apt/trusted.gpg"
-    trustedkeys = trustedkeys if trustedkeys.exists() else f"/usr/share/keyrings/{state.config.release}-archive-keyring"
-    trustedkeys_dir = state.pkgmngr / "etc/apt/trusted.gpg.d"
-    trustedkeys_dir = trustedkeys_dir if trustedkeys_dir.exists() else "/usr/share/keyrings"
 
+    # Anything that users can override with dropins is written into the config file.
     config.write_text(
         dedent(
-            f"""\
-            APT::Architecture "{debarch}";
-            APT::Architectures "{debarch}";
-            APT::Immediate-Configure "off";
+            """\
             APT::Install-Recommends "false";
-            APT::Get::Assume-Yes "true";
-            APT::Get::AutomaticRemove "true";
-            APT::Get::Allow-Change-Held-Packages "true";
-            APT::Get::Allow-Remove-Essential "true";
-            APT::Sandbox::User "root";
-            Dir::Cache "{state.cache_dir}";
-            Dir::State "{state.pkgmngr / "var/lib/apt"}";
-            Dir::State::status "{state.root / "var/lib/dpkg/status"}";
-            Dir::Etc "{state.pkgmngr / "etc/apt"}";
-            Dir::Etc::trusted "{trustedkeys}";
-            Dir::Etc::trustedparts "{trustedkeys_dir}";
-            Dir::Log "{state.pkgmngr / "var/log/apt"}";
-            Dir::Bin::dpkg "{shutil.which("dpkg")}";
-            Debug::NoLocking "true";
-            DPkg::Options:: "--root={state.root}";
-            DPkg::Options:: "--log={state.pkgmngr / "var/log/apt/dpkg.log"}";
-            DPkg::Options:: "--force-unsafe-io";
-            DPkg::Options:: "--force-architecture";
-            DPkg::Options:: "--force-depends";
-            Dpkg::Use-Pty "false";
-            DPkg::Install::Recursive::Minimum "1000";
-            pkgCacheGen::ForceEssential ",";
             """
         )
     )
@@ -234,7 +204,43 @@ def invoke_apt(
         INITRD="No",
     )
 
-    return bwrap(["apt-get", operation, *extra], apivfs=state.root if apivfs else None, env=env | state.environment)
+    debarch = state.installer.architecture(state.config.architecture)
+
+    trustedkeys = state.pkgmngr / "etc/apt/trusted.gpg"
+    trustedkeys = trustedkeys if trustedkeys.exists() else f"/usr/share/keyrings/{state.config.release}-archive-keyring"
+    trustedkeys_dir = state.pkgmngr / "etc/apt/trusted.gpg.d"
+    trustedkeys_dir = trustedkeys_dir if trustedkeys_dir.exists() else "/usr/share/keyrings"
+
+    options = [
+        "-o", f"APT::Architecture={debarch}",
+        "-o", f"APT::Architectures={debarch}",
+        "-o", "APT::Immediate-Configure=off",
+        "-o", "APT::Get::Assume-Yes=true",
+        "-o", "APT::Get::AutomaticRemove=true",
+        "-o", "APT::Get::Allow-Change-Held-Packages=true",
+        "-o", "APT::Get::Allow-Remove-Essential=true",
+        "-o", "APT::Sandbox::User=root",
+        "-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'}",
+        "-o", f"Dir::Bin::dpkg={shutil.which('dpkg')}",
+        "-o", "Debug::NoLocking=true",
+        "-o", f"DPkg::Options::=--root={state.root}",
+        "-o", f"DPkg::Options::=--log={state.pkgmngr / 'var/log/apt/dpkg.log'}",
+        "-o", "DPkg::Options::=--force-unsafe-io",
+        "-o", "DPkg::Options::=--force-architecture",
+        "-o", "DPkg::Options::=--force-depends",
+        "-o", "Dpkg::Use-Pty=false",
+        "-o", "DPkg::Install::Recursive::Minimum=1000",
+        "-o", "pkgCacheGen::ForceEssential=,",
+    ]
+
+    return bwrap(["apt-get", *options, operation, *extra],
+                 apivfs=state.root if apivfs else None, env=env | state.environment)
 
 
 def install_apt_sources(state: MkosiState, repos: Sequence[str]) -> None: