# 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)
# SPDX-License-Identifier: LGPL-2.1+
import os
+from pathlib import Path
from mkosi.config import ConfigFeature
from mkosi.context import Context
]
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
"-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())}",
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=*",
"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",
"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",
]