]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Mount package manager caches to their canonical locations
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 15 Jan 2024 20:57:35 +0000 (21:57 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 16 Jan 2024 10:58:55 +0000 (11:58 +0100)
Let's reduce the amount of configuration by mounting package
manager caches to their canonical locations.

mkosi/distributions/debian.py
mkosi/installer/__init__.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/installer/zypper.py

index cd3b3d2e54fba39f8e1d4fa376dcce00fca9736a..8c56722f9cd1226ebd536b3805546b9704351291 100644 (file)
@@ -136,7 +136,12 @@ class Installer(DistributionInstaller):
         # then extracting the tar file into the chroot.
 
         for deb in essential:
-            with open(deb, "rb") as i, tempfile.NamedTemporaryFile() as o:
+            with (
+                # The deb paths will be in the form of "/var/cache/apt/<deb>" so we transform them to the corresponding
+                # path in mkosi's package cache directory.
+                open(context.cache_dir / Path(deb).relative_to("/var"), "rb") as i,
+                tempfile.NamedTemporaryFile() as o
+            ):
                 run(["dpkg-deb", "--fsys-tarfile", "/dev/stdin"], stdin=i, stdout=o, sandbox=context.sandbox())
                 extract_tar(context, Path(o.name), context.root, log=False)
 
index e4b99722bc4738ab63dbffe59d57e2781bf28e02..52dcc150c556f96bfead6f0d4af35142c4647f35 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 import os
+from pathlib import Path
 
 from mkosi.config import ConfigFeature
 from mkosi.context import Context
@@ -72,16 +73,16 @@ def finalize_package_manager_mounts(context: Context) -> list[PathString]:
     ]
 
     mounts += flatten(
-        ["--bind", d, d]
+        ["--bind", context.cache_dir / d, Path("/var") / d]
         for d in (
-            context.cache_dir / "lib/apt",
-            context.cache_dir / "cache/apt",
-            context.cache_dir / "cache" / dnf_subdir(context),
-            context.cache_dir / "lib" / dnf_subdir(context),
-            context.cache_dir / "cache/pacman/pkg",
-            context.cache_dir / "cache/zypp",
+            "lib/apt",
+            "cache/apt",
+            f"cache/{dnf_subdir(context)}",
+            f"lib/{dnf_subdir(context)}",
+            "cache/pacman/pkg",
+            "cache/zypp",
         )
-        if d.exists()
+        if (context.cache_dir / d).exists()
     )
 
     return mounts
index 0996039fd66d8771e103a05011932cab20ef2d78..bc8298049d0de8e8726b27675abc20a13ae84ce6 100644 (file)
@@ -65,8 +65,8 @@ def apt_cmd(context: Context, command: str) -> list[PathString]:
         "-o", "APT::Get::Allow-Change-Held-Packages=true",
         "-o", "APT::Get::Allow-Remove-Essential=true",
         "-o", "APT::Sandbox::User=root",
-        "-o", f"Dir::Cache={context.cache_dir / 'cache/apt'}",
-        "-o", f"Dir::State={context.cache_dir / 'lib/apt'}",
+        "-o", "Dir::Cache=/var/cache/apt",
+        "-o", "Dir::State=/var/lib/apt",
         "-o", f"Dir::State::Status={context.root / 'var/lib/dpkg/status'}",
         "-o", f"Dir::Log={context.workspace}",
         "-o", f"Dir::Bin::DPkg={find_binary('dpkg', root=context.config.tools())}",
index 74d743411365d8c8363e686b4d2b15fa484ca0d4..86c15c47eafcece323461f02fd7cf571593fa7d4 100644 (file)
@@ -88,8 +88,8 @@ def dnf_cmd(context: Context) -> list[PathString]:
         f"--releasever={context.config.release}",
         f"--installroot={context.root}",
         "--setopt=keepcache=1",
-        f"--setopt=cachedir={context.cache_dir / 'cache' / dnf_subdir(context)}",
-        f"--setopt=persistdir={context.cache_dir / 'lib' / dnf_subdir(context)}",
+        f"--setopt=cachedir=/var/cache/{dnf_subdir(context)}",
+        f"--setopt=persistdir=/var/lib/{dnf_subdir(context)}",
         f"--setopt=install_weak_deps={int(context.config.with_recommends)}",
         "--setopt=check_config_file_age=0",
         "--disable-plugin=*" if dnf.endswith("dnf5") else "--disableplugin=*",
index 08fa7e2001d8887f9e4a31dd22667edefd8c8a94..9028359ed00b3e1852b7c14b1662891c526af352 100644 (file)
@@ -76,7 +76,7 @@ def pacman_cmd(context: Context) -> list[PathString]:
         "pacman",
         "--root", context.root,
         "--logfile=/dev/null",
-        "--cachedir", context.cache_dir / "cache/pacman/pkg",
+        "--cachedir=/var/cache/pacman/pkg",
         "--hookdir", context.root / "etc/pacman.d/hooks",
         "--arch", context.config.distribution.architecture(context.config.architecture),
         "--color", "auto",
index 5af2a697754a4726a4f61e211df5233f7a655100..708a71cd072375321b34b05fe4b4b89e62ed0d53 100644 (file)
@@ -66,7 +66,7 @@ def zypper_cmd(context: Context) -> list[PathString]:
         "HOME=/",
         "zypper",
         f"--installroot={context.root}",
-        f"--cache-dir={context.cache_dir / 'cache/zypp'}",
+        "--cache-dir=/var/cache/zypp",
         "--gpg-auto-import-keys" if context.config.repository_key_check else "--no-gpg-checks",
         "--non-interactive",
     ]